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

(-)a/C4/Installer/PerlDependencies.pm (+5 lines)
Lines 737-742 our $PERL_DEPS = { Link Here
737
        'required' => '0',
737
        'required' => '0',
738
        'min_ver'  => '0.89',
738
        'min_ver'  => '0.89',
739
    },
739
    },
740
    'Time::Fake'   => {
741
        'usage'    => 'Test code coverage',
742
        'required' => '0',
743
        'min_ver'  => '0.11',
744
    }
740
};
745
};
741
746
742
1;
747
1;
(-)a/t/Circulation/AgeRestrictionMarkers.t (-18 / +38 lines)
Lines 1-8 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
4
use DateTime;
5
use DateTime;
5
use Test::More tests => 10;
6
use Test::More tests => 6;
6
7
7
use t::lib::Mocks;
8
use t::lib::Mocks;
8
9
Lines 10-34 use C4::Circulation; Link Here
10
11
11
t::lib::Mocks::mock_preference( 'AgeRestrictionMarker', 'FSK|PEGI|Age|K' );
12
t::lib::Mocks::mock_preference( 'AgeRestrictionMarker', 'FSK|PEGI|Age|K' );
12
13
14
$| = 1;
13
is ( C4::Circulation::GetAgeRestriction('FSK 16'), '16', 'FSK 16 returns 16' );
15
is ( C4::Circulation::GetAgeRestriction('FSK 16'), '16', 'FSK 16 returns 16' );
14
is ( C4::Circulation::GetAgeRestriction('PEGI 16'), '16', 'PEGI 16 returns 16' );
16
is ( C4::Circulation::GetAgeRestriction('PEGI 16'), '16', 'PEGI 16 returns 16' );
15
is ( C4::Circulation::GetAgeRestriction('PEGI16'), '16', 'PEGI16 returns 16' );
17
is ( C4::Circulation::GetAgeRestriction('PEGI16'), '16', 'PEGI16 returns 16' );
16
is ( C4::Circulation::GetAgeRestriction('Age 16'), '16', 'Age 16 returns 16' );
18
is ( C4::Circulation::GetAgeRestriction('Age 16'), '16', 'Age 16 returns 16' );
17
is ( C4::Circulation::GetAgeRestriction('K16'), '16', 'K16 returns 16' );
19
is ( C4::Circulation::GetAgeRestriction('K16'), '16', 'K16 returns 16' );
18
20
19
21
subtest 'Patron tests - 15 years old' => sub {
20
##Testing age restriction for a borrower.
22
    my $MaxOffset;
21
my $now = DateTime->now();
23
    my $CheckTimeFake = eval { require Time::Fake; 1; } || 0;
22
my $borrower = {};
24
    if ($CheckTimeFake==1) {
23
C4::Members::SetAge( $borrower, '0015-00-00' );
25
        $MaxOffset = 24;
24
26
        plan tests => 120;
25
my ($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('FSK 16', $borrower);
27
    }
26
is ( ($daysToAgeRestriction > 0), 1, 'FSK 16 blocked for a 15 year old' );
28
    else {
27
($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('PEGI 15', $borrower);
29
        diag("Install Time::Fake to regression test for Bug 14362.");
28
is ( ($daysToAgeRestriction <= 0), 1, 'PEGI 15 allowed for a 15 year old' );
30
        $MaxOffset = 1;
29
($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('PEGI14', $borrower);
31
        plan tests => 5;
30
is ( ($daysToAgeRestriction <= 0), 1, 'PEGI14 allowed for a 15 year old' );
32
    }
31
($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('Age 10', $borrower);
33
    my $offset = 0;
32
is ( ($daysToAgeRestriction <= 0), 1, 'Age 10 allowed for a 15 year old' );
34
    while ($offset<$MaxOffset) {
33
($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('K18', $borrower);
35
        if ($MaxOffset>1) {
34
is ( ($daysToAgeRestriction > 0), 1, 'K18 blocked for a 15 year old' );
36
            Time::Fake->offset("+${offset}h");
37
        }
38
        ##Testing age restriction for a borrower.
39
        my $now = DateTime->now();
40
        my $borrower = {};
41
        C4::Members::SetAge( $borrower, '0015-00-00' );
42
43
        my ($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('FSK 16', $borrower);
44
        is ( ($daysToAgeRestriction > 0), 1, "FSK 16 blocked for a 15 year old - $offset hours" );
45
        ($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('PEGI 15', $borrower);
46
        is ( ($daysToAgeRestriction <= 0), 1, "PEGI 15 allowed for a 15 year old - $offset hours" );
47
        ($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('PEGI14', $borrower);
48
        is ( ($daysToAgeRestriction <= 0), 1, "PEGI14 allowed for a 15 year old - $offset hours" );
49
        ($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('Age 10', $borrower);
50
        is ( ($daysToAgeRestriction <= 0), 1, "Age 10 allowed for a 15 year old - $offset hours" );
51
        ($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('K18', $borrower);
52
        is ( ($daysToAgeRestriction > 0), 1, "K18 blocked for a 15 year old - $offset hours" );
53
        $offset++;
54
    }
55
}
35
- 

Return to bug 14362