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