Lines 192-198
$schema->storage->txn_rollback;
Link Here
|
192 |
|
192 |
|
193 |
|
193 |
|
194 |
subtest 'pickup_locations' => sub { |
194 |
subtest 'pickup_locations' => sub { |
195 |
plan tests => 25; |
195 |
plan tests => 8; |
196 |
|
196 |
|
197 |
$schema->storage->txn_begin; |
197 |
$schema->storage->txn_begin; |
198 |
|
198 |
|
Lines 221-317
subtest 'pickup_locations' => sub {
Link Here
|
221 |
my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
221 |
my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
222 |
my $library5 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
222 |
my $library5 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
223 |
my $library6 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
223 |
my $library6 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
|
|
224 |
my $library7 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
225 |
my $library8 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0 } } ); |
224 |
|
226 |
|
225 |
my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } ); |
|
|
226 |
my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } ); |
227 |
|
228 |
my $group2_3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } ); |
229 |
my $group2_4 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } ); |
230 |
|
231 |
my $group3_5 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library5->branchcode } } ); |
232 |
my $group3_6 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library6->branchcode } } ); |
233 |
|
234 |
my $biblio1 = $builder->build_object( { class => 'Koha::Biblios' } ); |
235 |
my $biblioitem1 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio1->biblionumber } } ); |
236 |
my $biblio2 = $builder->build_object( { class => 'Koha::Biblios' } ); |
237 |
my $biblioitem2 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio2->biblionumber } } ); |
238 |
|
239 |
my $item1_1 = Koha::Item->new({ |
240 |
biblionumber => $biblio1->biblionumber, |
241 |
biblioitemnumber => $biblioitem1->biblioitemnumber, |
242 |
homebranch => $library1->branchcode, |
243 |
holdingbranch => $library2->branchcode, |
244 |
itype => 'test', |
245 |
barcode => "item11barcode", |
246 |
})->store; |
247 |
|
248 |
my $item1_3 = Koha::Item->new({ |
249 |
biblionumber => $biblio1->biblionumber, |
250 |
biblioitemnumber => $biblioitem1->biblioitemnumber, |
251 |
homebranch => $library3->branchcode, |
252 |
holdingbranch => $library4->branchcode, |
253 |
itype => 'test', |
254 |
barcode => "item13barcode", |
255 |
})->store; |
256 |
|
257 |
my $item2_2 = Koha::Item->new({ |
258 |
biblionumber => $biblio2->biblionumber, |
259 |
biblioitemnumber => $biblioitem2->biblioitemnumber, |
260 |
homebranch => $library2->branchcode, |
261 |
holdingbranch => $library1->branchcode, |
262 |
itype => 'test', |
263 |
barcode => "item22barcode", |
264 |
})->store; |
265 |
|
266 |
my $item2_3 = Koha::Item->new({ |
267 |
biblionumber => $biblio2->biblionumber, |
268 |
biblioitemnumber => $biblioitem2->biblioitemnumber, |
269 |
homebranch => $library3->branchcode, |
270 |
holdingbranch => $library3->branchcode, |
271 |
itype => 'test', |
272 |
barcode => "item23barcode", |
273 |
})->store; |
274 |
|
275 |
my $item2_4 = Koha::Item->new({ |
276 |
biblionumber => $biblio2->biblionumber, |
277 |
biblioitemnumber => $biblioitem2->biblioitemnumber, |
278 |
homebranch => $library4->branchcode, |
279 |
holdingbranch => $library4->branchcode, |
280 |
itype => 'test', |
281 |
barcode => "item24barcode", |
282 |
})->store; |
283 |
|
284 |
my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode } } ); |
285 |
my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode } } ); |
286 |
|
287 |
t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch'); |
288 |
|
289 |
#Case 1: holdallowed any, hold_fulfillment_policy any |
290 |
Koha::CirculationRules->set_rules( |
227 |
Koha::CirculationRules->set_rules( |
291 |
{ |
228 |
{ |
292 |
branchcode => undef, |
229 |
branchcode => $library1->branchcode, |
293 |
itemtype => undef, |
|
|
294 |
categorycode => undef, |
295 |
rules => { |
296 |
holdallowed => 2, |
297 |
hold_fulfillment_policy => 'any', |
298 |
returnbranch => 'any' |
299 |
} |
300 |
} |
301 |
); |
302 |
|
303 |
my @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
304 |
my @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
305 |
my @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
306 |
my @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
307 |
|
308 |
|
309 |
ok(scalar(@pl_1_1) == 5 && scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries that are pickup locations'); |
310 |
|
311 |
#Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch' |
312 |
Koha::CirculationRules->set_rules( |
313 |
{ |
314 |
branchcode => undef, |
315 |
itemtype => undef, |
230 |
itemtype => undef, |
316 |
categorycode => undef, |
231 |
categorycode => undef, |
317 |
rules => { |
232 |
rules => { |
Lines 322-424
subtest 'pickup_locations' => sub {
Link Here
|
322 |
} |
237 |
} |
323 |
); |
238 |
); |
324 |
|
239 |
|
325 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
|
|
326 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
327 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
328 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
329 |
|
330 |
ok(scalar(@pl_1_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries that are pickup locations, when item\'s hombebranch equals patron\' homebranch'); |
331 |
ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations'); |
332 |
|
333 |
#Case 3: holdallowed holdgroup, hold_fulfillment_policy any |
334 |
Koha::CirculationRules->set_rules( |
240 |
Koha::CirculationRules->set_rules( |
335 |
{ |
241 |
{ |
336 |
branchcode => undef, |
242 |
branchcode => $library2->branchcode, |
337 |
itemtype => undef, |
243 |
itemtype => undef, |
338 |
categorycode => undef, |
244 |
categorycode => undef, |
339 |
rules => { |
245 |
rules => { |
340 |
holdallowed => 3, |
246 |
holdallowed => 3, |
341 |
hold_fulfillment_policy => 'any', |
|
|
342 |
returnbranch => 'any' |
343 |
} |
344 |
} |
345 |
); |
346 |
|
347 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
348 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
349 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
350 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
351 |
|
352 |
ok(scalar(@pl_1_1) == 5 && scalar(@pl_2_4) == 5 && scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5, 'Returns all libraries that are pickup_locations, when item\'s hombebranch is in patron\' holdgroup'); |
353 |
|
354 |
#Case 4: holdallowed any, hold_fulfillment_policy holdgroup |
355 |
Koha::CirculationRules->set_rules( |
356 |
{ |
357 |
branchcode => undef, |
358 |
itemtype => undef, |
359 |
categorycode => undef, |
360 |
rules => { |
361 |
holdallowed => 2, |
362 |
hold_fulfillment_policy => 'holdgroup', |
247 |
hold_fulfillment_policy => 'holdgroup', |
363 |
returnbranch => 'any' |
248 |
returnbranch => 'any' |
364 |
} |
249 |
} |
365 |
} |
250 |
} |
366 |
); |
251 |
); |
367 |
|
252 |
|
368 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
|
|
369 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
370 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
371 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
372 |
|
373 |
ok(scalar(@pl_1_1) == 3 && scalar(@pl_2_4) == 3 && scalar(@pl_1_4) == 3 && scalar(@pl_2_1) == 3, 'Returns libraries in item\'s holdgroup, and that are pickup_locations'); |
374 |
|
375 |
#Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch' |
376 |
Koha::CirculationRules->set_rules( |
253 |
Koha::CirculationRules->set_rules( |
377 |
{ |
254 |
{ |
378 |
branchcode => undef, |
255 |
branchcode => $library3->branchcode, |
379 |
itemtype => undef, |
256 |
itemtype => undef, |
380 |
categorycode => undef, |
257 |
categorycode => undef, |
381 |
rules => { |
258 |
rules => { |
382 |
holdallowed => 1, |
259 |
holdallowed => 3, |
383 |
hold_fulfillment_policy => 'holdgroup', |
260 |
hold_fulfillment_policy => 'patrongroup', |
384 |
returnbranch => 'any' |
261 |
returnbranch => 'any' |
385 |
} |
262 |
} |
386 |
} |
263 |
} |
387 |
); |
264 |
); |
388 |
|
265 |
|
389 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
|
|
390 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
391 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
392 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
393 |
|
394 |
ok(scalar(@pl_1_1) == 2 && scalar(@pl_2_4) == 1, 'Returns libraries in item\'s holdgroup whose homebranch equals patron\'s homebranch, and that are pickup_locations'); |
395 |
ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations'); |
396 |
|
397 |
#Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup |
398 |
Koha::CirculationRules->set_rules( |
266 |
Koha::CirculationRules->set_rules( |
399 |
{ |
267 |
{ |
400 |
branchcode => undef, |
268 |
branchcode => $library4->branchcode, |
401 |
itemtype => undef, |
269 |
itemtype => undef, |
402 |
categorycode => undef, |
270 |
categorycode => undef, |
403 |
rules => { |
271 |
rules => { |
404 |
holdallowed => 3, |
272 |
holdallowed => 2, |
405 |
hold_fulfillment_policy => 'holdgroup', |
273 |
hold_fulfillment_policy => 'holdingbranch', |
406 |
returnbranch => 'any' |
274 |
returnbranch => 'any' |
407 |
} |
275 |
} |
408 |
} |
276 |
} |
409 |
); |
277 |
); |
410 |
|
278 |
|
411 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
|
|
412 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
413 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
414 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
415 |
|
416 |
ok(scalar(@pl_1_1) == 2 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 1 && scalar(@pl_1_4) == 1, 'Returns libraries in item\'s holdgroup whose homebranch is included patron\'s holdgroup, and that are pickup_locations'); |
417 |
|
418 |
#Case 7: holdallowed any, hold_fulfillment_policy homebranch |
419 |
Koha::CirculationRules->set_rules( |
279 |
Koha::CirculationRules->set_rules( |
420 |
{ |
280 |
{ |
421 |
branchcode => undef, |
281 |
branchcode => $library5->branchcode, |
422 |
itemtype => undef, |
282 |
itemtype => undef, |
423 |
categorycode => undef, |
283 |
categorycode => undef, |
424 |
rules => { |
284 |
rules => { |
Lines 429-639
subtest 'pickup_locations' => sub {
Link Here
|
429 |
} |
289 |
} |
430 |
); |
290 |
); |
431 |
|
291 |
|
432 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
|
|
433 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
434 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
435 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
436 |
|
437 |
ok(scalar(@pl_1_1) == 1 && scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 2, 'Returns homebranch of items in biblio, that are pickup_locations'); |
438 |
|
439 |
#Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch' |
440 |
Koha::CirculationRules->set_rules( |
292 |
Koha::CirculationRules->set_rules( |
441 |
{ |
293 |
{ |
442 |
branchcode => undef, |
294 |
branchcode => $library6->branchcode, |
443 |
itemtype => undef, |
295 |
itemtype => undef, |
444 |
categorycode => undef, |
296 |
categorycode => undef, |
445 |
rules => { |
297 |
rules => { |
446 |
holdallowed => 1, |
298 |
holdallowed => 1, |
447 |
hold_fulfillment_policy => 'homebranch', |
299 |
hold_fulfillment_policy => 'holdgroup', |
448 |
returnbranch => 'any' |
300 |
returnbranch => 'any' |
449 |
} |
301 |
} |
450 |
} |
302 |
} |
451 |
); |
303 |
); |
452 |
|
304 |
|
453 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
|
|
454 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
455 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
456 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
457 |
|
458 |
ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_4) == 1 && $pl_1_1[0]->{branchcode} eq $library1->branchcode && $pl_2_4[0]->{branchcode} eq $library4->branchcode, 'Returns homebranch of items in biblio that equals patron\'s homebranch, and that are pickup_locations'); |
459 |
ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned'); |
460 |
|
461 |
#Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch |
462 |
Koha::CirculationRules->set_rules( |
305 |
Koha::CirculationRules->set_rules( |
463 |
{ |
306 |
{ |
464 |
branchcode => undef, |
307 |
branchcode => $library7->branchcode, |
465 |
itemtype => undef, |
308 |
itemtype => undef, |
466 |
categorycode => undef, |
309 |
categorycode => undef, |
467 |
rules => { |
310 |
rules => { |
468 |
holdallowed => 3, |
311 |
holdallowed => 3, |
469 |
hold_fulfillment_policy => 'homebranch', |
|
|
470 |
returnbranch => 'any' |
471 |
} |
472 |
} |
473 |
); |
474 |
|
475 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
476 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
477 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
478 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
479 |
|
480 |
ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_1) == 1 && scalar(@pl_2_4) == 1, 'Returns homebranch of items in biblio that are within patron\'s holdgroup, and that are pickup_locations'); |
481 |
ok(scalar(@pl_1_4) == 0, 'No pickup locations returned'); |
482 |
|
483 |
#Case 10: holdallowed any, hold_fulfillment_policy holdingbranch |
484 |
Koha::CirculationRules->set_rules( |
485 |
{ |
486 |
branchcode => undef, |
487 |
itemtype => undef, |
488 |
categorycode => undef, |
489 |
rules => { |
490 |
holdallowed => 2, |
491 |
hold_fulfillment_policy => 'holdingbranch', |
312 |
hold_fulfillment_policy => 'holdingbranch', |
492 |
returnbranch => 'any' |
313 |
returnbranch => 'any' |
493 |
} |
314 |
} |
494 |
} |
315 |
} |
495 |
); |
316 |
); |
496 |
|
317 |
|
497 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
|
|
498 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
499 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
500 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
501 |
|
502 |
ok(scalar(@pl_1_1) == 2 && scalar(@pl_1_4) == 2 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 2, 'Returns holdingbranch of items in biblio, that are pickup_locations'); |
503 |
|
318 |
|
504 |
#Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch' |
|
|
505 |
Koha::CirculationRules->set_rules( |
319 |
Koha::CirculationRules->set_rules( |
506 |
{ |
320 |
{ |
507 |
branchcode => undef, |
321 |
branchcode => $library8->branchcode, |
508 |
itemtype => undef, |
322 |
itemtype => undef, |
509 |
categorycode => undef, |
323 |
categorycode => undef, |
510 |
rules => { |
324 |
rules => { |
511 |
holdallowed => 1, |
325 |
holdallowed => 2, |
512 |
hold_fulfillment_policy => 'holdingbranch', |
326 |
hold_fulfillment_policy => 'patrongroup', |
513 |
returnbranch => 'any' |
327 |
returnbranch => 'any' |
514 |
} |
328 |
} |
515 |
} |
329 |
} |
516 |
); |
330 |
); |
517 |
|
331 |
|
518 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
332 |
my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } ); |
519 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
333 |
my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } ); |
520 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
|
|
521 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
522 |
|
334 |
|
523 |
ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_4) == 1, 'Returns holdingbranch of items in biblio, whose homebranch equals patron\'s, and that are pickup_locations'); |
335 |
my $group2_3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } ); |
524 |
ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned'); |
336 |
my $group2_4 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } ); |
525 |
|
337 |
|
526 |
#Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch |
338 |
my $group3_5 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library5->branchcode } } ); |
527 |
Koha::CirculationRules->set_rules( |
339 |
my $group3_6 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library6->branchcode } } ); |
528 |
{ |
340 |
my $group3_7 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library7->branchcode } } ); |
529 |
branchcode => undef, |
341 |
my $group3_8 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library8->branchcode } } ); |
530 |
itemtype => undef, |
|
|
531 |
categorycode => undef, |
532 |
rules => { |
533 |
holdallowed => 3, |
534 |
hold_fulfillment_policy => 'holdingbranch', |
535 |
returnbranch => 'any' |
536 |
} |
537 |
} |
538 |
); |
539 |
|
342 |
|
540 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
343 |
my $biblio1 = $builder->build_object( { class => 'Koha::Biblios', value => {title => '1'} } ); |
541 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
344 |
my $biblioitem1 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio1->biblionumber } } ); |
542 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
345 |
my $biblio2 = $builder->build_object( { class => 'Koha::Biblios', value => {title => '2'} } ); |
543 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
346 |
my $biblioitem2 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio2->biblionumber } } ); |
544 |
|
347 |
|
545 |
ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_4) == 1 && scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 1, 'Returns holdingbranch of items in biblio, whose homebranch are within patron\'s holdgroup, and that are pickup_locations'); |
348 |
my $item1_1 = Koha::Item->new({ |
|
|
349 |
biblionumber => $biblio1->biblionumber, |
350 |
biblioitemnumber => $biblioitem1->biblioitemnumber, |
351 |
homebranch => $library1->branchcode, |
352 |
holdingbranch => $library2->branchcode, |
353 |
itype => 'test', |
354 |
barcode => "item11barcode", |
355 |
})->store; |
546 |
|
356 |
|
547 |
t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch'); |
357 |
my $item1_3 = Koha::Item->new({ |
|
|
358 |
biblionumber => $biblio1->biblionumber, |
359 |
biblioitemnumber => $biblioitem1->biblioitemnumber, |
360 |
homebranch => $library3->branchcode, |
361 |
holdingbranch => $library4->branchcode, |
362 |
itype => 'test', |
363 |
barcode => "item13barcode", |
364 |
})->store; |
548 |
|
365 |
|
549 |
#Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch' |
366 |
my $item1_7 = Koha::Item->new({ |
550 |
Koha::CirculationRules->set_rules( |
367 |
biblionumber => $biblio1->biblionumber, |
551 |
{ |
368 |
biblioitemnumber => $biblioitem1->biblioitemnumber, |
552 |
branchcode => undef, |
369 |
homebranch => $library7->branchcode, |
553 |
itemtype => undef, |
370 |
holdingbranch => $library4->branchcode, |
554 |
categorycode => undef, |
371 |
itype => 'test', |
555 |
rules => { |
372 |
barcode => "item17barcode", |
556 |
holdallowed => 1, |
373 |
})->store; |
557 |
hold_fulfillment_policy => 'any', |
|
|
558 |
returnbranch => 'any' |
559 |
} |
560 |
} |
561 |
); |
562 |
|
374 |
|
563 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
375 |
my $item2_2 = Koha::Item->new({ |
564 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
376 |
biblionumber => $biblio2->biblionumber, |
565 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
377 |
biblioitemnumber => $biblioitem2->biblioitemnumber, |
566 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
378 |
homebranch => $library2->branchcode, |
|
|
379 |
holdingbranch => $library1->branchcode, |
380 |
itype => 'test', |
381 |
barcode => "item22barcode", |
382 |
})->store; |
567 |
|
383 |
|
568 |
ok(scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries when item\'s holdingbranch equals patron\'s homebranch, and that are pickup_locations'); |
384 |
my $item2_4 = Koha::Item->new({ |
569 |
ok(scalar(@pl_1_1) == 0, 'No pickup locations returned'); |
385 |
biblionumber => $biblio2->biblionumber, |
|
|
386 |
biblioitemnumber => $biblioitem2->biblioitemnumber, |
387 |
homebranch => $library4->branchcode, |
388 |
holdingbranch => $library3->branchcode, |
389 |
itype => 'test', |
390 |
barcode => "item23barcode", |
391 |
})->store; |
570 |
|
392 |
|
571 |
#Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch' |
393 |
my $item2_6 = Koha::Item->new({ |
572 |
Koha::CirculationRules->set_rules( |
394 |
biblionumber => $biblio2->biblionumber, |
573 |
{ |
395 |
biblioitemnumber => $biblioitem2->biblioitemnumber, |
574 |
branchcode => undef, |
396 |
homebranch => $library6->branchcode, |
575 |
itemtype => undef, |
397 |
holdingbranch => $library4->branchcode, |
576 |
categorycode => undef, |
398 |
itype => 'test', |
577 |
rules => { |
399 |
barcode => "item26barcode", |
578 |
holdallowed => 1, |
400 |
})->store; |
579 |
hold_fulfillment_policy => 'holdgroup', |
|
|
580 |
returnbranch => 'any' |
581 |
} |
582 |
} |
583 |
); |
584 |
|
401 |
|
585 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
402 |
my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'1', branchcode => $library1->branchcode } } ); |
586 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
403 |
my $patron8 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'8', branchcode => $library8->branchcode } } ); |
587 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
|
|
588 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
589 |
|
404 |
|
590 |
ok(scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 1, 'Returns libraries in item\'s holdgroup whose holdingbranch equals patron\'s homebranch, and that are pickup_locations'); |
405 |
my $results = { |
591 |
ok(scalar(@pl_1_1) == 0, 'No pickup locations returned'); |
406 |
"ItemHomeLibrary-1-1" => 6, |
|
|
407 |
"ItemHomeLibrary-1-8" => 1, |
408 |
"ItemHomeLibrary-2-1" => 2, |
409 |
"ItemHomeLibrary-2-8" => 0, |
410 |
"PatronLibrary-1-1" => 6, |
411 |
"PatronLibrary-1-8" => 3, |
412 |
"PatronLibrary-2-1" => 0, |
413 |
"PatronLibrary-2-8" => 3, |
414 |
}; |
592 |
|
415 |
|
593 |
#Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch' |
416 |
sub _doTest { |
594 |
Koha::CirculationRules->set_rules( |
417 |
my ( $cbranch, $biblio, $patron, $results ) = @_; |
595 |
{ |
418 |
t::lib::Mocks::mock_preference('ReservesControlBranch', $cbranch); |
596 |
branchcode => undef, |
|
|
597 |
itemtype => undef, |
598 |
categorycode => undef, |
599 |
rules => { |
600 |
holdallowed => 1, |
601 |
hold_fulfillment_policy => 'homebranch', |
602 |
returnbranch => 'any' |
603 |
} |
604 |
} |
605 |
); |
606 |
|
419 |
|
607 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
420 |
my @pl = $biblio->pickup_locations( { patron => $patron} ); |
608 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
|
|
609 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
610 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
611 |
|
421 |
|
612 |
#ok(scalar(@pl_2_4) == 1 && $pl_2_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 4 and item 3 renders item\'s holding branch'); |
422 |
ok(scalar(@pl) == $results->{$cbranch.'-'.$biblio->title.'-'.$patron->firstname}, 'ReservesControlBranch: '.$cbranch.', biblio'.$biblio->title.', patron'.$patron->firstname.' should return '.$results->{$cbranch.'-'.$biblio->title.'-'.$patron->firstname}.' but returns '.scalar(@pl)); |
613 |
ok(scalar(@pl_2_1) == 1 && scalar(@pl_2_4) == 1, 'Returns homebranch of items in biblio whose holdingbranch equals patron\'s homebranch, and that are pickup_locations'); |
423 |
} |
614 |
ok(scalar(@pl_1_1) == 0 && scalar(@pl_1_4) == 0, 'No pickup locations returned'); |
|
|
615 |
|
424 |
|
616 |
#Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch' |
425 |
foreach my $cbranch ('ItemHomeLibrary','PatronLibrary') { |
617 |
Koha::CirculationRules->set_rules( |
426 |
foreach my $biblio ($biblio1, $biblio2) { |
618 |
{ |
427 |
foreach my $patron ($patron1, $patron8) { |
619 |
branchcode => undef, |
428 |
_doTest($cbranch, $biblio, $patron, $results); |
620 |
itemtype => undef, |
|
|
621 |
categorycode => undef, |
622 |
rules => { |
623 |
holdallowed => 1, |
624 |
hold_fulfillment_policy => 'holdingbranch', |
625 |
returnbranch => 'any' |
626 |
} |
429 |
} |
627 |
} |
430 |
} |
628 |
); |
431 |
} |
629 |
|
|
|
630 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
631 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
632 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
633 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
634 |
|
635 |
ok(scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 1 && scalar(@pl_2_4) == 1, 'Returns holdingbranch of items in biblio that equals patron\'s homebranch, and that are pickup_locations'); |
636 |
ok(scalar(@pl_1_1) == 0, 'No pickup locations returned'); |
637 |
|
432 |
|
638 |
$schema->storage->txn_rollback; |
433 |
$schema->storage->txn_rollback; |
639 |
}; |
434 |
}; |