Bug 31076: Handle year limits with equal sign or colon
[koha.git] / t / Koha_Template_Plugin_Koha.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 5;
21 use Test::MockModule;
22 use t::lib::Mocks;
23
24 use String::Random;
25
26 # Test the plugin is usable
27 use_ok( 'Koha::Template::Plugin::Koha' );
28 ok( my $cache = Koha::Template::Plugin::Koha->new() );
29
30 subtest "Koha::Template::Plugin::Koha::Version tests" => sub {
31
32     plan tests => 2;
33
34     # Variables for mocking Koha::version()
35     my $major;
36     my $minor;
37     my $maintenance;
38     my $development;
39
40     # Mock Koha::version()
41     my $koha = Test::MockModule->new('Koha');
42     $koha->mock( 'version', sub {
43         return "$major.$minor.$maintenance.$development";
44     });
45
46     my $rnd = String::Random->new;
47     # development version test
48     $major       = $rnd->randregex('\d');
49     $minor       = $rnd->randregex('\d\d');
50     $maintenance = $rnd->randregex('\d\d');
51     $development = $rnd->randregex('\d\d\d');
52     my $version = "$major.$minor.$maintenance.$development";
53     my $res = Koha::Template::Plugin::Koha::Version( $version );
54     is_deeply( $res, {
55         major       => $major,
56         minor       => $minor,
57         release     => $major . "." . $minor,
58         maintenance => $major . "." . $minor . "." . $maintenance,
59         development => $development
60     }, "Correct development version");
61
62
63     # maintenance release test
64     $major       = $rnd->randregex('\d');
65     $minor       = $rnd->randregex('\d\d');
66     $maintenance = $rnd->randregex('\d\d');
67     $development = "000";
68     $version = "$major.$minor.$maintenance.$development";
69     $res = Koha::Template::Plugin::Koha::Version( $version );
70     is_deeply( $res, {
71         major       => $major,
72         minor       => $minor,
73         release     => $major . "." . $minor,
74         maintenance => $major . "." . $minor . "." . $maintenance,
75         development => undef
76     }, "Correct maintenance version");
77
78 };
79
80 subtest "Koha::Template::Plugin::Koha::ArePluginsEnabled tests" => sub {
81
82     plan tests => 2;
83
84     t::lib::Mocks::mock_config( 'enable_plugins', 1 );
85     is(Koha::Template::Plugin::Koha::ArePluginsEnabled(), 1, "Correct ArePluginsEnabled is yes");
86
87     t::lib::Mocks::mock_config( 'enable_plugins', 0 );
88     is(Koha::Template::Plugin::Koha::ArePluginsEnabled(), 0, "Correct ArePluginsEnabled is no");
89
90 };
91
92 subtest "Koha::Template::Plugin::Koha::CSVDelimiter tests" => sub {
93
94     plan tests => 8;
95
96     my $plugin = Koha::Template::Plugin::Koha->new();
97
98     t::lib::Mocks::mock_preference('CSVDelimiter', '');
99     is($plugin->CSVDelimiter(), ',', "CSVDelimiter() returns comma when preference is empty string");
100
101     t::lib::Mocks::mock_preference('CSVDelimiter', undef);
102     is($plugin->CSVDelimiter(), ',', "CSVDelimiter() returns comma when preference is undefined");
103
104     t::lib::Mocks::mock_preference('CSVDelimiter', ';');
105     is($plugin->CSVDelimiter(), ';', "CSVDelimiter() returns preference value when preference is not tabulation");
106
107     t::lib::Mocks::mock_preference('CSVDelimiter', 'tabulation');
108     is($plugin->CSVDelimiter(), "\t", "CSVDelimiter() returns \\t when preference is tabulation");
109
110     t::lib::Mocks::mock_preference('CSVDelimiter', '#');
111     is($plugin->CSVDelimiter(undef), '#', "CSVDelimiter(arg) returns preference value when arg is undefined");
112     is($plugin->CSVDelimiter(''), '#', "CSVDelimiter(arg) returns preference value when arg is empty string");
113     is($plugin->CSVDelimiter(','), ',', "CSVDelimiter(arg) returns arg value when arg is not tabulation");
114     is($plugin->CSVDelimiter('tabulation'), "\t", "CSVDelimiter(arg) returns \\t value when arg is tabulation");
115 };