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