Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright The National Library of Finland, University of Helsinki 2020 |
4 |
# Copyright Petro Vashchuk <stalkernoid@gmail.com> 2020 |
5 |
# |
6 |
# This file is part of Koha. |
7 |
# |
8 |
# Koha is free software; you can redistribute it and/or modify it under the |
9 |
# terms of the GNU General Public License as published by the Free Software |
10 |
# Foundation; either version 3 of the License, or (at your option) any later |
11 |
# version. |
12 |
# |
13 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
14 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
15 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License along |
18 |
# with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
20 |
use Modern::Perl; |
21 |
|
22 |
use C4::Context; |
23 |
use Koha::CirculationRules; |
24 |
|
25 |
use Test::More tests => 10; |
26 |
|
27 |
use t::lib::TestBuilder; |
28 |
use t::lib::Mocks; |
29 |
use Koha::Holds; |
30 |
|
31 |
use Koha::Account; |
32 |
use Koha::Account::DebitTypes; |
33 |
|
34 |
BEGIN { |
35 |
use_ok('C4::Reserves'); |
36 |
} |
37 |
|
38 |
my $schema = Koha::Database->schema; |
39 |
$schema->storage->txn_begin; |
40 |
my $dbh = C4::Context->dbh; |
41 |
|
42 |
my $builder = t::lib::TestBuilder->new; |
43 |
|
44 |
my $library1 = $builder->build({ |
45 |
source => 'Branch', |
46 |
}); |
47 |
|
48 |
my $bib_title = "Test Title"; |
49 |
|
50 |
my $borrower = $builder->build({ |
51 |
source => 'Borrower', |
52 |
value => { |
53 |
branchcode => $library1->{branchcode}, |
54 |
} |
55 |
}); |
56 |
|
57 |
my $borrowernumber = $borrower->{borrowernumber}; |
58 |
my $library_A_code = $library1->{branchcode}; |
59 |
|
60 |
my $biblio = $builder->build_sample_biblio({itemtype=>'BK'}); |
61 |
my $biblionumber = $biblio->biblionumber; |
62 |
my $item1 = $builder->build_sample_item({ |
63 |
biblionumber => $biblionumber, |
64 |
itype => 'CF', |
65 |
homebranch => $library_A_code, |
66 |
holdingbranch => $library_A_code |
67 |
}); |
68 |
my $item2 = $builder->build_sample_item({ |
69 |
biblionumber => $biblionumber, |
70 |
itype => 'MU', |
71 |
homebranch => $library_A_code, |
72 |
holdingbranch => $library_A_code |
73 |
}); |
74 |
my $item3 = $builder->build_sample_item({ |
75 |
biblionumber => $biblionumber, |
76 |
itype => 'MX', |
77 |
homebranch => $library_A_code, |
78 |
holdingbranch => $library_A_code |
79 |
}); |
80 |
|
81 |
$dbh->do("DELETE FROM circulation_rules"); |
82 |
Koha::CirculationRules->set_rules( |
83 |
{ |
84 |
itemtype => 'CF', |
85 |
categorycode => undef, |
86 |
branchcode => undef, |
87 |
rules => { |
88 |
expire_reserves_charge => '111' |
89 |
} |
90 |
} |
91 |
); |
92 |
Koha::CirculationRules->set_rules( |
93 |
{ |
94 |
itemtype => 'MU', |
95 |
categorycode => undef, |
96 |
branchcode => undef, |
97 |
rules => { |
98 |
expire_reserves_charge => undef |
99 |
} |
100 |
} |
101 |
); |
102 |
|
103 |
my $reserve_id; |
104 |
my $account; |
105 |
my $status; |
106 |
my $start_balance; |
107 |
|
108 |
# TEST: Hold Computer File item |
109 |
$reserve_id = AddReserve( |
110 |
{ |
111 |
branchcode => $library_A_code, |
112 |
borrowernumber => $borrowernumber, |
113 |
biblionumber => $biblionumber, |
114 |
priority => 1, |
115 |
itemnumber => $item1->itemnumber, |
116 |
} |
117 |
); |
118 |
|
119 |
$account = Koha::Account->new({ patron_id => $borrowernumber }); |
120 |
|
121 |
( $status ) = CheckReserves($item1->id); |
122 |
is( $status, 'Reserved', "Hold for the CF created" ); |
123 |
|
124 |
$start_balance = $account->balance(); |
125 |
|
126 |
Koha::Holds->find( $reserve_id )->cancel({ charge_cancel_fee => 1 }); |
127 |
|
128 |
( $status ) = CheckReserves($item1->id); |
129 |
is( $status, '', "Hold for the CF cancelled" ); |
130 |
|
131 |
is( $account->balance() - $start_balance, 111, "Account debt is 111" ); |
132 |
|
133 |
# TEST: Hold Music item that has 'expire_reserves_charge' set undef |
134 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 222); |
135 |
|
136 |
$reserve_id = AddReserve( |
137 |
{ |
138 |
branchcode => $library_A_code, |
139 |
borrowernumber => $borrowernumber, |
140 |
biblionumber => $biblionumber, |
141 |
priority => 1, |
142 |
itemnumber => $item2->itemnumber, |
143 |
} |
144 |
); |
145 |
|
146 |
$account = Koha::Account->new({ patron_id => $borrowernumber }); |
147 |
|
148 |
( $status ) = CheckReserves($item2->id); |
149 |
is( $status, 'Reserved', "Hold for the MU created" ); |
150 |
|
151 |
$start_balance = $account->balance(); |
152 |
|
153 |
Koha::Holds->find( $reserve_id )->cancel({ charge_cancel_fee => 1 }); |
154 |
|
155 |
( $status ) = CheckReserves($item2->id); |
156 |
is( $status, '', "Hold for the MU cancelled" ); |
157 |
|
158 |
is( $account->balance() - $start_balance, 222, "Account debt is 222" ); |
159 |
|
160 |
# TEST: Hold MX item that has no circulation rules |
161 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 333); |
162 |
|
163 |
$reserve_id = AddReserve( |
164 |
{ |
165 |
branchcode => $library_A_code, |
166 |
borrowernumber => $borrowernumber, |
167 |
biblionumber => $biblionumber, |
168 |
priority => 1, |
169 |
itemnumber => $item3->itemnumber, |
170 |
} |
171 |
); |
172 |
|
173 |
$account = Koha::Account->new({ patron_id => $borrowernumber }); |
174 |
|
175 |
( $status ) = CheckReserves($item3->id); |
176 |
is( $status, 'Reserved', "Hold for the MX created" ); |
177 |
|
178 |
$start_balance = $account->balance(); |
179 |
|
180 |
Koha::Holds->find( $reserve_id )->cancel({ charge_cancel_fee => 1 }); |
181 |
|
182 |
( $status ) = CheckReserves($item3->id); |
183 |
is( $status, '', "Hold for the MX cancelled" ); |
184 |
|
185 |
is( $account->balance() - $start_balance, 333, "Account debt is 333" ); |
186 |
|
187 |
$schema->storage->txn_rollback; |