|
Lines 134-209
subtest 'cancel' => sub {
Link Here
|
| 134 |
is( $third_hold->discard_changes->priority, 2, 'Third hold should now be second' ); |
134 |
is( $third_hold->discard_changes->priority, 2, 'Third hold should now be second' ); |
| 135 |
|
135 |
|
| 136 |
subtest 'charge_cancel_fee parameter' => sub { |
136 |
subtest 'charge_cancel_fee parameter' => sub { |
| 137 |
plan tests => 15; |
137 |
plan tests => 18; |
| 138 |
my $library1 = $builder->build({ |
138 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 139 |
source => 'Branch', |
139 |
my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 140 |
}); |
140 |
my $library3 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 141 |
my $library2 = $builder->build({ |
|
|
| 142 |
source => 'Branch', |
| 143 |
}); |
| 144 |
|
141 |
|
| 145 |
my $bib_title = "Test Title"; |
142 |
my $bib_title = "Test Title"; |
| 146 |
|
143 |
|
| 147 |
my $borrower = $builder->build({ |
144 |
my $borrower = $builder->build_object({ class => "Koha::Patrons", value => { branchcode => $library1->branchcode } }); |
| 148 |
source => 'Borrower', |
|
|
| 149 |
value => { |
| 150 |
branchcode => $library1->{branchcode}, |
| 151 |
} |
| 152 |
}); |
| 153 |
|
145 |
|
| 154 |
my $itemtype1 = $builder->build({ |
146 |
my $itemtype1 = $builder->build_object( { class => 'Koha::ItemTypes', value => {} } ); |
| 155 |
source => 'Itemtype', |
147 |
my $itemtype2 = $builder->build_object( { class => 'Koha::ItemTypes', value => {} } ); |
| 156 |
value => {} |
148 |
my $itemtype3 = $builder->build_object( { class => 'Koha::ItemTypes', value => {} } ); |
| 157 |
}); |
149 |
my $itemtype4 = $builder->build_object( { class => 'Koha::ItemTypes', value => {} } ); |
| 158 |
my $itemtype2 = $builder->build({ |
|
|
| 159 |
source => 'Itemtype', |
| 160 |
value => {} |
| 161 |
}); |
| 162 |
my $itemtype3 = $builder->build({ |
| 163 |
source => 'Itemtype', |
| 164 |
value => {} |
| 165 |
}); |
| 166 |
my $itemtype4 = $builder->build({ |
| 167 |
source => 'Itemtype', |
| 168 |
value => {} |
| 169 |
}); |
| 170 |
|
150 |
|
| 171 |
my $borrowernumber = $borrower->{borrowernumber}; |
151 |
my $borrowernumber = $borrower->borrowernumber; |
| 172 |
|
152 |
|
| 173 |
my $library_A_code = $library1->{branchcode}; |
153 |
my $library_A_code = $library1->branchcode; |
| 174 |
|
154 |
|
| 175 |
my $biblio = $builder->build_sample_biblio({itemtype => $itemtype1->{itemtype}}); |
155 |
my $biblio = $builder->build_sample_biblio({itemtype => $itemtype1->itemtype}); |
| 176 |
my $biblionumber = $biblio->biblionumber; |
156 |
my $biblionumber = $biblio->biblionumber; |
| 177 |
my $item1 = $builder->build_sample_item({ |
157 |
my $item1 = $builder->build_sample_item({ |
| 178 |
biblionumber => $biblionumber, |
158 |
biblionumber => $biblionumber, |
| 179 |
itype => $itemtype1->{itemtype}, |
159 |
itype => $itemtype1->itemtype, |
| 180 |
homebranch => $library_A_code, |
160 |
homebranch => $library_A_code, |
| 181 |
holdingbranch => $library_A_code |
161 |
holdingbranch => $library_A_code |
| 182 |
}); |
162 |
}); |
| 183 |
my $item2 = $builder->build_sample_item({ |
163 |
my $item2 = $builder->build_sample_item({ |
| 184 |
biblionumber => $biblionumber, |
164 |
biblionumber => $biblionumber, |
| 185 |
itype => $itemtype2->{itemtype}, |
165 |
itype => $itemtype2->itemtype, |
| 186 |
homebranch => $library_A_code, |
166 |
homebranch => $library_A_code, |
| 187 |
holdingbranch => $library_A_code |
167 |
holdingbranch => $library_A_code |
| 188 |
}); |
168 |
}); |
| 189 |
my $item3 = $builder->build_sample_item({ |
169 |
my $item3 = $builder->build_sample_item({ |
| 190 |
biblionumber => $biblionumber, |
170 |
biblionumber => $biblionumber, |
| 191 |
itype => $itemtype3->{itemtype}, |
171 |
itype => $itemtype3->itemtype, |
| 192 |
homebranch => $library_A_code, |
172 |
homebranch => $library_A_code, |
| 193 |
holdingbranch => $library_A_code |
173 |
holdingbranch => $library_A_code |
| 194 |
}); |
174 |
}); |
| 195 |
|
175 |
|
| 196 |
my $library_B_code = $library2->{branchcode}; |
176 |
my $library_B_code = $library2->branchcode; |
| 197 |
|
177 |
|
| 198 |
my $biblio2 = $builder->build_sample_biblio({itemtype => $itemtype4->{itemtype}}); |
178 |
my $biblio2 = $builder->build_sample_biblio({itemtype => $itemtype4->itemtype}); |
| 199 |
my $biblionumber2 = $biblio2->biblionumber; |
179 |
my $biblionumber2 = $biblio2->biblionumber; |
| 200 |
my $item4 = $builder->build_sample_item({ |
180 |
my $item4 = $builder->build_sample_item({ |
| 201 |
biblionumber => $biblionumber2, |
181 |
biblionumber => $biblionumber2, |
| 202 |
itype => $itemtype4->{itemtype}, |
182 |
itype => $itemtype4->itemtype, |
| 203 |
homebranch => $library_B_code, |
183 |
homebranch => $library_B_code, |
| 204 |
holdingbranch => $library_B_code |
184 |
holdingbranch => $library_B_code |
| 205 |
}); |
185 |
}); |
| 206 |
|
186 |
|
|
|
187 |
my $library_C_code = $library3->branchcode; |
| 188 |
|
| 189 |
my $biblio3 = $builder->build_sample_biblio({itemtype => $itemtype4->itemtype}); |
| 190 |
my $biblionumber3 = $biblio3->biblionumber; |
| 191 |
my $item5 = $builder->build_sample_item({ |
| 192 |
biblionumber => $biblionumber3, |
| 193 |
itype => $itemtype4->itemtype, |
| 194 |
homebranch => $library_C_code, |
| 195 |
holdingbranch => $library_C_code |
| 196 |
}); |
| 197 |
|
| 207 |
Koha::CirculationRules->set_rules( |
198 |
Koha::CirculationRules->set_rules( |
| 208 |
{ |
199 |
{ |
| 209 |
itemtype => undef, |
200 |
itemtype => undef, |
|
Lines 216-222
subtest 'cancel' => sub {
Link Here
|
| 216 |
); |
207 |
); |
| 217 |
Koha::CirculationRules->set_rules( |
208 |
Koha::CirculationRules->set_rules( |
| 218 |
{ |
209 |
{ |
| 219 |
itemtype => $itemtype1->{itemtype}, |
210 |
itemtype => $itemtype1->itemtype, |
| 220 |
categorycode => undef, |
211 |
categorycode => undef, |
| 221 |
branchcode => undef, |
212 |
branchcode => undef, |
| 222 |
rules => { |
213 |
rules => { |
|
Lines 226-232
subtest 'cancel' => sub {
Link Here
|
| 226 |
); |
217 |
); |
| 227 |
Koha::CirculationRules->set_rules( |
218 |
Koha::CirculationRules->set_rules( |
| 228 |
{ |
219 |
{ |
| 229 |
itemtype => $itemtype2->{itemtype}, |
220 |
itemtype => $itemtype2->itemtype, |
| 230 |
categorycode => undef, |
221 |
categorycode => undef, |
| 231 |
branchcode => undef, |
222 |
branchcode => undef, |
| 232 |
rules => { |
223 |
rules => { |
|
Lines 244-249
subtest 'cancel' => sub {
Link Here
|
| 244 |
} |
235 |
} |
| 245 |
} |
236 |
} |
| 246 |
); |
237 |
); |
|
|
238 |
Koha::CirculationRules->set_rules( |
| 239 |
{ |
| 240 |
itemtype => undef, |
| 241 |
categorycode => undef, |
| 242 |
branchcode => $library_C_code, |
| 243 |
rules => { |
| 244 |
expire_reserves_charge => '0' |
| 245 |
} |
| 246 |
} |
| 247 |
); |
| 247 |
|
248 |
|
| 248 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
249 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
| 249 |
|
250 |
|
|
Lines 252-258
subtest 'cancel' => sub {
Link Here
|
| 252 |
my $status; |
253 |
my $status; |
| 253 |
my $start_balance; |
254 |
my $start_balance; |
| 254 |
|
255 |
|
| 255 |
# TEST: Hold itemtype1 item |
256 |
# TEST: Hold itemtype1 item |
| 256 |
$reserve_id = AddReserve( |
257 |
$reserve_id = AddReserve( |
| 257 |
{ |
258 |
{ |
| 258 |
branchcode => $library_A_code, |
259 |
branchcode => $library_A_code, |
|
Lines 277-283
subtest 'cancel' => sub {
Link Here
|
| 277 |
|
278 |
|
| 278 |
is( $account->balance() - $start_balance, 111, "Used circulation rule for itemtype1" ); |
279 |
is( $account->balance() - $start_balance, 111, "Used circulation rule for itemtype1" ); |
| 279 |
|
280 |
|
| 280 |
# TEST: circulation rule for itemtype2 has 'expire_reserves_charge' set undef, so it should use ExpireReservesMaxPickUpDelayCharge preference |
281 |
# TEST: circulation rule for itemtype2 has 'expire_reserves_charge' set undef, so it should use ExpireReservesMaxPickUpDelayCharge preference |
| 281 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 222); |
282 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 222); |
| 282 |
|
283 |
|
| 283 |
$reserve_id = AddReserve( |
284 |
$reserve_id = AddReserve( |
|
Lines 304-310
subtest 'cancel' => sub {
Link Here
|
| 304 |
|
305 |
|
| 305 |
is( $account->balance() - $start_balance, 222, "Used ExpireReservesMaxPickUpDelayCharge preference as expire_reserves_charge set to undef" ); |
306 |
is( $account->balance() - $start_balance, 222, "Used ExpireReservesMaxPickUpDelayCharge preference as expire_reserves_charge set to undef" ); |
| 306 |
|
307 |
|
| 307 |
# TEST: no circulation rules for itemtype3, it should use ExpireReservesMaxPickUpDelayCharge preference |
308 |
# TEST: no circulation rules for itemtype3, it should use ExpireReservesMaxPickUpDelayCharge preference |
| 308 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 333); |
309 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 333); |
| 309 |
|
310 |
|
| 310 |
$reserve_id = AddReserve( |
311 |
$reserve_id = AddReserve( |
|
Lines 331-337
subtest 'cancel' => sub {
Link Here
|
| 331 |
|
332 |
|
| 332 |
is( $account->balance() - $start_balance, 333, "Used ExpireReservesMaxPickUpDelayCharge preference as there's no circulation rules for itemtype3" ); |
333 |
is( $account->balance() - $start_balance, 333, "Used ExpireReservesMaxPickUpDelayCharge preference as there's no circulation rules for itemtype3" ); |
| 333 |
|
334 |
|
| 334 |
# TEST: circulation rule for itemtype4 with library_B_code |
335 |
# TEST: circulation rule for itemtype4 with library_B_code |
| 335 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 555); |
336 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 555); |
| 336 |
|
337 |
|
| 337 |
$reserve_id = AddReserve( |
338 |
$reserve_id = AddReserve( |
|
Lines 358-363
subtest 'cancel' => sub {
Link Here
|
| 358 |
|
359 |
|
| 359 |
is( $account->balance() - $start_balance, 444, "Used circulation rule for itemtype4 with library_B_code" ); |
360 |
is( $account->balance() - $start_balance, 444, "Used circulation rule for itemtype4 with library_B_code" ); |
| 360 |
|
361 |
|
|
|
362 |
# TEST: circulation rule for library_C_code that has expire_reserves_charge = 0 |
| 363 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 777); |
| 364 |
|
| 365 |
$reserve_id = AddReserve( |
| 366 |
{ |
| 367 |
branchcode => $library_C_code, |
| 368 |
borrowernumber => $borrowernumber, |
| 369 |
biblionumber => $biblionumber3, |
| 370 |
priority => 1, |
| 371 |
itemnumber => $item5->itemnumber, |
| 372 |
} |
| 373 |
); |
| 374 |
|
| 375 |
$account = Koha::Account->new({ patron_id => $borrowernumber }); |
| 376 |
|
| 377 |
( $status ) = CheckReserves($item5->id); |
| 378 |
is( $status, 'Reserved', "Hold for the itemtype5 created" ); |
| 379 |
|
| 380 |
$start_balance = $account->balance(); |
| 381 |
|
| 382 |
Koha::Holds->find( $reserve_id )->cancel({ charge_cancel_fee => 1 }); |
| 383 |
|
| 384 |
( $status ) = CheckReserves($item5->id); |
| 385 |
is( $status, '', "Hold for the itemtype5 cancelled" ); |
| 386 |
|
| 387 |
is( $account->balance() - $start_balance, 0, "Used circulation rule for itemtype4 with library_C_code even though it's 0" ); |
| 388 |
|
| 389 |
# TEST: charge_cancel_fee is 0 |
| 361 |
$reserve_id = AddReserve( |
390 |
$reserve_id = AddReserve( |
| 362 |
{ |
391 |
{ |
| 363 |
branchcode => $library_B_code, |
392 |
branchcode => $library_B_code, |
| 364 |
- |
|
|