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