Lines 26-32
use Koha::Database;
Link Here
|
26 |
|
26 |
|
27 |
BEGIN { |
27 |
BEGIN { |
28 |
use_ok('Koha::Object'); |
28 |
use_ok('Koha::Object'); |
29 |
use_ok('Koha::RefundLostItemFeeRule'); |
29 |
use_ok('Koha::CirculationRule'); |
30 |
use_ok('Koha::RefundLostItemFeeRules'); |
30 |
use_ok('Koha::RefundLostItemFeeRules'); |
31 |
} |
31 |
} |
32 |
|
32 |
|
Lines 41-72
subtest 'Koha::RefundLostItemFeeRule::delete() tests' => sub {
Link Here
|
41 |
$schema->storage->txn_begin; |
41 |
$schema->storage->txn_begin; |
42 |
|
42 |
|
43 |
# Clean the table |
43 |
# Clean the table |
44 |
$schema->resultset('RefundLostItemFeeRule')->search()->delete; |
44 |
$schema->resultset('CirculationRule')->search()->delete; |
45 |
|
45 |
|
46 |
my $generated_default_rule = $builder->build({ |
46 |
my $generated_default_rule = $builder->build( |
47 |
source => 'RefundLostItemFeeRule', |
47 |
{ |
48 |
value => { |
48 |
source => 'CirculationRule', |
49 |
branchcode => '*' |
49 |
value => { |
|
|
50 |
branchcode => '*', |
51 |
categorycode => undef, |
52 |
itemtype => undef, |
53 |
rule_name => 'refund', |
54 |
} |
50 |
} |
55 |
} |
51 |
}); |
56 |
); |
52 |
my $generated_other_rule = $builder->build({ |
57 |
my $generated_other_rule = $builder->build( |
53 |
source => 'RefundLostItemFeeRule' |
58 |
{ |
54 |
}); |
59 |
source => 'CirculationRule', |
55 |
|
60 |
value => { |
56 |
my $default_rule = Koha::RefundLostItemFeeRules->find({ |
61 |
categorycode => undef, |
57 |
branchcode => '*' }); |
62 |
itemtype => undef, |
|
|
63 |
rule_name => 'refund', |
64 |
} |
65 |
} |
66 |
); |
67 |
|
68 |
my $default_rule = Koha::CirculationRules->search( |
69 |
{ |
70 |
branchcode => '*', |
71 |
categorycode => undef, |
72 |
itemtype => undef, |
73 |
rule_name => 'refund', |
74 |
} |
75 |
)->next(); |
58 |
ok( defined $default_rule, 'Default rule created' ); |
76 |
ok( defined $default_rule, 'Default rule created' ); |
59 |
ok( $default_rule->in_storage, 'Default rule actually in storage'); |
77 |
ok( $default_rule->_result->in_storage, 'Default rule actually in storage'); |
60 |
|
78 |
|
61 |
my $other_rule = Koha::RefundLostItemFeeRules->find({ |
79 |
my $other_rule = Koha::CirculationRules->search( |
62 |
branchcode => $generated_other_rule->{ branchcode } |
80 |
{ |
63 |
}); |
81 |
branchcode => $generated_other_rule->{branchcode}, |
|
|
82 |
categorycode => undef, |
83 |
itemtype => undef, |
84 |
rule_name => 'refund', |
85 |
} |
86 |
)->next(); |
64 |
ok( defined $other_rule, 'Other rule created' ); |
87 |
ok( defined $other_rule, 'Other rule created' ); |
65 |
ok( $other_rule->in_storage, 'Other rule actually in storage'); |
88 |
ok( $other_rule->_result->in_storage, 'Other rule actually in storage'); |
66 |
|
89 |
|
67 |
# deleting the regular rule |
90 |
# deleting the regular rule |
68 |
$other_rule->delete; |
91 |
$other_rule->delete; |
69 |
ok( !$other_rule->in_storage, 'Other rule deleted from storage' ); |
92 |
ok( !$other_rule->_result->in_storage, 'Other rule deleted from storage' ); |
70 |
|
93 |
|
71 |
# Rollback transaction |
94 |
# Rollback transaction |
72 |
$schema->storage->txn_rollback; |
95 |
$schema->storage->txn_rollback; |
Lines 80-114
subtest 'Koha::RefundLostItemFeeRules::_default_rule() tests' => sub {
Link Here
|
80 |
$schema->storage->txn_begin; |
103 |
$schema->storage->txn_begin; |
81 |
|
104 |
|
82 |
# Clean the table |
105 |
# Clean the table |
83 |
$schema->resultset('RefundLostItemFeeRule')->search()->delete; |
106 |
$schema->resultset('CirculationRule')->search()->delete; |
84 |
|
107 |
|
85 |
my $generated_default_rule = $builder->build({ |
108 |
my $generated_default_rule = $builder->build( |
86 |
source => 'RefundLostItemFeeRule', |
109 |
{ |
87 |
value => { |
110 |
source => 'CirculationRule', |
88 |
branchcode => '*', |
111 |
value => { |
89 |
refund => 1 |
112 |
branchcode => '*', |
|
|
113 |
categorycode => undef, |
114 |
itemtype => undef, |
115 |
rule_name => 'refund', |
116 |
rule_value => 1, |
117 |
} |
90 |
} |
118 |
} |
91 |
}); |
119 |
); |
92 |
my $generated_other_rule = $builder->build({ |
120 |
my $generated_other_rule = $builder->build( |
93 |
source => 'RefundLostItemFeeRule' |
121 |
{ |
94 |
}); |
122 |
source => 'CirculationRule', |
95 |
|
123 |
value => { |
96 |
my $default_rule = Koha::RefundLostItemFeeRules->find({ |
124 |
categorycode => undef, |
97 |
branchcode => '*' }); |
125 |
itemtype => undef, |
|
|
126 |
rule_name => 'refund', |
127 |
} |
128 |
} |
129 |
); |
130 |
|
131 |
my $default_rule = Koha::CirculationRules->search( |
132 |
{ |
133 |
branchcode => '*', |
134 |
categorycode => undef, |
135 |
itemtype => undef, |
136 |
rule_name => 'refund', |
137 |
} |
138 |
)->next(); |
98 |
ok( defined $default_rule, 'Default rule created' ); |
139 |
ok( defined $default_rule, 'Default rule created' ); |
99 |
ok( $default_rule->in_storage, 'Default rule actually in storage'); |
140 |
ok( $default_rule->_result->in_storage, 'Default rule actually in storage'); |
100 |
ok( Koha::RefundLostItemFeeRules->_default_rule, 'Default rule is set to refund' ); |
141 |
is( Koha::RefundLostItemFeeRules->_default_rule, 1, 'Default rule is set to refund' ); |
101 |
|
142 |
|
102 |
# Change default rule to "Don't refund" |
143 |
# Change default rule to "Don't refund" |
103 |
$default_rule->refund(0); |
144 |
$default_rule->rule_value(0); |
104 |
$default_rule->store; |
145 |
$default_rule->store; |
105 |
# Re-read from DB, to be sure |
146 |
# Re-read from DB, to be sure |
106 |
$default_rule = Koha::RefundLostItemFeeRules->find({ |
147 |
$default_rule = Koha::CirculationRules->search( |
107 |
branchcode => '*' }); |
148 |
{ |
|
|
149 |
branchcode => '*', |
150 |
categorycode => undef, |
151 |
itemtype => undef, |
152 |
rule_name => 'refund', |
153 |
} |
154 |
)->next(); |
108 |
ok( !Koha::RefundLostItemFeeRules->_default_rule, 'Default rule is set to not refund' ); |
155 |
ok( !Koha::RefundLostItemFeeRules->_default_rule, 'Default rule is set to not refund' ); |
109 |
|
156 |
|
110 |
$default_rule->delete; |
157 |
$default_rule->delete; |
111 |
ok( !$default_rule->in_storage, 'Default rule effectively deleted from storage' ); |
158 |
ok( !$default_rule->_result->in_storage, 'Default rule effectively deleted from storage' ); |
112 |
|
159 |
|
113 |
ok( Koha::RefundLostItemFeeRules->_default_rule, 'Default rule is set to refund if no default rule is present' ); |
160 |
ok( Koha::RefundLostItemFeeRules->_default_rule, 'Default rule is set to refund if no default rule is present' ); |
114 |
|
161 |
|
Lines 124-150
subtest 'Koha::RefundLostItemFeeRules::_effective_branch_rule() tests' => sub {
Link Here
|
124 |
$schema->storage->txn_begin; |
171 |
$schema->storage->txn_begin; |
125 |
|
172 |
|
126 |
# Clean the table |
173 |
# Clean the table |
127 |
$schema->resultset('RefundLostItemFeeRule')->search()->delete; |
174 |
$schema->resultset('CirculationRule')->search()->delete; |
128 |
|
175 |
|
129 |
my $default_rule = $builder->build({ |
176 |
my $default_rule = $builder->build( |
130 |
source => 'RefundLostItemFeeRule', |
177 |
{ |
131 |
value => { |
178 |
source => 'CirculationRule', |
132 |
branchcode => '*', |
179 |
value => { |
133 |
refund => 1 |
180 |
branchcode => '*', |
|
|
181 |
categorycode => undef, |
182 |
itemtype => undef, |
183 |
rule_name => 'refund', |
184 |
rule_value => 1, |
185 |
} |
134 |
} |
186 |
} |
135 |
}); |
187 |
); |
136 |
my $specific_rule_false = $builder->build({ |
188 |
my $specific_rule_false = $builder->build( |
137 |
source => 'RefundLostItemFeeRule', |
189 |
{ |
138 |
value => { |
190 |
source => 'CirculationRule', |
139 |
refund => 0 |
191 |
value => { |
|
|
192 |
categorycode => undef, |
193 |
itemtype => undef, |
194 |
rule_name => 'refund', |
195 |
rule_value => 0, |
196 |
} |
140 |
} |
197 |
} |
141 |
}); |
198 |
); |
142 |
my $specific_rule_true = $builder->build({ |
199 |
my $specific_rule_true = $builder->build( |
143 |
source => 'RefundLostItemFeeRule', |
200 |
{ |
144 |
value => { |
201 |
source => 'CirculationRule', |
145 |
refund => 1 |
202 |
value => { |
|
|
203 |
categorycode => undef, |
204 |
itemtype => undef, |
205 |
rule_name => 'refund', |
206 |
rule_value => 1, |
207 |
} |
146 |
} |
208 |
} |
147 |
}); |
209 |
); |
148 |
|
210 |
|
149 |
is( Koha::RefundLostItemFeeRules->_effective_branch_rule( $specific_rule_true->{ branchcode } ), |
211 |
is( Koha::RefundLostItemFeeRules->_effective_branch_rule( $specific_rule_true->{ branchcode } ), |
150 |
1,'Specific rule is applied (true)'); |
212 |
1,'Specific rule is applied (true)'); |
Lines 225-258
subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub {
Link Here
|
225 |
|
287 |
|
226 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' ); |
288 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' ); |
227 |
|
289 |
|
228 |
$schema->resultset('RefundLostItemFeeRule')->search()->delete; |
290 |
$schema->resultset('CirculationRule')->search()->delete; |
229 |
|
291 |
|
230 |
my $default_rule = $builder->build({ |
292 |
my $default_rule = $builder->build( |
231 |
source => 'RefundLostItemFeeRule', |
293 |
{ |
232 |
value => { |
294 |
source => 'CirculationRule', |
233 |
branchcode => '*', |
295 |
value => { |
234 |
refund => 1 |
296 |
branchcode => '*', |
|
|
297 |
categorycode => undef, |
298 |
itemtype => undef, |
299 |
rule_name => 'refund', |
300 |
rule_value => 1 |
301 |
} |
235 |
} |
302 |
} |
236 |
}); |
303 |
); |
237 |
my $specific_rule_false = $builder->build({ |
304 |
my $specific_rule_false = $builder->build( |
238 |
source => 'RefundLostItemFeeRule', |
305 |
{ |
239 |
value => { |
306 |
source => 'CirculationRule', |
240 |
refund => 0 |
307 |
value => { |
|
|
308 |
categorycode => undef, |
309 |
itemtype => undef, |
310 |
rule_name => 'refund', |
311 |
rule_value => 0 |
312 |
} |
241 |
} |
313 |
} |
242 |
}); |
314 |
); |
243 |
my $specific_rule_true = $builder->build({ |
315 |
my $specific_rule_true = $builder->build( |
244 |
source => 'RefundLostItemFeeRule', |
316 |
{ |
245 |
value => { |
317 |
source => 'CirculationRule', |
246 |
refund => 1 |
318 |
value => { |
|
|
319 |
categorycode => undef, |
320 |
itemtype => undef, |
321 |
rule_name => 'refund', |
322 |
rule_value => 1 |
323 |
} |
247 |
} |
324 |
} |
248 |
}); |
325 |
); |
249 |
# Make sure we have an unused branchcode |
326 |
# Make sure we have an unused branchcode |
250 |
my $specific_rule_dummy = $builder->build({ |
327 |
my $specific_rule_dummy = $builder->build( |
251 |
source => 'RefundLostItemFeeRule' |
328 |
{ |
252 |
}); |
329 |
source => 'CirculationRule', |
|
|
330 |
value => { |
331 |
categorycode => undef, |
332 |
itemtype => undef, |
333 |
rule_name => 'refund', |
334 |
} |
335 |
} |
336 |
); |
253 |
my $branch_without_rule = $specific_rule_dummy->{ branchcode }; |
337 |
my $branch_without_rule = $specific_rule_dummy->{ branchcode }; |
254 |
Koha::RefundLostItemFeeRules |
338 |
Koha::CirculationRules |
255 |
->find({ branchcode => $branch_without_rule }) |
339 |
->search( |
|
|
340 |
{ |
341 |
branchcode => $branch_without_rule, |
342 |
categorycode => undef, |
343 |
itemtype => undef, |
344 |
rule_name => 'refund' |
345 |
} |
346 |
) |
347 |
->next |
256 |
->delete; |
348 |
->delete; |
257 |
|
349 |
|
258 |
my $params = { |
350 |
my $params = { |
Lines 271-277
subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub {
Link Here
|
271 |
1,'No rule for branch, global rule applied (true)'); |
363 |
1,'No rule for branch, global rule applied (true)'); |
272 |
|
364 |
|
273 |
# Change the default value just to try |
365 |
# Change the default value just to try |
274 |
Koha::RefundLostItemFeeRules->find({ branchcode => '*' })->refund(0)->store; |
366 |
Koha::CirculationRules->search({ branchcode => '*', rule_name => 'refund' })->next->rule_value(0)->store; |
275 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' ); |
367 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' ); |
276 |
is( Koha::RefundLostItemFeeRules->should_refund( $params ), |
368 |
is( Koha::RefundLostItemFeeRules->should_refund( $params ), |
277 |
0,'No rule for branch, global rule applied (false)'); |
369 |
0,'No rule for branch, global rule applied (false)'); |
278 |
- |
|
|