Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 1; |
22 |
use Test::More tests => 2; |
|
|
23 |
use Test::Deep qw( cmp_methods ); |
24 |
use Test::Exception; |
23 |
|
25 |
|
24 |
use Benchmark; |
26 |
use Benchmark; |
25 |
|
27 |
|
Lines 35-49
my $builder = t::lib::TestBuilder->new;
Link Here
|
35 |
subtest 'get_effective_issuing_rule' => sub { |
37 |
subtest 'get_effective_issuing_rule' => sub { |
36 |
plan tests => 3; |
38 |
plan tests => 3; |
37 |
|
39 |
|
38 |
my $patron = $builder->build({ source => 'Borrower' }); |
40 |
my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'}; |
39 |
my $item = $builder->build({ source => 'Item' }); |
41 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{'itemtype'}; |
40 |
|
42 |
my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'}; |
41 |
my $categorycode = $patron->{'categorycode'}; |
|
|
42 |
my $itemtype = $item->{'itype'}; |
43 |
my $branchcode = $item->{'homebranch'}; |
44 |
|
43 |
|
45 |
subtest 'Call with undefined values' => sub { |
44 |
subtest 'Call with undefined values' => sub { |
46 |
plan tests => 4; |
45 |
plan tests => 5; |
47 |
|
46 |
|
48 |
my $rule; |
47 |
my $rule; |
49 |
Koha::CirculationRules->delete; |
48 |
Koha::CirculationRules->delete; |
Lines 58-82
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
58 |
is($rule, undef, 'When I attempt to get effective issuing rule by' |
57 |
is($rule, undef, 'When I attempt to get effective issuing rule by' |
59 |
.' providing undefined values, then undef is returned.'); |
58 |
.' providing undefined values, then undef is returned.'); |
60 |
ok(Koha::CirculationRule->new({ |
59 |
ok(Koha::CirculationRule->new({ |
61 |
branchcode => '*', |
60 |
branchcode => undef, |
62 |
categorycode => '*', |
61 |
categorycode => undef, |
63 |
itemtype => '*', |
62 |
itemtype => undef, |
64 |
rule_name => 'fine', |
63 |
rule_name => 'fine', |
65 |
})->store, 'Given I added an issuing rule branchcode => *,' |
64 |
})->store, 'Given I added an issuing rule branchcode => undef,' |
66 |
.' categorycode => *, itemtype => *,'); |
65 |
.' categorycode => undef, itemtype => undef,'); |
67 |
$rule = Koha::CirculationRules->get_effective_rule({ |
66 |
$rule = Koha::CirculationRules->get_effective_rule({ |
68 |
branchcode => '*', |
67 |
branchcode => undef, |
69 |
categorycode => '*', |
68 |
categorycode => undef, |
70 |
itemtype => '*', |
69 |
itemtype => undef, |
71 |
rule_name => 'fine', |
70 |
rule_name => 'fine', |
72 |
}); |
71 |
}); |
73 |
ok(_row_match($rule, '*', '*', '*'), 'When I attempt to get effective' |
72 |
_is_row_match( |
|
|
73 |
$rule, |
74 |
{ |
75 |
branchcode => undef, |
76 |
categorycode => undef, |
77 |
itemtype => undef |
78 |
}, |
79 |
'When I attempt to get effective' |
74 |
.' issuing rule by providing undefined values, then the above one is' |
80 |
.' issuing rule by providing undefined values, then the above one is' |
75 |
.' returned.'); |
81 |
.' returned.' |
|
|
82 |
); |
76 |
}; |
83 |
}; |
77 |
|
84 |
|
78 |
subtest 'Get effective issuing rule in correct order' => sub { |
85 |
subtest 'Get effective issuing rule in correct order' => sub { |
79 |
plan tests => 18; |
86 |
plan tests => 26; |
80 |
|
87 |
|
81 |
my $rule; |
88 |
my $rule; |
82 |
Koha::CirculationRules->delete; |
89 |
Koha::CirculationRules->delete; |
Lines 91-199
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
91 |
.' is returned.'); |
98 |
.' is returned.'); |
92 |
|
99 |
|
93 |
ok(Koha::CirculationRule->new({ |
100 |
ok(Koha::CirculationRule->new({ |
94 |
branchcode => '*', |
101 |
branchcode => undef, |
95 |
categorycode => '*', |
102 |
categorycode => undef, |
96 |
itemtype => '*', |
103 |
itemtype => undef, |
97 |
rule_name => 'fine', |
104 |
rule_name => 'fine', |
98 |
})->store, 'Given I added an issuing rule branchcode => *, categorycode => *, itemtype => *,'); |
105 |
})->store, 'Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => undef,'); |
99 |
$rule = Koha::CirculationRules->get_effective_rule({ |
106 |
$rule = Koha::CirculationRules->get_effective_rule({ |
100 |
branchcode => $branchcode, |
107 |
branchcode => $branchcode, |
101 |
categorycode => $categorycode, |
108 |
categorycode => $categorycode, |
102 |
itemtype => $itemtype, |
109 |
itemtype => $itemtype, |
103 |
rule_name => 'fine', |
110 |
rule_name => 'fine', |
104 |
}); |
111 |
}); |
105 |
ok(_row_match($rule, '*', '*', '*'), 'When I attempt to get effective issuing rule,' |
112 |
_is_row_match( |
106 |
.' then the above one is returned.'); |
113 |
$rule, |
|
|
114 |
{ |
115 |
branchcode => undef, |
116 |
categorycode => undef, |
117 |
itemtype => undef |
118 |
}, |
119 |
'When I attempt to get effective issuing rule,' |
120 |
.' then the above one is returned.' |
121 |
); |
107 |
|
122 |
|
108 |
ok(Koha::CirculationRule->new({ |
123 |
ok(Koha::CirculationRule->new({ |
109 |
branchcode => '*', |
124 |
branchcode => undef, |
110 |
categorycode => '*', |
125 |
categorycode => undef, |
111 |
itemtype => $itemtype, |
126 |
itemtype => $itemtype, |
112 |
rule_name => 'fine', |
127 |
rule_name => 'fine', |
113 |
})->store, "Given I added an issuing rule branchcode => *, categorycode => *, itemtype => $itemtype,"); |
128 |
})->store, "Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => $itemtype,"); |
114 |
$rule = Koha::CirculationRules->get_effective_rule({ |
129 |
$rule = Koha::CirculationRules->get_effective_rule({ |
115 |
branchcode => $branchcode, |
130 |
branchcode => $branchcode, |
116 |
categorycode => $categorycode, |
131 |
categorycode => $categorycode, |
117 |
itemtype => $itemtype, |
132 |
itemtype => $itemtype, |
118 |
rule_name => 'fine', |
133 |
rule_name => 'fine', |
119 |
}); |
134 |
}); |
120 |
ok(_row_match($rule, '*', '*', $itemtype), 'When I attempt to get effective issuing rule,' |
135 |
_is_row_match( |
121 |
.' then the above one is returned.'); |
136 |
$rule, |
|
|
137 |
{ |
138 |
branchcode => undef, |
139 |
categorycode => undef, |
140 |
itemtype => $itemtype |
141 |
}, |
142 |
'When I attempt to get effective issuing rule,' |
143 |
.' then the above one is returned.' |
144 |
); |
122 |
|
145 |
|
123 |
ok(Koha::CirculationRule->new({ |
146 |
ok(Koha::CirculationRule->new({ |
124 |
branchcode => '*', |
147 |
branchcode => undef, |
125 |
categorycode => $categorycode, |
148 |
categorycode => $categorycode, |
126 |
itemtype => '*', |
149 |
itemtype => undef, |
127 |
rule_name => 'fine', |
150 |
rule_name => 'fine', |
128 |
})->store, "Given I added an issuing rule branchcode => *, categorycode => $categorycode, itemtype => *,"); |
151 |
})->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => undef,"); |
129 |
$rule = Koha::CirculationRules->get_effective_rule({ |
152 |
$rule = Koha::CirculationRules->get_effective_rule({ |
130 |
branchcode => $branchcode, |
153 |
branchcode => $branchcode, |
131 |
categorycode => $categorycode, |
154 |
categorycode => $categorycode, |
132 |
itemtype => $itemtype, |
155 |
itemtype => $itemtype, |
133 |
rule_name => 'fine', |
156 |
rule_name => 'fine', |
134 |
}); |
157 |
}); |
135 |
ok(_row_match($rule, '*', $categorycode, '*'), 'When I attempt to get effective issuing rule,' |
158 |
_is_row_match( |
136 |
.' then the above one is returned.'); |
159 |
$rule, |
|
|
160 |
{ |
161 |
branchcode => undef, |
162 |
categorycode => $categorycode, |
163 |
itemtype => undef |
164 |
}, |
165 |
'When I attempt to get effective issuing rule,' |
166 |
.' then the above one is returned.' |
167 |
); |
137 |
|
168 |
|
138 |
ok(Koha::CirculationRule->new({ |
169 |
ok(Koha::CirculationRule->new({ |
139 |
branchcode => '*', |
170 |
branchcode => undef, |
140 |
categorycode => $categorycode, |
171 |
categorycode => $categorycode, |
141 |
itemtype => $itemtype, |
172 |
itemtype => $itemtype, |
142 |
rule_name => 'fine', |
173 |
rule_name => 'fine', |
143 |
})->store, "Given I added an issuing rule branchcode => *, categorycode => $categorycode, itemtype => $itemtype,"); |
174 |
})->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => $itemtype,"); |
144 |
$rule = Koha::CirculationRules->get_effective_rule({ |
175 |
$rule = Koha::CirculationRules->get_effective_rule({ |
145 |
branchcode => $branchcode, |
176 |
branchcode => $branchcode, |
146 |
categorycode => $categorycode, |
177 |
categorycode => $categorycode, |
147 |
itemtype => $itemtype, |
178 |
itemtype => $itemtype, |
148 |
rule_name => 'fine', |
179 |
rule_name => 'fine', |
149 |
}); |
180 |
}); |
150 |
ok(_row_match($rule, '*', $categorycode, $itemtype), 'When I attempt to get effective issuing rule,' |
181 |
_is_row_match( |
151 |
.' then the above one is returned.'); |
182 |
$rule, |
|
|
183 |
{ |
184 |
branchcode => undef, |
185 |
categorycode => $categorycode, |
186 |
itemtype => $itemtype |
187 |
}, |
188 |
'When I attempt to get effective issuing rule,' |
189 |
.' then the above one is returned.' |
190 |
); |
152 |
|
191 |
|
153 |
ok(Koha::CirculationRule->new({ |
192 |
ok(Koha::CirculationRule->new({ |
154 |
branchcode => $branchcode, |
193 |
branchcode => $branchcode, |
155 |
categorycode => '*', |
194 |
categorycode => undef, |
156 |
itemtype => '*', |
195 |
itemtype => undef, |
157 |
rule_name => 'fine', |
196 |
rule_name => 'fine', |
158 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => '*', itemtype => '*',"); |
197 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => undef,"); |
159 |
$rule = Koha::CirculationRules->get_effective_rule({ |
198 |
$rule = Koha::CirculationRules->get_effective_rule({ |
160 |
branchcode => $branchcode, |
199 |
branchcode => $branchcode, |
161 |
categorycode => $categorycode, |
200 |
categorycode => $categorycode, |
162 |
itemtype => $itemtype, |
201 |
itemtype => $itemtype, |
163 |
rule_name => 'fine', |
202 |
rule_name => 'fine', |
164 |
}); |
203 |
}); |
165 |
ok(_row_match($rule, $branchcode, '*', '*'), 'When I attempt to get effective issuing rule,' |
204 |
_is_row_match( |
166 |
.' then the above one is returned.'); |
205 |
$rule, |
|
|
206 |
{ |
207 |
branchcode => $branchcode, |
208 |
categorycode => undef, |
209 |
itemtype => undef |
210 |
}, |
211 |
'When I attempt to get effective issuing rule,' |
212 |
.' then the above one is returned.' |
213 |
); |
167 |
|
214 |
|
168 |
ok(Koha::CirculationRule->new({ |
215 |
ok(Koha::CirculationRule->new({ |
169 |
branchcode => $branchcode, |
216 |
branchcode => $branchcode, |
170 |
categorycode => '*', |
217 |
categorycode => undef, |
171 |
itemtype => $itemtype, |
218 |
itemtype => $itemtype, |
172 |
rule_name => 'fine', |
219 |
rule_name => 'fine', |
173 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => '*', itemtype => $itemtype,"); |
220 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => $itemtype,"); |
174 |
$rule = Koha::CirculationRules->get_effective_rule({ |
221 |
$rule = Koha::CirculationRules->get_effective_rule({ |
175 |
branchcode => $branchcode, |
222 |
branchcode => $branchcode, |
176 |
categorycode => $categorycode, |
223 |
categorycode => $categorycode, |
177 |
itemtype => $itemtype, |
224 |
itemtype => $itemtype, |
178 |
rule_name => 'fine', |
225 |
rule_name => 'fine', |
179 |
}); |
226 |
}); |
180 |
ok(_row_match($rule, $branchcode, '*', $itemtype), 'When I attempt to get effective issuing rule,' |
227 |
_is_row_match( |
181 |
.' then the above one is returned.'); |
228 |
$rule, |
|
|
229 |
{ |
230 |
branchcode => $branchcode, |
231 |
categorycode => undef, |
232 |
itemtype => $itemtype |
233 |
}, |
234 |
'When I attempt to get effective issuing rule,' |
235 |
.' then the above one is returned.' |
236 |
); |
182 |
|
237 |
|
183 |
ok(Koha::CirculationRule->new({ |
238 |
ok(Koha::CirculationRule->new({ |
184 |
branchcode => $branchcode, |
239 |
branchcode => $branchcode, |
185 |
categorycode => $categorycode, |
240 |
categorycode => $categorycode, |
186 |
itemtype => '*', |
241 |
itemtype => undef, |
187 |
rule_name => 'fine', |
242 |
rule_name => 'fine', |
188 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => '*',"); |
243 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => undef,"); |
189 |
$rule = Koha::CirculationRules->get_effective_rule({ |
244 |
$rule = Koha::CirculationRules->get_effective_rule({ |
190 |
branchcode => $branchcode, |
245 |
branchcode => $branchcode, |
191 |
categorycode => $categorycode, |
246 |
categorycode => $categorycode, |
192 |
itemtype => $itemtype, |
247 |
itemtype => $itemtype, |
193 |
rule_name => 'fine', |
248 |
rule_name => 'fine', |
194 |
}); |
249 |
}); |
195 |
ok(_row_match($rule, $branchcode, $categorycode, '*'), 'When I attempt to get effective issuing rule,' |
250 |
_is_row_match( |
196 |
.' then the above one is returned.'); |
251 |
$rule, |
|
|
252 |
{ |
253 |
branchcode => $branchcode, |
254 |
categorycode => $categorycode, |
255 |
itemtype => undef |
256 |
}, |
257 |
'When I attempt to get effective issuing rule,' |
258 |
.' then the above one is returned.' |
259 |
); |
197 |
|
260 |
|
198 |
ok(Koha::CirculationRule->new({ |
261 |
ok(Koha::CirculationRule->new({ |
199 |
branchcode => $branchcode, |
262 |
branchcode => $branchcode, |
Lines 207-214
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
207 |
itemtype => $itemtype, |
270 |
itemtype => $itemtype, |
208 |
rule_name => 'fine', |
271 |
rule_name => 'fine', |
209 |
}); |
272 |
}); |
210 |
ok(_row_match($rule, $branchcode, $categorycode, $itemtype), 'When I attempt to get effective issuing rule,' |
273 |
_is_row_match( |
211 |
.' then the above one is returned.'); |
274 |
$rule, |
|
|
275 |
{ |
276 |
branchcode => $branchcode, |
277 |
categorycode => $categorycode, |
278 |
itemtype => $itemtype |
279 |
}, |
280 |
'When I attempt to get effective issuing rule,' |
281 |
.' then the above one is returned.' |
282 |
); |
212 |
}; |
283 |
}; |
213 |
|
284 |
|
214 |
subtest 'Performance' => sub { |
285 |
subtest 'Performance' => sub { |
Lines 265-275
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
265 |
}; |
336 |
}; |
266 |
}; |
337 |
}; |
267 |
|
338 |
|
268 |
sub _row_match { |
339 |
subtest 'set_rule' => sub { |
269 |
my ($rule, $branchcode, $categorycode, $itemtype) = @_; |
340 |
plan tests => 3; |
|
|
341 |
|
342 |
my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'}; |
343 |
my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'}; |
344 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{'itemtype'}; |
345 |
|
346 |
subtest 'Correct call' => sub { |
347 |
plan tests => 4; |
348 |
|
349 |
Koha::CirculationRules->delete; |
350 |
|
351 |
lives_ok( sub { |
352 |
Koha::CirculationRules->set_rule( { |
353 |
branchcode => $branchcode, |
354 |
rule_name => 'refund', |
355 |
rule_value => '', |
356 |
} ); |
357 |
}, 'setting refund with branch' ); |
358 |
|
359 |
lives_ok( sub { |
360 |
Koha::CirculationRules->set_rule( { |
361 |
branchcode => $branchcode, |
362 |
categorycode => $categorycode, |
363 |
rule_name => 'patron_maxissueqty', |
364 |
rule_value => '', |
365 |
} ); |
366 |
}, 'setting patron_maxissueqty with branch/category succeeds' ); |
367 |
|
368 |
lives_ok( sub { |
369 |
Koha::CirculationRules->set_rule( { |
370 |
branchcode => $branchcode, |
371 |
itemtype => $itemtype, |
372 |
rule_name => 'holdallowed', |
373 |
rule_value => '', |
374 |
} ); |
375 |
}, 'setting holdallowed with branch/itemtype succeeds' ); |
376 |
|
377 |
lives_ok( sub { |
378 |
Koha::CirculationRules->set_rule( { |
379 |
branchcode => $branchcode, |
380 |
categorycode => $categorycode, |
381 |
itemtype => $itemtype, |
382 |
rule_name => 'fine', |
383 |
rule_value => '', |
384 |
} ); |
385 |
}, 'setting fine with branch/category/itemtype succeeds' ); |
386 |
}; |
387 |
|
388 |
subtest 'Call with missing params' => sub { |
389 |
plan tests => 4; |
390 |
|
391 |
Koha::CirculationRules->delete; |
392 |
|
393 |
throws_ok( sub { |
394 |
Koha::CirculationRules->set_rule( { |
395 |
rule_name => 'refund', |
396 |
rule_value => '', |
397 |
} ); |
398 |
}, qr/branchcode/, 'setting refund without branch fails' ); |
399 |
|
400 |
throws_ok( sub { |
401 |
Koha::CirculationRules->set_rule( { |
402 |
branchcode => $branchcode, |
403 |
rule_name => 'patron_maxissueqty', |
404 |
rule_value => '', |
405 |
} ); |
406 |
}, qr/categorycode/, 'setting patron_maxissueqty without categorycode fails' ); |
407 |
|
408 |
throws_ok( sub { |
409 |
Koha::CirculationRules->set_rule( { |
410 |
branchcode => $branchcode, |
411 |
rule_name => 'holdallowed', |
412 |
rule_value => '', |
413 |
} ); |
414 |
}, qr/itemtype/, 'setting holdallowed without itemtype fails' ); |
415 |
|
416 |
throws_ok( sub { |
417 |
Koha::CirculationRules->set_rule( { |
418 |
branchcode => $branchcode, |
419 |
categorycode => $categorycode, |
420 |
rule_name => 'fine', |
421 |
rule_value => '', |
422 |
} ); |
423 |
}, qr/itemtype/, 'setting fine without itemtype fails' ); |
424 |
}; |
425 |
|
426 |
subtest 'Call with extra params' => sub { |
427 |
plan tests => 3; |
428 |
|
429 |
Koha::CirculationRules->delete; |
430 |
|
431 |
throws_ok( sub { |
432 |
Koha::CirculationRules->set_rule( { |
433 |
branchcode => $branchcode, |
434 |
categorycode => $categorycode, |
435 |
rule_name => 'refund', |
436 |
rule_value => '', |
437 |
} ); |
438 |
}, qr/categorycode/, 'setting refund with categorycode fails' ); |
439 |
|
440 |
throws_ok( sub { |
441 |
Koha::CirculationRules->set_rule( { |
442 |
branchcode => $branchcode, |
443 |
categorycode => $categorycode, |
444 |
itemtype => $itemtype, |
445 |
rule_name => 'patron_maxissueqty', |
446 |
rule_value => '', |
447 |
} ); |
448 |
}, qr/itemtype/, 'setting patron_maxissueqty with itemtype fails' ); |
449 |
|
450 |
throws_ok( sub { |
451 |
Koha::CirculationRules->set_rule( { |
452 |
branchcode => $branchcode, |
453 |
rule_name => 'holdallowed', |
454 |
categorycode => $categorycode, |
455 |
itemtype => $itemtype, |
456 |
rule_value => '', |
457 |
} ); |
458 |
}, qr/categorycode/, 'setting holdallowed with categorycode fails' ); |
459 |
}; |
460 |
}; |
461 |
|
462 |
sub _is_row_match { |
463 |
my ( $rule, $expected, $message ) = @_; |
270 |
|
464 |
|
271 |
return $rule->branchcode eq $branchcode && $rule->categorycode eq $categorycode |
465 |
ok( $rule, $message ) ? |
272 |
&& $rule->itemtype eq $itemtype; |
466 |
cmp_methods( $rule, [ %$expected ], $message ) : |
|
|
467 |
fail( $message ); |
273 |
} |
468 |
} |
274 |
|
469 |
|
275 |
$schema->storage->txn_rollback; |
470 |
$schema->storage->txn_rollback; |