Bug 13758: Move the Koha version from kohaversion.pl
[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 => 3;
21 use Test::MockModule;
22
23 use String::Random;
24
25 # Test the plugin is usable
26 use_ok( 'Koha::Template::Plugin::Koha' );
27 ok( my $cache = Koha::Template::Plugin::Koha->new() );
28
29 subtest "Koha::Template::Plugin::Koha::version tests" => sub {
30
31     plan tests => 2;
32
33     # Variables for mocking Koha::version()
34     my $major;
35     my $minor;
36     my $maintenance;
37     my $development;
38
39     # Mock Koha::version()
40     my $koha = new Test::MockModule('Koha');
41     $koha->mock( 'Version', sub {
42         return "$major.$minor.$maintenance.$development";
43     });
44
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");
59
60
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");
74
75 };
76
77 1;