Bug 14153: Noisy warns in admin/transport-cost-matrix.pl
[koha.git] / t / Koha_Template_Plugin_Koha.t
blob950257cf7459b0dfa14a099cfb60a0427aaefd05
1 #!/usr/bin/perl
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>.
18 use Modern::Perl;
20 use Test::More tests => 3;
21 use Test::MockModule;
23 use String::Random;
25 # Test the plugin is usable
26 use_ok( 'Koha::Template::Plugin::Koha' );
27 ok( my $cache = Koha::Template::Plugin::Koha->new() );
29 subtest "Koha::Template::Plugin::Koha::Version tests" => sub {
31 plan tests => 2;
33 # Variables for mocking Koha::version()
34 my $major;
35 my $minor;
36 my $maintenance;
37 my $development;
39 # Mock Koha::version()
40 my $koha = new Test::MockModule('Koha');
41 $koha->mock( 'version', sub {
42 return "$major.$minor.$maintenance.$development";
43 });
45 my $rnd = new String::Random;
46 # development version test
47 $major = $rnd->randregex('\d');
48 $minor = $rnd->randregex('\d\d');
49 $maintenance = $rnd->randregex('\d\d');
50 $development = $rnd->randregex('\d\d\d');
51 my $version = "$major.$minor.$maintenance.$development";
52 my $res = Koha::Template::Plugin::Koha::Version( $version );
53 is_deeply( $res, {
54 major => $major,
55 release => $major . "." . $minor,
56 maintenance => $major . "." . $minor . "." . $maintenance,
57 development => $development
58 }, "Correct development version");
61 # maintenance release test
62 $major = $rnd->randregex('\d');
63 $minor = $rnd->randregex('\d\d');
64 $maintenance = $rnd->randregex('\d\d');
65 $development = "000";
66 $version = "$major.$minor.$maintenance.$development";
67 $res = Koha::Template::Plugin::Koha::Version( $version );
68 is_deeply( $res, {
69 major => $major,
70 release => $major . "." . $minor,
71 maintenance => $major . "." . $minor . "." . $maintenance,
72 development => undef
73 }, "Correct maintenance version");