|
Lines 279-293
subtest 'get_lostreturn_policy() tests' => sub {
Link Here
|
| 279 |
|
279 |
|
| 280 |
$schema->resultset('CirculationRule')->search()->delete; |
280 |
$schema->resultset('CirculationRule')->search()->delete; |
| 281 |
|
281 |
|
| 282 |
my $default_rule = $builder->build( |
282 |
my $default_rule_charge = $builder->build( |
| 283 |
{ |
283 |
{ |
| 284 |
source => 'CirculationRule', |
284 |
source => 'CirculationRule', |
| 285 |
value => { |
285 |
value => { |
| 286 |
branchcode => undef, |
286 |
branchcode => undef, |
| 287 |
categorycode => undef, |
287 |
categorycode => undef, |
| 288 |
itemtype => undef, |
288 |
itemtype => undef, |
| 289 |
rule_name => 'refund', |
289 |
rule_name => 'lostreturn', |
| 290 |
rule_value => 1 |
290 |
rule_value => 'charge' |
| 291 |
} |
291 |
} |
| 292 |
} |
292 |
} |
| 293 |
); |
293 |
); |
|
Lines 299-332
subtest 'get_lostreturn_policy() tests' => sub {
Link Here
|
| 299 |
branchcode => $branchcode, |
299 |
branchcode => $branchcode, |
| 300 |
categorycode => undef, |
300 |
categorycode => undef, |
| 301 |
itemtype => undef, |
301 |
itemtype => undef, |
| 302 |
rule_name => 'refund', |
302 |
rule_name => 'lostreturn', |
| 303 |
rule_value => 0 |
303 |
rule_value => 0 |
| 304 |
} |
304 |
} |
| 305 |
} |
305 |
} |
| 306 |
); |
306 |
); |
| 307 |
my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
307 |
my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 308 |
my $specific_rule_true = $builder->build( |
308 |
my $specific_rule_refund = $builder->build( |
| 309 |
{ |
309 |
{ |
| 310 |
source => 'CirculationRule', |
310 |
source => 'CirculationRule', |
| 311 |
value => { |
311 |
value => { |
| 312 |
branchcode => $branchcode2, |
312 |
branchcode => $branchcode2, |
| 313 |
categorycode => undef, |
313 |
categorycode => undef, |
| 314 |
itemtype => undef, |
314 |
itemtype => undef, |
| 315 |
rule_name => 'refund', |
315 |
rule_name => 'lostreturn', |
| 316 |
rule_value => 1 |
316 |
rule_value => 'refund' |
| 317 |
} |
317 |
} |
| 318 |
} |
318 |
} |
| 319 |
); |
319 |
); |
| 320 |
# Make sure we have an unused branchcode |
|
|
| 321 |
my $branchcode3 = $builder->build( { source => 'Branch' } )->{branchcode}; |
320 |
my $branchcode3 = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 322 |
my $specific_rule_dummy = $builder->build( |
321 |
my $specific_rule_restore = $builder->build( |
| 323 |
{ |
322 |
{ |
| 324 |
source => 'CirculationRule', |
323 |
source => 'CirculationRule', |
| 325 |
value => { |
324 |
value => { |
| 326 |
branchcode => $branchcode3, |
325 |
branchcode => $branchcode3, |
| 327 |
categorycode => undef, |
326 |
categorycode => undef, |
| 328 |
itemtype => undef, |
327 |
itemtype => undef, |
| 329 |
rule_name => 'refund', |
328 |
rule_name => 'lostreturn', |
|
|
329 |
rule_value => 'restore' |
| 330 |
} |
| 331 |
} |
| 332 |
); |
| 333 |
|
| 334 |
# Make sure we have an unused branchcode |
| 335 |
my $branchcode4 = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 336 |
my $specific_rule_dummy = $builder->build( |
| 337 |
{ |
| 338 |
source => 'CirculationRule', |
| 339 |
value => { |
| 340 |
branchcode => $branchcode4, |
| 341 |
categorycode => undef, |
| 342 |
itemtype => undef, |
| 343 |
rule_name => 'lostreturn', |
| 344 |
rule_value => 'refund' |
| 330 |
} |
345 |
} |
| 331 |
} |
346 |
} |
| 332 |
); |
347 |
); |
|
Lines 337-343
subtest 'get_lostreturn_policy() tests' => sub {
Link Here
|
| 337 |
branchcode => $branch_without_rule, |
352 |
branchcode => $branch_without_rule, |
| 338 |
categorycode => undef, |
353 |
categorycode => undef, |
| 339 |
itemtype => undef, |
354 |
itemtype => undef, |
| 340 |
rule_name => 'refund' |
355 |
rule_name => 'lostreturn', |
|
|
356 |
rule_value => 'refund' |
| 341 |
} |
357 |
} |
| 342 |
) |
358 |
) |
| 343 |
->next |
359 |
->next |
|
Lines 345-380
subtest 'get_lostreturn_policy() tests' => sub {
Link Here
|
| 345 |
|
361 |
|
| 346 |
my $item = $builder->build_sample_item( |
362 |
my $item = $builder->build_sample_item( |
| 347 |
{ |
363 |
{ |
| 348 |
homebranch => $specific_rule_false->{branchcode}, |
364 |
homebranch => $specific_rule_restore->{branchcode}, |
| 349 |
holdingbranch => $specific_rule_true->{branchcode} |
365 |
holdingbranch => $specific_rule_false->{branchcode} |
| 350 |
} |
366 |
} |
| 351 |
); |
367 |
); |
| 352 |
my $params = { |
368 |
my $params = { |
| 353 |
return_branch => $specific_rule_true->{ branchcode }, |
369 |
return_branch => $specific_rule_refund->{ branchcode }, |
| 354 |
item => $item |
370 |
item => $item |
| 355 |
}; |
371 |
}; |
| 356 |
|
372 |
|
| 357 |
# Specific rules |
373 |
# Specific rules |
| 358 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' ); |
374 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' ); |
| 359 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
375 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
| 360 |
1,'Specific rule for checkin branch is applied (true)'); |
376 |
'refund','Specific rule for checkin branch is applied (refund)'); |
| 361 |
|
377 |
|
| 362 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' ); |
378 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' ); |
| 363 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
379 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
| 364 |
0,'Specific rule for home branch is applied (false)'); |
380 |
'restore','Specific rule for home branch is applied (restore)'); |
| 365 |
|
381 |
|
| 366 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' ); |
382 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' ); |
| 367 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
383 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
| 368 |
1,'Specific rule for holding branch is applied (true)'); |
384 |
0,'Specific rule for holding branch is applied (false)'); |
| 369 |
|
385 |
|
| 370 |
# Default rule check |
386 |
# Default rule check |
| 371 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' ); |
387 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' ); |
| 372 |
$params->{return_branch} = $branch_without_rule; |
388 |
$params->{return_branch} = $branch_without_rule; |
| 373 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
389 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
| 374 |
1,'No rule for branch, global rule applied (true)'); |
390 |
'charge','No rule for branch, global rule applied (charge)'); |
| 375 |
|
391 |
|
| 376 |
# Change the default value just to try |
392 |
# Change the default value just to try |
| 377 |
Koha::CirculationRules->search({ branchcode => undef, rule_name => 'refund' })->next->rule_value(0)->store; |
393 |
Koha::CirculationRules->search({ branchcode => undef, rule_name => 'lostreturn' })->next->rule_value(0)->store; |
| 378 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
394 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
| 379 |
0,'No rule for branch, global rule applied (false)'); |
395 |
0,'No rule for branch, global rule applied (false)'); |
| 380 |
|
396 |
|
|
Lines 385-402
subtest 'get_lostreturn_policy() tests' => sub {
Link Here
|
| 385 |
branchcode => undef, |
401 |
branchcode => undef, |
| 386 |
categorycode => undef, |
402 |
categorycode => undef, |
| 387 |
itemtype => undef, |
403 |
itemtype => undef, |
| 388 |
rule_name => 'refund' |
404 |
rule_name => 'lostreturn' |
| 389 |
} |
405 |
} |
| 390 |
) |
406 |
) |
| 391 |
->next |
407 |
->next |
| 392 |
->delete; |
408 |
->delete; |
| 393 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
409 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
| 394 |
1,'No rule for branch, no default rule, fallback default (true)'); |
410 |
'refund','No rule for branch, no default rule, fallback default (refund)'); |
| 395 |
|
411 |
|
| 396 |
# Fallback to ItemHoldBranch if CheckinLibrary is undefined |
412 |
# Fallback to ItemHoldBranch if CheckinLibrary is undefined |
| 397 |
$params->{return_branch} = undef; |
413 |
$params->{return_branch} = undef; |
| 398 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
414 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
| 399 |
0,'return_branch undefined, fallback to ItemHomeBranch rule (false)'); |
415 |
'restore','return_branch undefined, fallback to ItemHomeBranch rule (restore)'); |
| 400 |
|
416 |
|
| 401 |
$schema->storage->txn_rollback; |
417 |
$schema->storage->txn_rollback; |
| 402 |
}; |
418 |
}; |