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