Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 8; |
20 |
use Test::More tests => 9; |
21 |
use t::lib::Mocks; |
21 |
use t::lib::Mocks; |
22 |
use t::lib::TestBuilder; |
22 |
use t::lib::TestBuilder; |
23 |
|
23 |
|
Lines 47-53
subtest 'Koha::RefundLostItemFeeRule::delete() tests' => sub {
Link Here
|
47 |
{ |
47 |
{ |
48 |
source => 'CirculationRule', |
48 |
source => 'CirculationRule', |
49 |
value => { |
49 |
value => { |
50 |
branchcode => '*', |
50 |
branchcode => undef, |
51 |
categorycode => undef, |
51 |
categorycode => undef, |
52 |
itemtype => undef, |
52 |
itemtype => undef, |
53 |
rule_name => 'refund', |
53 |
rule_name => 'refund', |
Lines 67-73
subtest 'Koha::RefundLostItemFeeRule::delete() tests' => sub {
Link Here
|
67 |
|
67 |
|
68 |
my $default_rule = Koha::CirculationRules->search( |
68 |
my $default_rule = Koha::CirculationRules->search( |
69 |
{ |
69 |
{ |
70 |
branchcode => '*', |
70 |
branchcode => undef, |
71 |
categorycode => undef, |
71 |
categorycode => undef, |
72 |
itemtype => undef, |
72 |
itemtype => undef, |
73 |
rule_name => 'refund', |
73 |
rule_name => 'refund', |
Lines 109-115
subtest 'Koha::RefundLostItemFeeRules::_default_rule() tests' => sub {
Link Here
|
109 |
{ |
109 |
{ |
110 |
source => 'CirculationRule', |
110 |
source => 'CirculationRule', |
111 |
value => { |
111 |
value => { |
112 |
branchcode => '*', |
112 |
branchcode => undef, |
113 |
categorycode => undef, |
113 |
categorycode => undef, |
114 |
itemtype => undef, |
114 |
itemtype => undef, |
115 |
rule_name => 'refund', |
115 |
rule_name => 'refund', |
Lines 130-136
subtest 'Koha::RefundLostItemFeeRules::_default_rule() tests' => sub {
Link Here
|
130 |
|
130 |
|
131 |
my $default_rule = Koha::CirculationRules->search( |
131 |
my $default_rule = Koha::CirculationRules->search( |
132 |
{ |
132 |
{ |
133 |
branchcode => '*', |
133 |
branchcode => undef, |
134 |
categorycode => undef, |
134 |
categorycode => undef, |
135 |
itemtype => undef, |
135 |
itemtype => undef, |
136 |
rule_name => 'refund', |
136 |
rule_name => 'refund', |
Lines 146-157
subtest 'Koha::RefundLostItemFeeRules::_default_rule() tests' => sub {
Link Here
|
146 |
# Re-read from DB, to be sure |
146 |
# Re-read from DB, to be sure |
147 |
$default_rule = Koha::CirculationRules->search( |
147 |
$default_rule = Koha::CirculationRules->search( |
148 |
{ |
148 |
{ |
149 |
branchcode => '*', |
149 |
branchcode => undef, |
150 |
categorycode => undef, |
150 |
categorycode => undef, |
151 |
itemtype => undef, |
151 |
itemtype => undef, |
152 |
rule_name => 'refund', |
152 |
rule_name => 'refund', |
153 |
} |
153 |
} |
154 |
)->next(); |
154 |
)->next(); |
|
|
155 |
use Data::Printer colored => 1; |
155 |
ok( !Koha::RefundLostItemFeeRules->_default_rule, 'Default rule is set to not refund' ); |
156 |
ok( !Koha::RefundLostItemFeeRules->_default_rule, 'Default rule is set to not refund' ); |
156 |
|
157 |
|
157 |
$default_rule->delete; |
158 |
$default_rule->delete; |
Lines 177-183
subtest 'Koha::RefundLostItemFeeRules::_effective_branch_rule() tests' => sub {
Link Here
|
177 |
{ |
178 |
{ |
178 |
source => 'CirculationRule', |
179 |
source => 'CirculationRule', |
179 |
value => { |
180 |
value => { |
180 |
branchcode => '*', |
181 |
branchcode => undef, |
181 |
categorycode => undef, |
182 |
categorycode => undef, |
182 |
itemtype => undef, |
183 |
itemtype => undef, |
183 |
rule_name => 'refund', |
184 |
rule_name => 'refund', |
Lines 293-299
subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub {
Link Here
|
293 |
{ |
294 |
{ |
294 |
source => 'CirculationRule', |
295 |
source => 'CirculationRule', |
295 |
value => { |
296 |
value => { |
296 |
branchcode => '*', |
297 |
branchcode => undef, |
297 |
categorycode => undef, |
298 |
categorycode => undef, |
298 |
itemtype => undef, |
299 |
itemtype => undef, |
299 |
rule_name => 'refund', |
300 |
rule_name => 'refund', |
Lines 363-369
subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub {
Link Here
|
363 |
1,'No rule for branch, global rule applied (true)'); |
364 |
1,'No rule for branch, global rule applied (true)'); |
364 |
|
365 |
|
365 |
# Change the default value just to try |
366 |
# Change the default value just to try |
366 |
Koha::CirculationRules->search({ branchcode => '*', rule_name => 'refund' })->next->rule_value(0)->store; |
367 |
Koha::CirculationRules->search({ branchcode => undef, rule_name => 'refund' })->next->rule_value(0)->store; |
367 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' ); |
368 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' ); |
368 |
is( Koha::RefundLostItemFeeRules->should_refund( $params ), |
369 |
is( Koha::RefundLostItemFeeRules->should_refund( $params ), |
369 |
0,'No rule for branch, global rule applied (false)'); |
370 |
0,'No rule for branch, global rule applied (false)'); |
Lines 372-374
subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub {
Link Here
|
372 |
$schema->storage->txn_rollback; |
373 |
$schema->storage->txn_rollback; |
373 |
}; |
374 |
}; |
374 |
|
375 |
|
375 |
- |
376 |
subtest 'Koha::RefundLostItemFeeRules::find() tests' => sub { |
|
|
377 |
|
378 |
plan tests => 4; |
379 |
|
380 |
# Start transaction |
381 |
$schema->storage->txn_begin; |
382 |
|
383 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' ); |
384 |
|
385 |
$schema->resultset('CirculationRule')->search()->delete; |
386 |
|
387 |
my $default_non_refund = $builder->build( |
388 |
{ |
389 |
source => 'CirculationRule', |
390 |
value => { |
391 |
branchcode => undef, |
392 |
categorycode => undef, |
393 |
itemtype => undef, |
394 |
rule_name => 'non_refund_rule', |
395 |
rule_value => 1 |
396 |
} |
397 |
} |
398 |
); |
399 |
my $specific_non_refund = $builder->build( |
400 |
{ |
401 |
source => 'CirculationRule', |
402 |
value => { |
403 |
categorycode => undef, |
404 |
itemtype => undef, |
405 |
rule_name => 'non_refund_rule', |
406 |
rule_value => 0 |
407 |
} |
408 |
} |
409 |
); |
410 |
|
411 |
ok(!defined Koha::RefundLostItemFeeRules->find({ branchcode => undef }), 'Non refund default rules are not found'); |
412 |
ok(!defined Koha::RefundLostItemFeeRules->find({ branchcode => $specific_non_refund->{branchcode} }), 'Non refund specific rules are not found'); |
413 |
|
414 |
my $default_refund = $builder->build( |
415 |
{ |
416 |
source => 'CirculationRule', |
417 |
value => { |
418 |
branchcode => undef, |
419 |
categorycode => undef, |
420 |
itemtype => undef, |
421 |
rule_name => 'refund', |
422 |
rule_value => 1 |
423 |
} |
424 |
} |
425 |
); |
426 |
my $specific_refund = $builder->build( |
427 |
{ |
428 |
source => 'CirculationRule', |
429 |
value => { |
430 |
categorycode => undef, |
431 |
itemtype => undef, |
432 |
rule_name => 'refund', |
433 |
rule_value => 0 |
434 |
} |
435 |
} |
436 |
); |
437 |
|
438 |
ok(defined Koha::RefundLostItemFeeRules->find({ branchcode => undef }), 'Refund default rules are found'); |
439 |
ok(defined Koha::RefundLostItemFeeRules->find({ branchcode => $specific_refund->{branchcode} }), 'Refund specific rules are found'); |
440 |
|
441 |
# Rollback transaction |
442 |
$schema->storage->txn_rollback; |
443 |
}; |