Lines 1-8
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
|
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Copyright (C) 2015 Mark Tompsett (Time Zone Shifts) |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
3 |
use Modern::Perl; |
20 |
use Modern::Perl; |
|
|
21 |
|
4 |
use DateTime; |
22 |
use DateTime; |
5 |
use Test::More tests => 10; |
23 |
use Test::More tests => 7; |
6 |
|
24 |
|
7 |
use t::lib::Mocks; |
25 |
use t::lib::Mocks; |
8 |
|
26 |
|
Lines 16-34
is ( C4::Circulation::GetAgeRestriction('PEGI16'), '16', 'PEGI16 returns 16' );
Link Here
|
16 |
is ( C4::Circulation::GetAgeRestriction('Age 16'), '16', 'Age 16 returns 16' ); |
34 |
is ( C4::Circulation::GetAgeRestriction('Age 16'), '16', 'Age 16 returns 16' ); |
17 |
is ( C4::Circulation::GetAgeRestriction('K16'), '16', 'K16 returns 16' ); |
35 |
is ( C4::Circulation::GetAgeRestriction('K16'), '16', 'K16 returns 16' ); |
18 |
|
36 |
|
|
|
37 |
subtest 'Patron tests - 15 years old' => sub { |
38 |
plan tests => 5; |
39 |
##Testing age restriction for a borrower. |
40 |
my $now = DateTime->now(); |
41 |
my $borrower = {}; |
42 |
C4::Members::SetAge( $borrower, '0015-00-00' ); |
43 |
TestPatron($borrower,0); |
44 |
}; |
45 |
|
46 |
subtest 'Patron tests - 15 years old (Time Zone shifts)' => sub { |
47 |
my $CheckTimeFake = eval { require Time::Fake; 1; } || 0; |
48 |
SKIP: { |
49 |
skip "Install Time::Fake to regression test for Bug 14362.", 115 if $CheckTimeFake!=1; |
50 |
# 115 regression tests = 5 tests (see TestPatron) for 23 timezones. |
51 |
plan tests => 115; |
52 |
my $offset = 1; |
53 |
# <24 hours in a day. |
54 |
while ($offset<24) { |
55 |
Time::Fake->offset("+${offset}h"); |
56 |
|
57 |
##Testing age restriction for a borrower. |
58 |
my $now = DateTime->now(); |
59 |
my $borrower = {}; |
60 |
C4::Members::SetAge( $borrower, '0015-00-00' ); |
61 |
TestPatron($borrower,$offset); |
62 |
|
63 |
$offset++; |
64 |
} |
65 |
} |
66 |
}; |
67 |
|
68 |
# The Patron tests |
69 |
sub TestPatron { |
70 |
my ($borrower,$offset) = @_; |
19 |
|
71 |
|
20 |
##Testing age restriction for a borrower. |
72 |
my ($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('FSK 16', $borrower); |
21 |
my $now = DateTime->now(); |
73 |
is ( ($daysToAgeRestriction > 0), 1, "FSK 16 blocked for a 15 year old - $offset hours" ); |
22 |
my $borrower = {}; |
74 |
($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('PEGI 15', $borrower); |
23 |
C4::Members::SetAge( $borrower, '0015-00-00' ); |
75 |
is ( ($daysToAgeRestriction <= 0), 1, "PEGI 15 allowed for a 15 year old - $offset hours" ); |
24 |
|
76 |
($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('PEGI14', $borrower); |
25 |
my ($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('FSK 16', $borrower); |
77 |
is ( ($daysToAgeRestriction <= 0), 1, "PEGI14 allowed for a 15 year old - $offset hours" ); |
26 |
is ( ($daysToAgeRestriction > 0), 1, 'FSK 16 blocked for a 15 year old' ); |
78 |
($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('Age 10', $borrower); |
27 |
($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('PEGI 15', $borrower); |
79 |
is ( ($daysToAgeRestriction <= 0), 1, "Age 10 allowed for a 15 year old - $offset hours" ); |
28 |
is ( ($daysToAgeRestriction <= 0), 1, 'PEGI 15 allowed for a 15 year old' ); |
80 |
($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('K18', $borrower); |
29 |
($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('PEGI14', $borrower); |
81 |
is ( ($daysToAgeRestriction > 0), 1, "K18 blocked for a 15 year old - $offset hours" ); |
30 |
is ( ($daysToAgeRestriction <= 0), 1, 'PEGI14 allowed for a 15 year old' ); |
82 |
return; |
31 |
($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('Age 10', $borrower); |
83 |
} |
32 |
is ( ($daysToAgeRestriction <= 0), 1, 'Age 10 allowed for a 15 year old' ); |
|
|
33 |
($restriction_age, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction('K18', $borrower); |
34 |
is ( ($daysToAgeRestriction > 0), 1, 'K18 blocked for a 15 year old' ); |
35 |
- |
|
|