Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Copyright 2015 Biblibre |
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 |
|
20 |
use Modern::Perl; |
21 |
use C4::Members; |
22 |
use Test::MockModule; |
23 |
use t::lib::TestBuilder; |
24 |
use t::lib::Mocks qw( mock_preference ); |
25 |
|
26 |
use Test::More tests => 5; |
27 |
use Test::MockModule; |
28 |
|
29 |
BEGIN { |
30 |
use_ok('C4::Members'); |
31 |
} |
32 |
|
33 |
my $date_time = new Test::MockModule('DateTime'); |
34 |
$date_time->mock( |
35 |
'now', sub { |
36 |
return DateTime->new( |
37 |
year => 2015, |
38 |
month => 6, |
39 |
day => 15, |
40 |
); |
41 |
|
42 |
}); |
43 |
|
44 |
t::lib::Mocks::mock_preference('MembershipExpiryDaysNotice', 15); |
45 |
|
46 |
my $builder = t::lib::TestBuilder->new(); |
47 |
$builder->build({ |
48 |
source => 'Category', |
49 |
value => { |
50 |
categorycode => 'AD', |
51 |
description => 'Adult', |
52 |
enrolmentperiod => 18, |
53 |
upperagelimit => 99, |
54 |
category_type => 'A', |
55 |
}, |
56 |
}); |
57 |
|
58 |
$builder->build({ |
59 |
source => 'Branch', |
60 |
value => { |
61 |
branchcode => 'CR', |
62 |
branchname => 'My branch', |
63 |
}, |
64 |
}); |
65 |
|
66 |
$builder->build({ |
67 |
source => 'Borrower', |
68 |
value => { |
69 |
firstname => 'Vincent', |
70 |
surname => 'Martin', |
71 |
cardnumber => '80808081', |
72 |
categorycode => 'AD', |
73 |
branchcode => 'CR', |
74 |
dateexpiry => '2015-06-30' |
75 |
}, |
76 |
}); |
77 |
|
78 |
$builder->build({ |
79 |
source => 'Borrower', |
80 |
value => { |
81 |
firstname => 'Claude', |
82 |
surname => 'Dupont', |
83 |
cardnumber => '80808082', |
84 |
categorycode => 'AD', |
85 |
branchcode => 'CR', |
86 |
dateexpiry => '2015-06-29' |
87 |
}, |
88 |
}); |
89 |
|
90 |
$builder->build({ |
91 |
source => 'Borrower', |
92 |
value => { |
93 |
firstname => 'Gilles', |
94 |
surname => 'Dupond', |
95 |
cardnumber => '80808083', |
96 |
categorycode => 'AD', |
97 |
branchcode => 'CR', |
98 |
dateexpiry => '2015-07-02' |
99 |
}, |
100 |
}); |
101 |
|
102 |
my $upcoming_mem_expires = C4::Members::GetUpcomingMembershipExpires(); |
103 |
is(scalar(@$upcoming_mem_expires), 1, 'Get upcoming membership expires should return 1 borrower.'); |
104 |
|
105 |
is($upcoming_mem_expires->[0]{surname}, 'Martin', 'Get upcoming membership expires should return borrower "Martin".'); |
106 |
|
107 |
# Test GetUpcomingMembershipExpires() with MembershipExpiryDaysNotice == 0 |
108 |
t::lib::Mocks::mock_preference('MembershipExpiryDaysNotice', 0); |
109 |
|
110 |
$upcoming_mem_expires = C4::Members::GetUpcomingMembershipExpires(); |
111 |
is(scalar(@$upcoming_mem_expires), 0, 'Get upcoming membership expires with 0 MembershipExpiryDaysNotice should return 0.'); |
112 |
|
113 |
# Test GetUpcomingMembershipExpires() with MembershipExpiryDaysNotice == undef |
114 |
t::lib::Mocks::mock_preference('MembershipExpiryDaysNotice', undef); |
115 |
|
116 |
$upcoming_mem_expires = C4::Members::GetUpcomingMembershipExpires(); |
117 |
is(scalar(@$upcoming_mem_expires), 0, 'Get upcoming membership expires without MembershipExpiryDaysNotice should return 0.'); |