Bug 15081: (followup) Make test files using TestBuilder handle their transactions
[koha.git] / t / db_dependent / Members / GetUpcomingMembershipExpires.t
blob1026b92b22bff114102e5f3e44cda66f77318acb
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Copyright 2015 Biblibre
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.
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.
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>.
20 use Modern::Perl;
22 use Test::More tests => 5;
23 use Test::MockModule;
24 use t::lib::TestBuilder;
25 use t::lib::Mocks qw( mock_preference );
27 use C4::Members;
28 use Koha::Database;
30 BEGIN {
31 use_ok('C4::Members');
34 my $schema = Koha::Database->new->schema;
35 $schema->storage->txn_begin;
37 my $date_time = new Test::MockModule('DateTime');
38 $date_time->mock(
39 'now', sub {
40 return DateTime->new(
41 year => 2015,
42 month => 6,
43 day => 15,
46 });
48 t::lib::Mocks::mock_preference('MembershipExpiryDaysNotice', 15);
50 my $builder = t::lib::TestBuilder->new();
51 $builder->build({
52 source => 'Category',
53 value => {
54 categorycode => 'AD',
55 description => 'Adult',
56 enrolmentperiod => 18,
57 upperagelimit => 99,
58 category_type => 'A',
60 });
62 $builder->build({
63 source => 'Branch',
64 value => {
65 branchcode => 'CR',
66 branchname => 'My branch',
68 });
70 $builder->build({
71 source => 'Borrower',
72 value => {
73 firstname => 'Vincent',
74 surname => 'Martin',
75 cardnumber => '80808081',
76 categorycode => 'AD',
77 branchcode => 'CR',
78 dateexpiry => '2015-06-30'
80 });
82 $builder->build({
83 source => 'Borrower',
84 value => {
85 firstname => 'Claude',
86 surname => 'Dupont',
87 cardnumber => '80808082',
88 categorycode => 'AD',
89 branchcode => 'CR',
90 dateexpiry => '2015-06-29'
92 });
94 $builder->build({
95 source => 'Borrower',
96 value => {
97 firstname => 'Gilles',
98 surname => 'Dupond',
99 cardnumber => '80808083',
100 categorycode => 'AD',
101 branchcode => 'CR',
102 dateexpiry => '2015-07-02'
106 my $upcoming_mem_expires = C4::Members::GetUpcomingMembershipExpires();
107 is(scalar(@$upcoming_mem_expires), 1, 'Get upcoming membership expires should return 1 borrower.');
109 is($upcoming_mem_expires->[0]{surname}, 'Martin', 'Get upcoming membership expires should return borrower "Martin".');
111 # Test GetUpcomingMembershipExpires() with MembershipExpiryDaysNotice == 0
112 t::lib::Mocks::mock_preference('MembershipExpiryDaysNotice', 0);
114 $upcoming_mem_expires = C4::Members::GetUpcomingMembershipExpires();
115 is(scalar(@$upcoming_mem_expires), 0, 'Get upcoming membership expires with 0 MembershipExpiryDaysNotice should return 0.');
117 # Test GetUpcomingMembershipExpires() with MembershipExpiryDaysNotice == undef
118 t::lib::Mocks::mock_preference('MembershipExpiryDaysNotice', undef);
120 $upcoming_mem_expires = C4::Members::GetUpcomingMembershipExpires();
121 is(scalar(@$upcoming_mem_expires), 0, 'Get upcoming membership expires without MembershipExpiryDaysNotice should return 0.');
123 $schema->storage->txn_rollback;