Lines 298-305
subtest 'get_lostreturn_policy() tests' => sub {
Link Here
|
298 |
branchcode => undef, |
298 |
branchcode => undef, |
299 |
categorycode => undef, |
299 |
categorycode => undef, |
300 |
itemtype => undef, |
300 |
itemtype => undef, |
301 |
rule_name => 'refund', |
301 |
rule_name => 'lostreturn', |
302 |
rule_value => 1 |
302 |
rule_value => 'charge' |
303 |
} |
303 |
} |
304 |
} |
304 |
} |
305 |
); |
305 |
); |
Lines 311-331
subtest 'get_lostreturn_policy() tests' => sub {
Link Here
|
311 |
branchcode => $branchcode, |
311 |
branchcode => $branchcode, |
312 |
categorycode => undef, |
312 |
categorycode => undef, |
313 |
itemtype => undef, |
313 |
itemtype => undef, |
314 |
rule_name => 'refund', |
314 |
rule_name => 'lostreturn', |
315 |
rule_value => 0 |
315 |
rule_value => 0 |
316 |
} |
316 |
} |
317 |
} |
317 |
} |
318 |
); |
318 |
); |
319 |
my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
319 |
my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
320 |
my $specific_rule_true = $builder->build( |
320 |
my $specific_rule_refund = $builder->build( |
321 |
{ |
321 |
{ |
322 |
source => 'CirculationRule', |
322 |
source => 'CirculationRule', |
323 |
value => { |
323 |
value => { |
324 |
branchcode => $branchcode2, |
324 |
branchcode => $branchcode2, |
325 |
categorycode => undef, |
325 |
categorycode => undef, |
326 |
itemtype => undef, |
326 |
itemtype => undef, |
327 |
rule_name => 'refund', |
327 |
rule_name => 'lostreturn', |
328 |
rule_value => 1 |
328 |
rule_value => 'refund' |
329 |
} |
329 |
} |
330 |
} |
330 |
} |
331 |
); |
331 |
); |
Lines 338-344
subtest 'get_lostreturn_policy() tests' => sub {
Link Here
|
338 |
branchcode => $branchcode3, |
338 |
branchcode => $branchcode3, |
339 |
categorycode => undef, |
339 |
categorycode => undef, |
340 |
itemtype => undef, |
340 |
itemtype => undef, |
341 |
rule_name => 'refund', |
341 |
rule_name => 'lostreturn', |
|
|
342 |
rule_value => 'restore' |
342 |
} |
343 |
} |
343 |
} |
344 |
} |
344 |
); |
345 |
); |
Lines 349-355
subtest 'get_lostreturn_policy() tests' => sub {
Link Here
|
349 |
branchcode => $branch_without_rule, |
350 |
branchcode => $branch_without_rule, |
350 |
categorycode => undef, |
351 |
categorycode => undef, |
351 |
itemtype => undef, |
352 |
itemtype => undef, |
352 |
rule_name => 'refund' |
353 |
rule_name => 'lostreturn', |
|
|
354 |
rule_value => 'restore' |
353 |
} |
355 |
} |
354 |
) |
356 |
) |
355 |
->next |
357 |
->next |
Lines 357-392
subtest 'get_lostreturn_policy() tests' => sub {
Link Here
|
357 |
|
359 |
|
358 |
my $item = $builder->build_sample_item( |
360 |
my $item = $builder->build_sample_item( |
359 |
{ |
361 |
{ |
360 |
homebranch => $specific_rule_true->{branchcode}, |
362 |
homebranch => $specific_rule_refund->{branchcode}, |
361 |
holdingbranch => $specific_rule_false->{branchcode} |
363 |
holdingbranch => $specific_rule_false->{branchcode} |
362 |
} |
364 |
} |
363 |
); |
365 |
); |
364 |
my $params = { |
366 |
my $params = { |
365 |
return_branch => $specific_rule_true->{ branchcode }, |
367 |
return_branch => $specific_rule_refund->{ branchcode }, |
366 |
item => $item |
368 |
item => $item |
367 |
}; |
369 |
}; |
368 |
|
370 |
|
369 |
# Specific rules |
371 |
# Specific rules |
370 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' ); |
372 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' ); |
371 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
373 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
372 |
1,'Specific rule for checkin branch is applied (true)'); |
374 |
'refund','Specific rule for checkin branch is applied (refund)'); |
373 |
|
375 |
|
374 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' ); |
376 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' ); |
375 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
377 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
376 |
1,'Specific rule for home branch is applied (true)'); |
378 |
'refund','Specific rule for home branch is applied (refund)'); |
377 |
|
379 |
|
378 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' ); |
380 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' ); |
379 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
381 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
380 |
0,'Specific rule for holoding branch is applied (false)'); |
382 |
0,'Specific rule for holding branch is applied (false)'); |
381 |
|
383 |
|
382 |
# Default rule check |
384 |
# Default rule check |
383 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' ); |
385 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' ); |
384 |
$params->{return_branch} = $branch_without_rule; |
386 |
$params->{return_branch} = $branch_without_rule; |
385 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
387 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
386 |
1,'No rule for branch, global rule applied (true)'); |
388 |
'charge','No rule for branch, global rule applied (charge)'); |
387 |
|
389 |
|
388 |
# Change the default value just to try |
390 |
# Change the default value just to try |
389 |
Koha::CirculationRules->search({ branchcode => undef, rule_name => 'refund' })->next->rule_value(0)->store; |
391 |
Koha::CirculationRules->search({ branchcode => undef, rule_name => 'lostreturn' })->next->rule_value(0)->store; |
390 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
392 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
391 |
0,'No rule for branch, global rule applied (false)'); |
393 |
0,'No rule for branch, global rule applied (false)'); |
392 |
|
394 |
|
Lines 397-409
subtest 'get_lostreturn_policy() tests' => sub {
Link Here
|
397 |
branchcode => undef, |
399 |
branchcode => undef, |
398 |
categorycode => undef, |
400 |
categorycode => undef, |
399 |
itemtype => undef, |
401 |
itemtype => undef, |
400 |
rule_name => 'refund' |
402 |
rule_name => 'lostreturn' |
401 |
} |
403 |
} |
402 |
) |
404 |
) |
403 |
->next |
405 |
->next |
404 |
->delete; |
406 |
->delete; |
405 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
407 |
is( Koha::CirculationRules->get_lostreturn_policy( $params ), |
406 |
1,'No rule for branch, no default rule, fallback default (true)'); |
408 |
'refund','No rule for branch, no default rule, fallback default (refund)'); |
407 |
|
409 |
|
408 |
$schema->storage->txn_rollback; |
410 |
$schema->storage->txn_rollback; |
409 |
}; |
411 |
}; |
410 |
- |
|
|