Lines 26-106
use Test::More tests => 6;
Link Here
|
26 |
|
26 |
|
27 |
use C4::Members qw|GetUpcomingMembershipExpires|; |
27 |
use C4::Members qw|GetUpcomingMembershipExpires|; |
28 |
use Koha::Database; |
28 |
use Koha::Database; |
|
|
29 |
use Koha::DateUtils; |
29 |
use t::lib::TestBuilder; |
30 |
use t::lib::TestBuilder; |
30 |
use t::lib::Mocks qw( mock_preference ); |
31 |
use t::lib::Mocks qw( mock_preference ); |
31 |
|
32 |
|
32 |
my $schema = Koha::Database->new->schema; |
33 |
my $schema = Koha::Database->new->schema; |
33 |
$schema->storage->txn_begin; |
34 |
$schema->storage->txn_begin; |
34 |
|
35 |
|
35 |
my $date_time = new Test::MockModule('DateTime'); |
36 |
my $expiry_days = 15; |
36 |
$date_time->mock( |
37 |
t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', $expiry_days ); |
37 |
'now', sub { |
38 |
my $nb_of_days_before = 1; |
38 |
return DateTime->new( |
39 |
my $nb_of_days_after = 2; |
39 |
year => 2015, |
|
|
40 |
month => 6, |
41 |
day => 15, |
42 |
); |
43 |
}); |
44 |
|
45 |
t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', 15 ); |
46 |
|
40 |
|
47 |
my $builder = t::lib::TestBuilder->new(); |
41 |
my $builder = t::lib::TestBuilder->new(); |
48 |
$builder->build({ |
|
|
49 |
source => 'Category', |
50 |
value => { |
51 |
categorycode => 'AD', |
52 |
description => 'Adult', |
53 |
enrolmentperiod => 18, |
54 |
upperagelimit => 99, |
55 |
category_type => 'A', |
56 |
}, |
57 |
}); |
58 |
|
42 |
|
59 |
my $branch = $builder->build({ |
43 |
my $library = $builder->build({ source => 'Branch' }); |
60 |
source => 'Branch', |
44 |
|
61 |
value => { |
|
|
62 |
branchname => 'My branch', |
63 |
}, |
64 |
}); |
65 |
my $branchcode = $branch->{branchcode}; |
66 |
# before we add borrowers to this branch, add the expires we have now |
45 |
# before we add borrowers to this branch, add the expires we have now |
67 |
# note that this pertains to the current mocked setting of the pref |
46 |
# note that this pertains to the current mocked setting of the pref |
68 |
# for this reason we add the new branchcode to most of the tests |
47 |
# for this reason we add the new branchcode to most of the tests |
69 |
my $expires = scalar @{ GetUpcomingMembershipExpires() }; |
48 |
my $expires = scalar @{ GetUpcomingMembershipExpires() }; |
70 |
|
49 |
|
71 |
$builder->build({ |
50 |
my $patron_1 = $builder->build({ |
72 |
source => 'Borrower', |
51 |
source => 'Borrower', |
73 |
value => { |
52 |
value => { |
74 |
firstname => 'Vincent', |
53 |
branchcode => $library->{branchcode}, |
75 |
surname => 'Martin', |
54 |
dateexpiry => dt_from_string->add( days => $expiry_days ) |
76 |
cardnumber => '80808081', |
|
|
77 |
categorycode => 'AD', |
78 |
branchcode => $branchcode, |
79 |
dateexpiry => '2015-06-30' |
80 |
}, |
55 |
}, |
81 |
}); |
56 |
}); |
82 |
|
57 |
|
83 |
$builder->build({ |
58 |
my $patron_2 = $builder->build({ |
84 |
source => 'Borrower', |
59 |
source => 'Borrower', |
85 |
value => { |
60 |
value => { |
86 |
firstname => 'Claude', |
61 |
branchcode => $library->{branchcode}, |
87 |
surname => 'Dupont', |
62 |
dateexpiry => dt_from_string->add( days => $expiry_days - $nb_of_days_before ) |
88 |
cardnumber => '80808082', |
|
|
89 |
categorycode => 'AD', |
90 |
branchcode => $branchcode, |
91 |
dateexpiry => '2015-06-29' |
92 |
}, |
63 |
}, |
93 |
}); |
64 |
}); |
94 |
|
65 |
|
95 |
$builder->build({ |
66 |
my $patron_3 = $builder->build({ |
96 |
source => 'Borrower', |
67 |
source => 'Borrower', |
97 |
value => { |
68 |
value => { |
98 |
firstname => 'Gilles', |
69 |
branchcode => $library->{branchcode}, |
99 |
surname => 'Dupond', |
70 |
dateexpiry => dt_from_string->add( days => $expiry_days + $nb_of_days_after ) |
100 |
cardnumber => '80808083', |
|
|
101 |
categorycode => 'AD', |
102 |
branchcode => $branchcode, |
103 |
dateexpiry => '2015-07-02' |
104 |
}, |
71 |
}, |
105 |
}); |
72 |
}); |
106 |
|
73 |
|
Lines 109-134
my $upcoming_mem_expires = GetUpcomingMembershipExpires();
Link Here
|
109 |
is( scalar(@$upcoming_mem_expires), $expires + 1, 'Get upcoming membership expires should return one new borrower.' ); |
76 |
is( scalar(@$upcoming_mem_expires), $expires + 1, 'Get upcoming membership expires should return one new borrower.' ); |
110 |
|
77 |
|
111 |
# Test with branch |
78 |
# Test with branch |
112 |
$upcoming_mem_expires = GetUpcomingMembershipExpires({ branch => $branchcode }); |
79 |
$upcoming_mem_expires = GetUpcomingMembershipExpires({ branch => $library->{branchcode} }); |
113 |
is( @$upcoming_mem_expires==1 && $upcoming_mem_expires->[0]{surname} eq 'Martin',1 , 'Get upcoming membership expires should return borrower "Martin".' ); |
80 |
is( @$upcoming_mem_expires==1 && $upcoming_mem_expires->[0]{surname} eq $patron_1->{surname},1 , 'Get upcoming membership expires should return the correct patron.' ); |
114 |
|
81 |
|
115 |
# Test MembershipExpiryDaysNotice == 0 |
82 |
# Test MembershipExpiryDaysNotice == 0 |
116 |
t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', 0 ); |
83 |
t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', 0 ); |
117 |
$upcoming_mem_expires = GetUpcomingMembershipExpires({ branch => $branchcode }); |
84 |
$upcoming_mem_expires = GetUpcomingMembershipExpires({ branch => $library->{branchcode} }); |
118 |
is( scalar(@$upcoming_mem_expires), 0, 'Get upcoming membership expires with MembershipExpiryDaysNotice==0 should not return new records.' ); |
85 |
is( scalar(@$upcoming_mem_expires), 0, 'Get upcoming membership expires with MembershipExpiryDaysNotice==0 should not return new records.' ); |
119 |
|
86 |
|
120 |
# Test MembershipExpiryDaysNotice == undef |
87 |
# Test MembershipExpiryDaysNotice == undef |
121 |
t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', undef ); |
88 |
t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', undef ); |
122 |
$upcoming_mem_expires = GetUpcomingMembershipExpires({ branch => $branchcode }); |
89 |
$upcoming_mem_expires = GetUpcomingMembershipExpires({ branch => $library->{branchcode} }); |
123 |
is( scalar(@$upcoming_mem_expires), 0, 'Get upcoming membership expires without MembershipExpiryDaysNotice should not return new records.' ); |
90 |
is( scalar(@$upcoming_mem_expires), 0, 'Get upcoming membership expires without MembershipExpiryDaysNotice should not return new records.' ); |
124 |
|
91 |
|
125 |
# Test the before parameter |
92 |
# Test the before parameter |
126 |
t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', 15 ); |
93 |
t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', 15 ); |
127 |
$upcoming_mem_expires = GetUpcomingMembershipExpires({ branch => $branchcode, before => 1 }); |
94 |
$upcoming_mem_expires = GetUpcomingMembershipExpires({ branch => $library->{branchcode}, before => $nb_of_days_before }); |
128 |
# Expect 29/6 and 30/6 |
95 |
# Expect 29/6 and 30/6 |
129 |
is( scalar(@$upcoming_mem_expires), 2, 'Expect two results for before==1'); |
96 |
is( scalar(@$upcoming_mem_expires), 2, 'Expect two results for before==1'); |
130 |
# Test after parameter also |
97 |
# Test after parameter also |
131 |
$upcoming_mem_expires = GetUpcomingMembershipExpires({ branch => $branchcode, before => 1, after => 2 }); |
98 |
$upcoming_mem_expires = GetUpcomingMembershipExpires({ branch => $library->{branchcode}, before => $nb_of_days_before, after => $nb_of_days_after }); |
132 |
# Expect 29/6, 30/6 and 2/7 |
99 |
# Expect 29/6, 30/6 and 2/7 |
133 |
is( scalar(@$upcoming_mem_expires), 3, 'Expect three results when adding after' ); |
100 |
is( scalar(@$upcoming_mem_expires), 3, 'Expect three results when adding after' ); |
134 |
|
101 |
|
135 |
- |
|
|