Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 3; |
22 |
use Test::More tests => 2; |
23 |
use Test::Deep qw( cmp_methods ); |
23 |
use Test::Deep qw( cmp_methods ); |
24 |
use Test::Exception; |
24 |
use Test::Exception; |
25 |
|
25 |
|
Lines 54-59
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
54 |
categorycode => undef, |
54 |
categorycode => undef, |
55 |
itemtype => undef, |
55 |
itemtype => undef, |
56 |
rule_name => 'fine', |
56 |
rule_name => 'fine', |
|
|
57 |
rule_value => 1, |
57 |
}); |
58 |
}); |
58 |
is($rule, undef, 'When I attempt to get effective issuing rule by' |
59 |
is($rule, undef, 'When I attempt to get effective issuing rule by' |
59 |
.' providing undefined values, then undef is returned.'); |
60 |
.' providing undefined values, then undef is returned.'); |
Lines 62-67
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
62 |
categorycode => undef, |
63 |
categorycode => undef, |
63 |
itemtype => undef, |
64 |
itemtype => undef, |
64 |
rule_name => 'fine', |
65 |
rule_name => 'fine', |
|
|
66 |
rule_value => 2, |
65 |
})->store, 'Given I added an issuing rule branchcode => undef,' |
67 |
})->store, 'Given I added an issuing rule branchcode => undef,' |
66 |
.' categorycode => undef, itemtype => undef,'); |
68 |
.' categorycode => undef, itemtype => undef,'); |
67 |
$rule = Koha::CirculationRules->get_effective_rule({ |
69 |
$rule = Koha::CirculationRules->get_effective_rule({ |
Lines 69-74
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
69 |
categorycode => undef, |
71 |
categorycode => undef, |
70 |
itemtype => undef, |
72 |
itemtype => undef, |
71 |
rule_name => 'fine', |
73 |
rule_name => 'fine', |
|
|
74 |
rule_value => 3, |
72 |
}); |
75 |
}); |
73 |
_is_row_match( |
76 |
_is_row_match( |
74 |
$rule, |
77 |
$rule, |
Lines 94-99
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
94 |
categorycode => $categorycode, |
97 |
categorycode => $categorycode, |
95 |
itemtype => $itemtype, |
98 |
itemtype => $itemtype, |
96 |
rule_name => 'fine', |
99 |
rule_name => 'fine', |
|
|
100 |
rule_value => 4, |
97 |
}); |
101 |
}); |
98 |
is($rule, undef, 'When I attempt to get effective issuing rule, then undef' |
102 |
is($rule, undef, 'When I attempt to get effective issuing rule, then undef' |
99 |
.' is returned.'); |
103 |
.' is returned.'); |
Lines 103-114
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
103 |
categorycode => undef, |
107 |
categorycode => undef, |
104 |
itemtype => undef, |
108 |
itemtype => undef, |
105 |
rule_name => 'fine', |
109 |
rule_name => 'fine', |
|
|
110 |
rule_value => 5, |
106 |
})->store, 'Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => undef,'); |
111 |
})->store, 'Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => undef,'); |
107 |
$rule = Koha::CirculationRules->get_effective_rule({ |
112 |
$rule = Koha::CirculationRules->get_effective_rule({ |
108 |
branchcode => $branchcode, |
113 |
branchcode => $branchcode, |
109 |
categorycode => $categorycode, |
114 |
categorycode => $categorycode, |
110 |
itemtype => $itemtype, |
115 |
itemtype => $itemtype, |
111 |
rule_name => 'fine', |
116 |
rule_name => 'fine', |
|
|
117 |
rule_value => 6, |
112 |
}); |
118 |
}); |
113 |
_is_row_match( |
119 |
_is_row_match( |
114 |
$rule, |
120 |
$rule, |
Lines 126-137
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
126 |
categorycode => undef, |
132 |
categorycode => undef, |
127 |
itemtype => $itemtype, |
133 |
itemtype => $itemtype, |
128 |
rule_name => 'fine', |
134 |
rule_name => 'fine', |
|
|
135 |
rule_value => 7, |
129 |
})->store, "Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => $itemtype,"); |
136 |
})->store, "Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => $itemtype,"); |
130 |
$rule = Koha::CirculationRules->get_effective_rule({ |
137 |
$rule = Koha::CirculationRules->get_effective_rule({ |
131 |
branchcode => $branchcode, |
138 |
branchcode => $branchcode, |
132 |
categorycode => $categorycode, |
139 |
categorycode => $categorycode, |
133 |
itemtype => $itemtype, |
140 |
itemtype => $itemtype, |
134 |
rule_name => 'fine', |
141 |
rule_name => 'fine', |
|
|
142 |
rule_value => 8, |
135 |
}); |
143 |
}); |
136 |
_is_row_match( |
144 |
_is_row_match( |
137 |
$rule, |
145 |
$rule, |
Lines 149-160
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
149 |
categorycode => $categorycode, |
157 |
categorycode => $categorycode, |
150 |
itemtype => undef, |
158 |
itemtype => undef, |
151 |
rule_name => 'fine', |
159 |
rule_name => 'fine', |
|
|
160 |
rule_value => 9, |
152 |
})->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => undef,"); |
161 |
})->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => undef,"); |
153 |
$rule = Koha::CirculationRules->get_effective_rule({ |
162 |
$rule = Koha::CirculationRules->get_effective_rule({ |
154 |
branchcode => $branchcode, |
163 |
branchcode => $branchcode, |
155 |
categorycode => $categorycode, |
164 |
categorycode => $categorycode, |
156 |
itemtype => $itemtype, |
165 |
itemtype => $itemtype, |
157 |
rule_name => 'fine', |
166 |
rule_name => 'fine', |
|
|
167 |
rule_value => 10, |
158 |
}); |
168 |
}); |
159 |
_is_row_match( |
169 |
_is_row_match( |
160 |
$rule, |
170 |
$rule, |
Lines 172-183
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
172 |
categorycode => $categorycode, |
182 |
categorycode => $categorycode, |
173 |
itemtype => $itemtype, |
183 |
itemtype => $itemtype, |
174 |
rule_name => 'fine', |
184 |
rule_name => 'fine', |
|
|
185 |
rule_value => 11, |
175 |
})->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => $itemtype,"); |
186 |
})->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => $itemtype,"); |
176 |
$rule = Koha::CirculationRules->get_effective_rule({ |
187 |
$rule = Koha::CirculationRules->get_effective_rule({ |
177 |
branchcode => $branchcode, |
188 |
branchcode => $branchcode, |
178 |
categorycode => $categorycode, |
189 |
categorycode => $categorycode, |
179 |
itemtype => $itemtype, |
190 |
itemtype => $itemtype, |
180 |
rule_name => 'fine', |
191 |
rule_name => 'fine', |
|
|
192 |
rule_value => 12, |
181 |
}); |
193 |
}); |
182 |
_is_row_match( |
194 |
_is_row_match( |
183 |
$rule, |
195 |
$rule, |
Lines 195-206
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
195 |
categorycode => undef, |
207 |
categorycode => undef, |
196 |
itemtype => undef, |
208 |
itemtype => undef, |
197 |
rule_name => 'fine', |
209 |
rule_name => 'fine', |
|
|
210 |
rule_value => 13, |
198 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => undef,"); |
211 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => undef,"); |
199 |
$rule = Koha::CirculationRules->get_effective_rule({ |
212 |
$rule = Koha::CirculationRules->get_effective_rule({ |
200 |
branchcode => $branchcode, |
213 |
branchcode => $branchcode, |
201 |
categorycode => $categorycode, |
214 |
categorycode => $categorycode, |
202 |
itemtype => $itemtype, |
215 |
itemtype => $itemtype, |
203 |
rule_name => 'fine', |
216 |
rule_name => 'fine', |
|
|
217 |
rule_value => 14, |
204 |
}); |
218 |
}); |
205 |
_is_row_match( |
219 |
_is_row_match( |
206 |
$rule, |
220 |
$rule, |
Lines 218-229
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
218 |
categorycode => undef, |
232 |
categorycode => undef, |
219 |
itemtype => $itemtype, |
233 |
itemtype => $itemtype, |
220 |
rule_name => 'fine', |
234 |
rule_name => 'fine', |
|
|
235 |
rule_value => 15, |
221 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => $itemtype,"); |
236 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => $itemtype,"); |
222 |
$rule = Koha::CirculationRules->get_effective_rule({ |
237 |
$rule = Koha::CirculationRules->get_effective_rule({ |
223 |
branchcode => $branchcode, |
238 |
branchcode => $branchcode, |
224 |
categorycode => $categorycode, |
239 |
categorycode => $categorycode, |
225 |
itemtype => $itemtype, |
240 |
itemtype => $itemtype, |
226 |
rule_name => 'fine', |
241 |
rule_name => 'fine', |
|
|
242 |
rule_value => 16, |
227 |
}); |
243 |
}); |
228 |
_is_row_match( |
244 |
_is_row_match( |
229 |
$rule, |
245 |
$rule, |
Lines 241-252
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
241 |
categorycode => $categorycode, |
257 |
categorycode => $categorycode, |
242 |
itemtype => undef, |
258 |
itemtype => undef, |
243 |
rule_name => 'fine', |
259 |
rule_name => 'fine', |
|
|
260 |
rule_value => 17, |
244 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => undef,"); |
261 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => undef,"); |
245 |
$rule = Koha::CirculationRules->get_effective_rule({ |
262 |
$rule = Koha::CirculationRules->get_effective_rule({ |
246 |
branchcode => $branchcode, |
263 |
branchcode => $branchcode, |
247 |
categorycode => $categorycode, |
264 |
categorycode => $categorycode, |
248 |
itemtype => $itemtype, |
265 |
itemtype => $itemtype, |
249 |
rule_name => 'fine', |
266 |
rule_name => 'fine', |
|
|
267 |
rule_value => 18, |
250 |
}); |
268 |
}); |
251 |
_is_row_match( |
269 |
_is_row_match( |
252 |
$rule, |
270 |
$rule, |
Lines 264-275
subtest 'get_effective_issuing_rule' => sub {
Link Here
|
264 |
categorycode => $categorycode, |
282 |
categorycode => $categorycode, |
265 |
itemtype => $itemtype, |
283 |
itemtype => $itemtype, |
266 |
rule_name => 'fine', |
284 |
rule_name => 'fine', |
|
|
285 |
rule_value => 19, |
267 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype,"); |
286 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype,"); |
268 |
$rule = Koha::CirculationRules->get_effective_rule({ |
287 |
$rule = Koha::CirculationRules->get_effective_rule({ |
269 |
branchcode => $branchcode, |
288 |
branchcode => $branchcode, |
270 |
categorycode => $categorycode, |
289 |
categorycode => $categorycode, |
271 |
itemtype => $itemtype, |
290 |
itemtype => $itemtype, |
272 |
rule_name => 'fine', |
291 |
rule_name => 'fine', |
|
|
292 |
rule_value => 20, |
273 |
}); |
293 |
}); |
274 |
_is_row_match( |
294 |
_is_row_match( |
275 |
$rule, |
295 |
$rule, |
Lines 460-512
subtest 'set_rule' => sub {
Link Here
|
460 |
}; |
480 |
}; |
461 |
}; |
481 |
}; |
462 |
|
482 |
|
463 |
subtest 'delete' => sub { |
|
|
464 |
plan tests => 1; |
465 |
|
466 |
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
467 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
468 |
my $category = $builder->build_object({ class => 'Koha::Patron::Categories' }); |
469 |
|
470 |
# We make an issuing rule |
471 |
my $issue_rule = $builder->build_object({ class => 'Koha::IssuingRules', value => { |
472 |
categorycode => $category->categorycode, |
473 |
itemtype => $itemtype->itemtype, |
474 |
branchcode => $library->branchcode |
475 |
} |
476 |
}); |
477 |
|
478 |
my $count = Koha::CirculationRules->search()->count; |
479 |
# Note how many circulation rules we start with |
480 |
|
481 |
# We make some circulation rules for the same thing |
482 |
$builder->build_object({ class => 'Koha::CirculationRules', value => { |
483 |
categorycode => $category->categorycode, |
484 |
itemtype => $itemtype->itemtype, |
485 |
branchcode => $library->branchcode, |
486 |
rule_name => 'maxissueqty', |
487 |
} |
488 |
}); |
489 |
$builder->build_object({ class => 'Koha::CirculationRules', value => { |
490 |
categorycode => $category->categorycode, |
491 |
itemtype => $itemtype->itemtype, |
492 |
branchcode => $library->branchcode, |
493 |
rule_name => 'maxonsiteissueqty', |
494 |
} |
495 |
}); |
496 |
$builder->build_object({ class => 'Koha::CirculationRules', value => { |
497 |
categorycode => $category->categorycode, |
498 |
itemtype => $itemtype->itemtype, |
499 |
branchcode => $library->branchcode, |
500 |
rule_name => 'another_rule', # That must not be deleted |
501 |
} |
502 |
}); |
503 |
|
504 |
# Now we delete the issuing rule |
505 |
$issue_rule->delete; |
506 |
is( Koha::CirculationRules->search()->count ,$count + 1, "We remove related circ rules maxissueqty and maxonsiteissueqty with our issuing rule"); |
507 |
|
508 |
}; |
509 |
|
510 |
sub _is_row_match { |
483 |
sub _is_row_match { |
511 |
my ( $rule, $expected, $message ) = @_; |
484 |
my ( $rule, $expected, $message ) = @_; |
512 |
|
485 |
|