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 $checkout_type = $Koha::Checkouts::type->{checkout}; |
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 |
checkout_type => 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 |
checkout_type => 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 |
checkout_type => 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 |
checkout_type => 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 |
checkout_type => '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 |
checkout_type => '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 |
checkout_type => '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 |
checkout_type => '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 |
checkout_type => $checkout_type, |
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 292-297
subtest 'clone' => sub {
Link Here
|
292 |
my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'}; |
315 |
my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'}; |
293 |
my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'}; |
316 |
my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'}; |
294 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{'itemtype'}; |
317 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{'itemtype'}; |
|
|
318 |
my $checkout_type = $Koha::Checkouts::type->{checkout}; |
295 |
|
319 |
|
296 |
subtest 'Clone multiple rules' => sub { |
320 |
subtest 'Clone multiple rules' => sub { |
297 |
plan tests => 4; |
321 |
plan tests => 4; |
Lines 302-307
subtest 'clone' => sub {
Link Here
|
302 |
branchcode => undef, |
326 |
branchcode => undef, |
303 |
categorycode => $categorycode, |
327 |
categorycode => $categorycode, |
304 |
itemtype => $itemtype, |
328 |
itemtype => $itemtype, |
|
|
329 |
checkout_type => $checkout_type, |
305 |
rule_name => 'fine', |
330 |
rule_name => 'fine', |
306 |
rule_value => 5, |
331 |
rule_value => 5, |
307 |
})->store; |
332 |
})->store; |
Lines 310-315
subtest 'clone' => sub {
Link Here
|
310 |
branchcode => undef, |
335 |
branchcode => undef, |
311 |
categorycode => $categorycode, |
336 |
categorycode => $categorycode, |
312 |
itemtype => $itemtype, |
337 |
itemtype => $itemtype, |
|
|
338 |
checkout_type => $checkout_type, |
313 |
rule_name => 'lengthunit', |
339 |
rule_name => 'lengthunit', |
314 |
rule_value => 'days', |
340 |
rule_value => 'days', |
315 |
})->store; |
341 |
})->store; |
Lines 320-331
subtest 'clone' => sub {
Link Here
|
320 |
branchcode => $branchcode, |
346 |
branchcode => $branchcode, |
321 |
categorycode => $categorycode, |
347 |
categorycode => $categorycode, |
322 |
itemtype => $itemtype, |
348 |
itemtype => $itemtype, |
|
|
349 |
checkout_type => $checkout_type, |
323 |
rule_name => 'fine', |
350 |
rule_name => 'fine', |
324 |
}); |
351 |
}); |
325 |
my $rule_lengthunit = Koha::CirculationRules->get_effective_rule({ |
352 |
my $rule_lengthunit = Koha::CirculationRules->get_effective_rule({ |
326 |
branchcode => $branchcode, |
353 |
branchcode => $branchcode, |
327 |
categorycode => $categorycode, |
354 |
categorycode => $categorycode, |
328 |
itemtype => $itemtype, |
355 |
itemtype => $itemtype, |
|
|
356 |
checkout_type => $checkout_type, |
329 |
rule_name => 'lengthunit', |
357 |
rule_name => 'lengthunit', |
330 |
}); |
358 |
}); |
331 |
|
359 |
|
Lines 335-340
subtest 'clone' => sub {
Link Here
|
335 |
branchcode => $branchcode, |
363 |
branchcode => $branchcode, |
336 |
categorycode => $categorycode, |
364 |
categorycode => $categorycode, |
337 |
itemtype => $itemtype, |
365 |
itemtype => $itemtype, |
|
|
366 |
checkout_type => $checkout_type, |
338 |
rule_name => 'fine', |
367 |
rule_name => 'fine', |
339 |
rule_value => 5, |
368 |
rule_value => 5, |
340 |
}, |
369 |
}, |
Lines 347-352
subtest 'clone' => sub {
Link Here
|
347 |
branchcode => $branchcode, |
376 |
branchcode => $branchcode, |
348 |
categorycode => $categorycode, |
377 |
categorycode => $categorycode, |
349 |
itemtype => $itemtype, |
378 |
itemtype => $itemtype, |
|
|
379 |
checkout_type => $checkout_type, |
350 |
rule_name => 'lengthunit', |
380 |
rule_name => 'lengthunit', |
351 |
rule_value => 'days', |
381 |
rule_value => 'days', |
352 |
}, |
382 |
}, |
Lines 365-370
subtest 'clone' => sub {
Link Here
|
365 |
branchcode => undef, |
395 |
branchcode => undef, |
366 |
categorycode => $categorycode, |
396 |
categorycode => $categorycode, |
367 |
itemtype => $itemtype, |
397 |
itemtype => $itemtype, |
|
|
398 |
checkout_type => $checkout_type, |
368 |
rule_name => 'fine', |
399 |
rule_name => 'fine', |
369 |
rule_value => 5, |
400 |
rule_value => 5, |
370 |
})->store; |
401 |
})->store; |
Lines 376-381
subtest 'clone' => sub {
Link Here
|
376 |
branchcode => $branchcode, |
407 |
branchcode => $branchcode, |
377 |
categorycode => $categorycode, |
408 |
categorycode => $categorycode, |
378 |
itemtype => $itemtype, |
409 |
itemtype => $itemtype, |
|
|
410 |
checkout_type => $checkout_type, |
379 |
rule_name => 'fine', |
411 |
rule_name => 'fine', |
380 |
}); |
412 |
}); |
381 |
|
413 |
|
Lines 385-390
subtest 'clone' => sub {
Link Here
|
385 |
branchcode => $branchcode, |
417 |
branchcode => $branchcode, |
386 |
categorycode => $categorycode, |
418 |
categorycode => $categorycode, |
387 |
itemtype => $itemtype, |
419 |
itemtype => $itemtype, |
|
|
420 |
checkout_type => $checkout_type, |
388 |
rule_name => 'fine', |
421 |
rule_name => 'fine', |
389 |
rule_value => '5', |
422 |
rule_value => '5', |
390 |
}, |
423 |
}, |
391 |
- |
|
|