3 # This file is part of Koha.
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.
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.
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>.
20 use Test::More tests => 4;
26 # Test the plugin is usable
27 use_ok( 'Koha::Template::Plugin::Koha' );
28 ok( my $cache = Koha::Template::Plugin::Koha->new() );
30 subtest "Koha::Template::Plugin::Koha::Version tests" => sub {
34 # Variables for mocking Koha::version()
40 # Mock Koha::version()
41 my $koha = Test::MockModule->new('Koha');
42 $koha->mock( 'version', sub {
43 return "$major.$minor.$maintenance.$development";
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 );
57 release => $major . "." . $minor,
58 maintenance => $major . "." . $minor . "." . $maintenance,
59 development => $development
60 }, "Correct development version");
63 # maintenance release test
64 $major = $rnd->randregex('\d');
65 $minor = $rnd->randregex('\d\d');
66 $maintenance = $rnd->randregex('\d\d');
68 $version = "$major.$minor.$maintenance.$development";
69 $res = Koha::Template::Plugin::Koha::Version( $version );
73 release => $major . "." . $minor,
74 maintenance => $major . "." . $minor . "." . $maintenance,
76 }, "Correct maintenance version");
80 subtest "Koha::Template::Plugin::Koha::CSVDelimiter tests" => sub {
84 my $plugin = Koha::Template::Plugin::Koha->new();
86 t::lib::Mocks::mock_preference('CSVDelimiter', '');
87 is($plugin->CSVDelimiter(), ',', "CSVDelimiter() returns comma when preference is empty string");
89 t::lib::Mocks::mock_preference('CSVDelimiter', undef);
90 is($plugin->CSVDelimiter(), ',', "CSVDelimiter() returns comma when preference is undefined");
92 t::lib::Mocks::mock_preference('CSVDelimiter', ';');
93 is($plugin->CSVDelimiter(), ';', "CSVDelimiter() returns preference value when preference is not tabulation");
95 t::lib::Mocks::mock_preference('CSVDelimiter', 'tabulation');
96 is($plugin->CSVDelimiter(), "\t", "CSVDelimiter() returns \\t when preference is tabulation");
98 t::lib::Mocks::mock_preference('CSVDelimiter', '#');
99 is($plugin->CSVDelimiter(undef), '#', "CSVDelimiter(arg) returns preference value when arg is undefined");
100 is($plugin->CSVDelimiter(''), '#', "CSVDelimiter(arg) returns preference value when arg is empty string");
101 is($plugin->CSVDelimiter(','), ',', "CSVDelimiter(arg) returns arg value when arg is not tabulation");
102 is($plugin->CSVDelimiter('tabulation'), "\t", "CSVDelimiter(arg) returns \\t value when arg is tabulation");