Bug 18302: Release team 17.05
[koha.git] / t / Koha_Template_Plugin_Koha.t
blob6bbe99f8a41bce60d2ef8d0f2f6fd8dac517b299
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 minor => $minor,
56 release => $major . "." . $minor,
57 maintenance => $major . "." . $minor . "." . $maintenance,
58 development => $development
59 }, "Correct development version");
62 # maintenance release test
63 $major = $rnd->randregex('\d');
64 $minor = $rnd->randregex('\d\d');
65 $maintenance = $rnd->randregex('\d\d');
66 $development = "000";
67 $version = "$major.$minor.$maintenance.$development";
68 $res = Koha::Template::Plugin::Koha::Version( $version );
69 is_deeply( $res, {
70 major => $major,
71 minor => $minor,
72 release => $major . "." . $minor,
73 maintenance => $major . "." . $minor . "." . $maintenance,
74 development => undef
75 }, "Correct maintenance version");