Lines 133-208
subtest 'cancel' => sub {
Link Here
|
133 |
is( $third_hold->discard_changes->priority, 2, 'Third hold should now be second' ); |
133 |
is( $third_hold->discard_changes->priority, 2, 'Third hold should now be second' ); |
134 |
|
134 |
|
135 |
subtest 'charge_cancel_fee parameter' => sub { |
135 |
subtest 'charge_cancel_fee parameter' => sub { |
136 |
plan tests => 15; |
136 |
plan tests => 18; |
137 |
my $library1 = $builder->build({ |
137 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
138 |
source => 'Branch', |
138 |
my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
139 |
}); |
139 |
my $library3 = $builder->build_object( { class => 'Koha::Libraries' } ); |
140 |
my $library2 = $builder->build({ |
|
|
141 |
source => 'Branch', |
142 |
}); |
143 |
|
140 |
|
144 |
my $bib_title = "Test Title"; |
141 |
my $bib_title = "Test Title"; |
145 |
|
142 |
|
146 |
my $borrower = $builder->build({ |
143 |
my $borrower = $builder->build_object({ class => "Koha::Patrons", value => { branchcode => $library1->branchcode } }); |
147 |
source => 'Borrower', |
|
|
148 |
value => { |
149 |
branchcode => $library1->{branchcode}, |
150 |
} |
151 |
}); |
152 |
|
144 |
|
153 |
my $itemtype1 = $builder->build({ |
145 |
my $itemtype1 = $builder->build_object( { class => 'Koha::ItemTypes', value => {} } ); |
154 |
source => 'Itemtype', |
146 |
my $itemtype2 = $builder->build_object( { class => 'Koha::ItemTypes', value => {} } ); |
155 |
value => {} |
147 |
my $itemtype3 = $builder->build_object( { class => 'Koha::ItemTypes', value => {} } ); |
156 |
}); |
148 |
my $itemtype4 = $builder->build_object( { class => 'Koha::ItemTypes', value => {} } ); |
157 |
my $itemtype2 = $builder->build({ |
|
|
158 |
source => 'Itemtype', |
159 |
value => {} |
160 |
}); |
161 |
my $itemtype3 = $builder->build({ |
162 |
source => 'Itemtype', |
163 |
value => {} |
164 |
}); |
165 |
my $itemtype4 = $builder->build({ |
166 |
source => 'Itemtype', |
167 |
value => {} |
168 |
}); |
169 |
|
149 |
|
170 |
my $borrowernumber = $borrower->{borrowernumber}; |
150 |
my $borrowernumber = $borrower->borrowernumber; |
171 |
|
151 |
|
172 |
my $library_A_code = $library1->{branchcode}; |
152 |
my $library_A_code = $library1->branchcode; |
173 |
|
153 |
|
174 |
my $biblio = $builder->build_sample_biblio({itemtype => $itemtype1->{itemtype}}); |
154 |
my $biblio = $builder->build_sample_biblio({itemtype => $itemtype1->itemtype}); |
175 |
my $biblionumber = $biblio->biblionumber; |
155 |
my $biblionumber = $biblio->biblionumber; |
176 |
my $item1 = $builder->build_sample_item({ |
156 |
my $item1 = $builder->build_sample_item({ |
177 |
biblionumber => $biblionumber, |
157 |
biblionumber => $biblionumber, |
178 |
itype => $itemtype1->{itemtype}, |
158 |
itype => $itemtype1->itemtype, |
179 |
homebranch => $library_A_code, |
159 |
homebranch => $library_A_code, |
180 |
holdingbranch => $library_A_code |
160 |
holdingbranch => $library_A_code |
181 |
}); |
161 |
}); |
182 |
my $item2 = $builder->build_sample_item({ |
162 |
my $item2 = $builder->build_sample_item({ |
183 |
biblionumber => $biblionumber, |
163 |
biblionumber => $biblionumber, |
184 |
itype => $itemtype2->{itemtype}, |
164 |
itype => $itemtype2->itemtype, |
185 |
homebranch => $library_A_code, |
165 |
homebranch => $library_A_code, |
186 |
holdingbranch => $library_A_code |
166 |
holdingbranch => $library_A_code |
187 |
}); |
167 |
}); |
188 |
my $item3 = $builder->build_sample_item({ |
168 |
my $item3 = $builder->build_sample_item({ |
189 |
biblionumber => $biblionumber, |
169 |
biblionumber => $biblionumber, |
190 |
itype => $itemtype3->{itemtype}, |
170 |
itype => $itemtype3->itemtype, |
191 |
homebranch => $library_A_code, |
171 |
homebranch => $library_A_code, |
192 |
holdingbranch => $library_A_code |
172 |
holdingbranch => $library_A_code |
193 |
}); |
173 |
}); |
194 |
|
174 |
|
195 |
my $library_B_code = $library2->{branchcode}; |
175 |
my $library_B_code = $library2->branchcode; |
196 |
|
176 |
|
197 |
my $biblio2 = $builder->build_sample_biblio({itemtype => $itemtype4->{itemtype}}); |
177 |
my $biblio2 = $builder->build_sample_biblio({itemtype => $itemtype4->itemtype}); |
198 |
my $biblionumber2 = $biblio2->biblionumber; |
178 |
my $biblionumber2 = $biblio2->biblionumber; |
199 |
my $item4 = $builder->build_sample_item({ |
179 |
my $item4 = $builder->build_sample_item({ |
200 |
biblionumber => $biblionumber2, |
180 |
biblionumber => $biblionumber2, |
201 |
itype => $itemtype4->{itemtype}, |
181 |
itype => $itemtype4->itemtype, |
202 |
homebranch => $library_B_code, |
182 |
homebranch => $library_B_code, |
203 |
holdingbranch => $library_B_code |
183 |
holdingbranch => $library_B_code |
204 |
}); |
184 |
}); |
205 |
|
185 |
|
|
|
186 |
my $library_C_code = $library3->branchcode; |
187 |
|
188 |
my $biblio3 = $builder->build_sample_biblio({itemtype => $itemtype4->itemtype}); |
189 |
my $biblionumber3 = $biblio3->biblionumber; |
190 |
my $item5 = $builder->build_sample_item({ |
191 |
biblionumber => $biblionumber3, |
192 |
itype => $itemtype4->itemtype, |
193 |
homebranch => $library_C_code, |
194 |
holdingbranch => $library_C_code |
195 |
}); |
196 |
|
206 |
Koha::CirculationRules->set_rules( |
197 |
Koha::CirculationRules->set_rules( |
207 |
{ |
198 |
{ |
208 |
itemtype => undef, |
199 |
itemtype => undef, |
Lines 215-221
subtest 'cancel' => sub {
Link Here
|
215 |
); |
206 |
); |
216 |
Koha::CirculationRules->set_rules( |
207 |
Koha::CirculationRules->set_rules( |
217 |
{ |
208 |
{ |
218 |
itemtype => $itemtype1->{itemtype}, |
209 |
itemtype => $itemtype1->itemtype, |
219 |
categorycode => undef, |
210 |
categorycode => undef, |
220 |
branchcode => undef, |
211 |
branchcode => undef, |
221 |
rules => { |
212 |
rules => { |
Lines 225-231
subtest 'cancel' => sub {
Link Here
|
225 |
); |
216 |
); |
226 |
Koha::CirculationRules->set_rules( |
217 |
Koha::CirculationRules->set_rules( |
227 |
{ |
218 |
{ |
228 |
itemtype => $itemtype2->{itemtype}, |
219 |
itemtype => $itemtype2->itemtype, |
229 |
categorycode => undef, |
220 |
categorycode => undef, |
230 |
branchcode => undef, |
221 |
branchcode => undef, |
231 |
rules => { |
222 |
rules => { |
Lines 243-248
subtest 'cancel' => sub {
Link Here
|
243 |
} |
234 |
} |
244 |
} |
235 |
} |
245 |
); |
236 |
); |
|
|
237 |
Koha::CirculationRules->set_rules( |
238 |
{ |
239 |
itemtype => undef, |
240 |
categorycode => undef, |
241 |
branchcode => $library_C_code, |
242 |
rules => { |
243 |
expire_reserves_charge => '0' |
244 |
} |
245 |
} |
246 |
); |
246 |
|
247 |
|
247 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
248 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
248 |
|
249 |
|
Lines 251-257
subtest 'cancel' => sub {
Link Here
|
251 |
my $status; |
252 |
my $status; |
252 |
my $start_balance; |
253 |
my $start_balance; |
253 |
|
254 |
|
254 |
# TEST: Hold itemtype1 item |
255 |
# TEST: Hold itemtype1 item |
255 |
$reserve_id = AddReserve( |
256 |
$reserve_id = AddReserve( |
256 |
{ |
257 |
{ |
257 |
branchcode => $library_A_code, |
258 |
branchcode => $library_A_code, |
Lines 276-282
subtest 'cancel' => sub {
Link Here
|
276 |
|
277 |
|
277 |
is( $account->balance() - $start_balance, 111, "Used circulation rule for itemtype1" ); |
278 |
is( $account->balance() - $start_balance, 111, "Used circulation rule for itemtype1" ); |
278 |
|
279 |
|
279 |
# TEST: circulation rule for itemtype2 has 'expire_reserves_charge' set undef, so it should use ExpireReservesMaxPickUpDelayCharge preference |
280 |
# TEST: circulation rule for itemtype2 has 'expire_reserves_charge' set undef, so it should use ExpireReservesMaxPickUpDelayCharge preference |
280 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 222); |
281 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 222); |
281 |
|
282 |
|
282 |
$reserve_id = AddReserve( |
283 |
$reserve_id = AddReserve( |
Lines 303-309
subtest 'cancel' => sub {
Link Here
|
303 |
|
304 |
|
304 |
is( $account->balance() - $start_balance, 222, "Used ExpireReservesMaxPickUpDelayCharge preference as expire_reserves_charge set to undef" ); |
305 |
is( $account->balance() - $start_balance, 222, "Used ExpireReservesMaxPickUpDelayCharge preference as expire_reserves_charge set to undef" ); |
305 |
|
306 |
|
306 |
# TEST: no circulation rules for itemtype3, it should use ExpireReservesMaxPickUpDelayCharge preference |
307 |
# TEST: no circulation rules for itemtype3, it should use ExpireReservesMaxPickUpDelayCharge preference |
307 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 333); |
308 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 333); |
308 |
|
309 |
|
309 |
$reserve_id = AddReserve( |
310 |
$reserve_id = AddReserve( |
Lines 330-336
subtest 'cancel' => sub {
Link Here
|
330 |
|
331 |
|
331 |
is( $account->balance() - $start_balance, 333, "Used ExpireReservesMaxPickUpDelayCharge preference as there's no circulation rules for itemtype3" ); |
332 |
is( $account->balance() - $start_balance, 333, "Used ExpireReservesMaxPickUpDelayCharge preference as there's no circulation rules for itemtype3" ); |
332 |
|
333 |
|
333 |
# TEST: circulation rule for itemtype4 with library_B_code |
334 |
# TEST: circulation rule for itemtype4 with library_B_code |
334 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 555); |
335 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 555); |
335 |
|
336 |
|
336 |
$reserve_id = AddReserve( |
337 |
$reserve_id = AddReserve( |
Lines 357-362
subtest 'cancel' => sub {
Link Here
|
357 |
|
358 |
|
358 |
is( $account->balance() - $start_balance, 444, "Used circulation rule for itemtype4 with library_B_code" ); |
359 |
is( $account->balance() - $start_balance, 444, "Used circulation rule for itemtype4 with library_B_code" ); |
359 |
|
360 |
|
|
|
361 |
# TEST: circulation rule for library_C_code that has expire_reserves_charge = 0 |
362 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 777); |
363 |
|
364 |
$reserve_id = AddReserve( |
365 |
{ |
366 |
branchcode => $library_C_code, |
367 |
borrowernumber => $borrowernumber, |
368 |
biblionumber => $biblionumber3, |
369 |
priority => 1, |
370 |
itemnumber => $item5->itemnumber, |
371 |
} |
372 |
); |
373 |
|
374 |
$account = Koha::Account->new({ patron_id => $borrowernumber }); |
375 |
|
376 |
( $status ) = CheckReserves($item5->id); |
377 |
is( $status, 'Reserved', "Hold for the itemtype5 created" ); |
378 |
|
379 |
$start_balance = $account->balance(); |
380 |
|
381 |
Koha::Holds->find( $reserve_id )->cancel({ charge_cancel_fee => 1 }); |
382 |
|
383 |
( $status ) = CheckReserves($item5->id); |
384 |
is( $status, '', "Hold for the itemtype5 cancelled" ); |
385 |
|
386 |
is( $account->balance() - $start_balance, 0, "Used circulation rule for itemtype4 with library_C_code even though it's 0" ); |
387 |
|
388 |
# TEST: charge_cancel_fee is 0 |
360 |
$reserve_id = AddReserve( |
389 |
$reserve_id = AddReserve( |
361 |
{ |
390 |
{ |
362 |
branchcode => $library_B_code, |
391 |
branchcode => $library_B_code, |
363 |
- |
|
|