View | Details | Raw Unified | Return to bug 13496
Collapse All | Expand All

(-)a/Koha/Template/Plugin/Koha.pm (+14 lines)
Lines 45-48 sub Preference { Link Here
45
    return encode('UTF-8', C4::Context->preference( $pref ) );
45
    return encode('UTF-8', C4::Context->preference( $pref ) );
46
}
46
}
47
47
48
sub Version {
49
    my $version_string = C4::Context::KOHAVERSION;
50
    my ($major,$minor,$maintenance,$development) = split('\.',$version_string);
51
52
    return {
53
        major       => $major,
54
        release     => $major . "." . $minor,
55
        maintenance => $major . "." . $minor . "." . $maintenance,
56
        development => ( $development ne '000' )
57
                            ? $development
58
                            : undef
59
    };
60
}
61
48
1;
62
1;
(-)a/t/Koha_Template_Plugin_Koha.t (-1 / +77 lines)
Line 0 Link Here
0
- 
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 KOHAVERSION
34
    my $major;
35
    my $minor;
36
    my $maintenance;
37
    my $development;
38
39
    # Mock C4::Context::KOHAVERSION
40
    my $context = new Test::MockModule('C4::Context');
41
    $context->mock( 'KOHAVERSION', 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;

Return to bug 13496