Lines 25-30
use Test::Exception;
Link Here
|
25 |
|
25 |
|
26 |
use Benchmark; |
26 |
use Benchmark; |
27 |
|
27 |
|
|
|
28 |
use Koha::Checkouts; |
28 |
use Koha::CirculationRules; |
29 |
use Koha::CirculationRules; |
29 |
|
30 |
|
30 |
use t::lib::TestBuilder; |
31 |
use t::lib::TestBuilder; |
Lines 41-46
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
41 |
my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'}; |
42 |
my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'}; |
42 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{'itemtype'}; |
43 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{'itemtype'}; |
43 |
my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'}; |
44 |
my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'}; |
|
|
45 |
my $onsite_checkout = 0; |
44 |
|
46 |
|
45 |
subtest 'Call with undefined values' => sub { |
47 |
subtest 'Call with undefined values' => sub { |
46 |
plan tests => 5; |
48 |
plan tests => 5; |
Lines 54-59
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
54 |
branchcode => undef, |
56 |
branchcode => undef, |
55 |
categorycode => undef, |
57 |
categorycode => undef, |
56 |
itemtype => undef, |
58 |
itemtype => undef, |
|
|
59 |
onsite_checkout => undef, |
57 |
rule_name => 'fine', |
60 |
rule_name => 'fine', |
58 |
rule_value => 1, |
61 |
rule_value => 1, |
59 |
}); |
62 |
}); |
Lines 67-72
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
67 |
branchcode => undef, |
70 |
branchcode => undef, |
68 |
categorycode => undef, |
71 |
categorycode => undef, |
69 |
itemtype => undef, |
72 |
itemtype => undef, |
|
|
73 |
onsite_checkout => undef, |
70 |
rule_name => 'fine', |
74 |
rule_name => 'fine', |
71 |
rule_value => 2, |
75 |
rule_value => 2, |
72 |
} |
76 |
} |
Lines 77-82
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
77 |
branchcode => undef, |
81 |
branchcode => undef, |
78 |
categorycode => undef, |
82 |
categorycode => undef, |
79 |
itemtype => undef, |
83 |
itemtype => undef, |
|
|
84 |
onsite_checkout => undef, |
80 |
rule_name => 'fine', |
85 |
rule_name => 'fine', |
81 |
}); |
86 |
}); |
82 |
_is_row_match( |
87 |
_is_row_match( |
Lines 85-90
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
85 |
branchcode => undef, |
90 |
branchcode => undef, |
86 |
categorycode => undef, |
91 |
categorycode => undef, |
87 |
itemtype => undef, |
92 |
itemtype => undef, |
|
|
93 |
onsite_checkout => undef, |
88 |
rule_name => 'fine', |
94 |
rule_name => 'fine', |
89 |
rule_value => 2, |
95 |
rule_value => 2, |
90 |
}, |
96 |
}, |
Lines 95-125
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
95 |
}; |
101 |
}; |
96 |
|
102 |
|
97 |
subtest 'Performance' => sub { |
103 |
subtest 'Performance' => sub { |
98 |
plan tests => 4; |
104 |
plan tests => 5; |
99 |
|
105 |
|
100 |
my $worst_case = timethis(500, |
106 |
my $worst_case = timethis(500, |
101 |
sub { Koha::CirculationRules->get_effective_rule({ |
107 |
sub { Koha::CirculationRules->get_effective_rule({ |
102 |
branchcode => 'nonexistent', |
108 |
branchcode => 'nonexistent', |
103 |
categorycode => 'nonexistent', |
109 |
categorycode => 'nonexistent', |
104 |
itemtype => 'nonexistent', |
110 |
itemtype => 'nonexistent', |
|
|
111 |
onsite_checkout => 'nonexistent', |
105 |
rule_name => 'nonexistent', |
112 |
rule_name => 'nonexistent', |
106 |
}); |
113 |
}); |
107 |
} |
114 |
} |
108 |
); |
115 |
); |
109 |
my $mid_case = timethis(500, |
116 |
my $mid_case1 = timethis(500, |
110 |
sub { Koha::CirculationRules->get_effective_rule({ |
117 |
sub { Koha::CirculationRules->get_effective_rule({ |
111 |
branchcode => $branchcode, |
118 |
branchcode => $branchcode, |
112 |
categorycode => 'nonexistent', |
119 |
categorycode => 'nonexistent', |
113 |
itemtype => 'nonexistent', |
120 |
itemtype => 'nonexistent', |
|
|
121 |
onsite_checkout => 'nonexistent', |
114 |
rule_name => 'nonexistent', |
122 |
rule_name => 'nonexistent', |
115 |
}); |
123 |
}); |
116 |
} |
124 |
} |
117 |
); |
125 |
); |
118 |
my $sec_best_case = timethis(500, |
126 |
my $mid_case2 = timethis(500, |
119 |
sub { Koha::CirculationRules->get_effective_rule({ |
127 |
sub { Koha::CirculationRules->get_effective_rule({ |
120 |
branchcode => $branchcode, |
128 |
branchcode => $branchcode, |
121 |
categorycode => $categorycode, |
129 |
categorycode => $categorycode, |
122 |
itemtype => 'nonexistent', |
130 |
itemtype => 'nonexistent', |
|
|
131 |
onsite_checkout => 'nonexistent', |
132 |
rule_name => 'nonexistent', |
133 |
}); |
134 |
} |
135 |
); |
136 |
my $mid_case3 = timethis(500, |
137 |
sub { Koha::CirculationRules->get_effective_rule({ |
138 |
branchcode => $branchcode, |
139 |
categorycode => $categorycode, |
140 |
itemtype => $itemtype, |
141 |
onsite_checkout => 'nonexistent', |
123 |
rule_name => 'nonexistent', |
142 |
rule_name => 'nonexistent', |
124 |
}); |
143 |
}); |
125 |
} |
144 |
} |
Lines 129-134
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
129 |
branchcode => $branchcode, |
148 |
branchcode => $branchcode, |
130 |
categorycode => $categorycode, |
149 |
categorycode => $categorycode, |
131 |
itemtype => $itemtype, |
150 |
itemtype => $itemtype, |
|
|
151 |
onsite_checkout => $onsite_checkout, |
132 |
rule_name => 'nonexistent', |
152 |
rule_name => 'nonexistent', |
133 |
}); |
153 |
}); |
134 |
} |
154 |
} |
Lines 136-146
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
136 |
ok($worst_case, 'In worst case, get_effective_issuing_rule finds matching' |
156 |
ok($worst_case, 'In worst case, get_effective_issuing_rule finds matching' |
137 |
.' rule '.sprintf('%.2f', $worst_case->iters/$worst_case->cpu_a) |
157 |
.' rule '.sprintf('%.2f', $worst_case->iters/$worst_case->cpu_a) |
138 |
.' times per second.'); |
158 |
.' times per second.'); |
139 |
ok($mid_case, 'In mid case, get_effective_issuing_rule finds matching' |
159 |
ok($mid_case1, 'In mid case 1, get_effective_issuing_rule finds matching' |
140 |
.' rule '.sprintf('%.2f', $mid_case->iters/$mid_case->cpu_a) |
160 |
.' rule '.sprintf('%.2f', $mid_case1->iters/$mid_case1->cpu_a) |
|
|
161 |
.' times per second.'); |
162 |
ok($mid_case2, 'In mid case 2, get_effective_issuing_rule finds matching' |
163 |
.' rule '.sprintf('%.2f', $mid_case2->iters/$mid_case2->cpu_a) |
141 |
.' times per second.'); |
164 |
.' times per second.'); |
142 |
ok($sec_best_case, 'In second best case, get_effective_issuing_rule finds matching' |
165 |
ok($mid_case3, 'In mid case 3, get_effective_issuing_rule finds matching' |
143 |
.' rule '.sprintf('%.2f', $sec_best_case->iters/$sec_best_case->cpu_a) |
166 |
.' rule '.sprintf('%.2f', $mid_case3->iters/$mid_case3->cpu_a) |
144 |
.' times per second.'); |
167 |
.' times per second.'); |
145 |
ok($best_case, 'In best case, get_effective_issuing_rule finds matching' |
168 |
ok($best_case, 'In best case, get_effective_issuing_rule finds matching' |
146 |
.' rule '.sprintf('%.2f', $best_case->iters/$best_case->cpu_a) |
169 |
.' rule '.sprintf('%.2f', $best_case->iters/$best_case->cpu_a) |
Lines 304-309
subtest 'clone' => sub {
Link Here
|
304 |
my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'}; |
327 |
my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'}; |
305 |
my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'}; |
328 |
my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'}; |
306 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{'itemtype'}; |
329 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{'itemtype'}; |
|
|
330 |
my $onsite_checkout = 0; |
307 |
|
331 |
|
308 |
subtest 'Clone multiple rules' => sub { |
332 |
subtest 'Clone multiple rules' => sub { |
309 |
plan tests => 4; |
333 |
plan tests => 4; |
Lines 314-319
subtest 'clone' => sub {
Link Here
|
314 |
branchcode => undef, |
338 |
branchcode => undef, |
315 |
categorycode => $categorycode, |
339 |
categorycode => $categorycode, |
316 |
itemtype => $itemtype, |
340 |
itemtype => $itemtype, |
|
|
341 |
onsite_checkout => $onsite_checkout, |
317 |
rule_name => 'fine', |
342 |
rule_name => 'fine', |
318 |
rule_value => 5, |
343 |
rule_value => 5, |
319 |
})->store; |
344 |
})->store; |
Lines 322-327
subtest 'clone' => sub {
Link Here
|
322 |
branchcode => undef, |
347 |
branchcode => undef, |
323 |
categorycode => $categorycode, |
348 |
categorycode => $categorycode, |
324 |
itemtype => $itemtype, |
349 |
itemtype => $itemtype, |
|
|
350 |
onsite_checkout => $onsite_checkout, |
325 |
rule_name => 'lengthunit', |
351 |
rule_name => 'lengthunit', |
326 |
rule_value => 'days', |
352 |
rule_value => 'days', |
327 |
})->store; |
353 |
})->store; |
Lines 332-343
subtest 'clone' => sub {
Link Here
|
332 |
branchcode => $branchcode, |
358 |
branchcode => $branchcode, |
333 |
categorycode => $categorycode, |
359 |
categorycode => $categorycode, |
334 |
itemtype => $itemtype, |
360 |
itemtype => $itemtype, |
|
|
361 |
onsite_checkout => $onsite_checkout, |
335 |
rule_name => 'fine', |
362 |
rule_name => 'fine', |
336 |
}); |
363 |
}); |
337 |
my $rule_lengthunit = Koha::CirculationRules->get_effective_rule({ |
364 |
my $rule_lengthunit = Koha::CirculationRules->get_effective_rule({ |
338 |
branchcode => $branchcode, |
365 |
branchcode => $branchcode, |
339 |
categorycode => $categorycode, |
366 |
categorycode => $categorycode, |
340 |
itemtype => $itemtype, |
367 |
itemtype => $itemtype, |
|
|
368 |
onsite_checkout => $onsite_checkout, |
341 |
rule_name => 'lengthunit', |
369 |
rule_name => 'lengthunit', |
342 |
}); |
370 |
}); |
343 |
|
371 |
|
Lines 347-352
subtest 'clone' => sub {
Link Here
|
347 |
branchcode => $branchcode, |
375 |
branchcode => $branchcode, |
348 |
categorycode => $categorycode, |
376 |
categorycode => $categorycode, |
349 |
itemtype => $itemtype, |
377 |
itemtype => $itemtype, |
|
|
378 |
onsite_checkout => $onsite_checkout, |
350 |
rule_name => 'fine', |
379 |
rule_name => 'fine', |
351 |
rule_value => 5, |
380 |
rule_value => 5, |
352 |
}, |
381 |
}, |
Lines 359-364
subtest 'clone' => sub {
Link Here
|
359 |
branchcode => $branchcode, |
388 |
branchcode => $branchcode, |
360 |
categorycode => $categorycode, |
389 |
categorycode => $categorycode, |
361 |
itemtype => $itemtype, |
390 |
itemtype => $itemtype, |
|
|
391 |
onsite_checkout => $onsite_checkout, |
362 |
rule_name => 'lengthunit', |
392 |
rule_name => 'lengthunit', |
363 |
rule_value => 'days', |
393 |
rule_value => 'days', |
364 |
}, |
394 |
}, |
Lines 377-382
subtest 'clone' => sub {
Link Here
|
377 |
branchcode => undef, |
407 |
branchcode => undef, |
378 |
categorycode => $categorycode, |
408 |
categorycode => $categorycode, |
379 |
itemtype => $itemtype, |
409 |
itemtype => $itemtype, |
|
|
410 |
onsite_checkout => $onsite_checkout, |
380 |
rule_name => 'fine', |
411 |
rule_name => 'fine', |
381 |
rule_value => 5, |
412 |
rule_value => 5, |
382 |
})->store; |
413 |
})->store; |
Lines 388-393
subtest 'clone' => sub {
Link Here
|
388 |
branchcode => $branchcode, |
419 |
branchcode => $branchcode, |
389 |
categorycode => $categorycode, |
420 |
categorycode => $categorycode, |
390 |
itemtype => $itemtype, |
421 |
itemtype => $itemtype, |
|
|
422 |
onsite_checkout => $onsite_checkout, |
391 |
rule_name => 'fine', |
423 |
rule_name => 'fine', |
392 |
}); |
424 |
}); |
393 |
|
425 |
|
Lines 397-402
subtest 'clone' => sub {
Link Here
|
397 |
branchcode => $branchcode, |
429 |
branchcode => $branchcode, |
398 |
categorycode => $categorycode, |
430 |
categorycode => $categorycode, |
399 |
itemtype => $itemtype, |
431 |
itemtype => $itemtype, |
|
|
432 |
onsite_checkout => $onsite_checkout, |
400 |
rule_name => 'fine', |
433 |
rule_name => 'fine', |
401 |
rule_value => '5', |
434 |
rule_value => '5', |
402 |
}, |
435 |
}, |
403 |
- |
|
|