View | Details | Raw Unified | Return to bug 22284
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Biblios.t (-306 / +101 lines)
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
};
(-)a/t/db_dependent/Koha/Items.t (-358 / +95 lines)
Lines 169-175 is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted th Link Here
169
$schema->storage->txn_rollback;
169
$schema->storage->txn_rollback;
170
170
171
subtest 'pickup_locations' => sub {
171
subtest 'pickup_locations' => sub {
172
    plan tests => 33;
172
    plan tests => 60;
173
173
174
    $schema->storage->txn_begin;
174
    $schema->storage->txn_begin;
175
175
Lines 209-216 subtest 'pickup_locations' => sub { Link Here
209
        biblioitemnumber => $biblioitem->{biblioitemnumber},
209
        biblioitemnumber => $biblioitem->{biblioitemnumber},
210
        homebranch       => $library1->branchcode,
210
        homebranch       => $library1->branchcode,
211
        holdingbranch    => $library2->branchcode,
211
        holdingbranch    => $library2->branchcode,
212
        barcode          => '1',
212
        itype            => 'test',
213
        itype            => 'test',
213
        barcode          => "item1barcode",
214
    })->store;
214
    })->store;
215
215
216
    my $item3  = Koha::Item->new({
216
    my $item3  = Koha::Item->new({
Lines 218-588 subtest 'pickup_locations' => sub { Link Here
218
        biblioitemnumber => $biblioitem->{biblioitemnumber},
218
        biblioitemnumber => $biblioitem->{biblioitemnumber},
219
        homebranch       => $library3->branchcode,
219
        homebranch       => $library3->branchcode,
220
        holdingbranch    => $library4->branchcode,
220
        holdingbranch    => $library4->branchcode,
221
        barcode          => '3',
221
        itype            => 'test',
222
        itype            => 'test',
222
        barcode          => "item3barcode",
223
    })->store;
223
    })->store;
224
224
225
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode } } );
225
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode, firstname => '1' } } );
226
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode } } );
226
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } );
227
227
228
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
228
    my $results = {
229
229
        "1-1-1-any" => 3,
230
    #Case 1: holdallowed any, hold_fulfillment_policy any
230
        "1-1-1-holdgroup" => 2,
231
    Koha::CirculationRules->set_rules(
231
        "1-1-1-patrongroup" => 2,
232
        {
232
        "1-1-1-homebranch" => 1,
233
            branchcode => undef,
233
        "1-1-1-holdingbranch" => 1,
234
            itemtype   => undef,
234
        "1-1-2-any" => 3,
235
            categorycode => undef,
235
        "1-1-2-holdgroup" => 2,
236
            rules => {
236
        "1-1-2-patrongroup" => 2,
237
                holdallowed => 2,
237
        "1-1-2-homebranch" => 1,
238
                hold_fulfillment_policy => 'any',
238
        "1-1-2-holdingbranch" => 1,
239
                returnbranch => 'any'
239
        "1-1-3-any" => 3,
240
        "1-1-3-holdgroup" => 2,
241
        "1-1-3-patrongroup" => 2,
242
        "1-1-3-homebranch" => 1,
243
        "1-1-3-holdingbranch" => 1,
244
        "1-4-1-any" => 0,
245
        "1-4-1-holdgroup" => 0,
246
        "1-4-1-patrongroup" => 0,
247
        "1-4-1-homebranch" => 0,
248
        "1-4-1-holdingbranch" => 0,
249
        "1-4-2-any" => 3,
250
        "1-4-2-holdgroup" => 2,
251
        "1-4-2-patrongroup" => 1,
252
        "1-4-2-homebranch" => 1,
253
        "1-4-2-holdingbranch" => 1,
254
        "1-4-3-any" => 0,
255
        "1-4-3-holdgroup" => 0,
256
        "1-4-3-patrongroup" => 0,
257
        "1-4-3-homebranch" => 0,
258
        "1-4-3-holdingbranch" => 0,
259
        "3-1-1-any" => 0,
260
        "3-1-1-holdgroup" => 0,
261
        "3-1-1-patrongroup" => 0,
262
        "3-1-1-homebranch" => 0,
263
        "3-1-1-holdingbranch" => 0,
264
        "3-1-2-any" => 3,
265
        "3-1-2-holdgroup" => 1,
266
        "3-1-2-patrongroup" => 2,
267
        "3-1-2-homebranch" => 0,
268
        "3-1-2-holdingbranch" => 1,
269
        "3-1-3-any" => 0,
270
        "3-1-3-holdgroup" => 0,
271
        "3-1-3-patrongroup" => 0,
272
        "3-1-3-homebranch" => 0,
273
        "3-1-3-holdingbranch" => 0,
274
        "3-4-1-any" => 0,
275
        "3-4-1-holdgroup" => 0,
276
        "3-4-1-patrongroup" => 0,
277
        "3-4-1-homebranch" => 0,
278
        "3-4-1-holdingbranch" => 0,
279
        "3-4-2-any" => 3,
280
        "3-4-2-holdgroup" => 1,
281
        "3-4-2-patrongroup" => 1,
282
        "3-4-2-homebranch" => 0,
283
        "3-4-2-holdingbranch" => 1,
284
        "3-4-3-any" => 3,
285
        "3-4-3-holdgroup" => 1,
286
        "3-4-3-patrongroup" => 1,
287
        "3-4-3-homebranch" => 0,
288
        "3-4-3-holdingbranch" => 1
289
    };
290
291
    sub _doTest {
292
        my ( $item, $patron, $ha, $hfp, $results ) = @_;
293
294
        Koha::CirculationRules->set_rules(
295
            {
296
                branchcode => undef,
297
                itemtype   => undef,
298
                categorycode => undef,
299
                rules => {
300
                    holdallowed => $ha,
301
                    hold_fulfillment_policy => $hfp,
302
                    returnbranch => 'any'
303
                }
240
            }
304
            }
241
        }
305
        );
242
    );
306
        my @pl = $item->pickup_locations( { patron => $patron} );
243
307
        my $ha_value=$ha==3?'holdgroup':($ha==2?'any':'homebranch');
244
    my @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
245
    my @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
246
    my @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
247
    my @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
248
249
    ok(scalar(@pl_1_1) == scalar(@pl_1_4) && scalar(@pl_1_1) == scalar(@pl_3_1) && scalar(@pl_1_1) == scalar(@pl_3_4), 'All combinations of patron/item renders the same number of locations');
250
251
    #Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch'
252
    Koha::CirculationRules->set_rules(
253
        {
254
            branchcode => undef,
255
            itemtype   => undef,
256
            categorycode => undef,
257
            rules => {
258
                holdallowed => 1,
259
                hold_fulfillment_policy => 'any',
260
                returnbranch => 'any'
261
            }
262
        }
263
    );
264
265
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
266
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
267
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
268
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
269
270
    ok(scalar(@pl_1_1) == 3, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
271
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
272
273
    #Case 3: holdallowed holdgroup, hold_fulfillment_policy any
274
    Koha::CirculationRules->set_rules(
275
        {
276
            branchcode => undef,
277
            itemtype   => undef,
278
            categorycode => undef,
279
            rules => {
280
                holdallowed => 3,
281
                hold_fulfillment_policy => 'any',
282
                returnbranch => 'any'
283
            }
284
        }
285
    );
286
287
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
288
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
289
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
290
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
291
292
    ok(scalar(@pl_1_1) == 3, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
293
    ok(scalar(@pl_3_4) == 3, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
294
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
295
296
    #Case 4: holdallowed any, hold_fulfillment_policy holdgroup
297
    Koha::CirculationRules->set_rules(
298
        {
299
            branchcode => undef,
300
            itemtype   => undef,
301
            categorycode => undef,
302
            rules => {
303
                holdallowed => 2,
304
                hold_fulfillment_policy => 'holdgroup',
305
                returnbranch => 'any'
306
            }
307
        }
308
    );
309
308
310
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
309
        ok(scalar(@pl) == $results->{$item->barcode.'-'.$patron->firstname.'-'.$ha.'-'.$hfp}, 'item'.$item->barcode.', patron'.$patron->firstname.', holdallowed: '.$ha_value.', hold_fulfillment_policy: '.$hfp.' should return '.$results->{$item->barcode.'-'.$patron->firstname.'-'.$ha.'-'.$hfp}.' but returns '.scalar(@pl));
311
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
310
    }
312
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
313
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
314
315
    ok(scalar(@pl_1_1) == 2 && scalar(@pl_1_4) == 2, 'Pickup locations for item 1 renders all libraries in items\'s holdgroup that are pickup_locations');
316
    ok(scalar(@pl_3_1) == 1 && scalar(@pl_3_4) == 1, 'Pickup locations for item 3 renders all libraries in items\'s holdgroup that are pickup_locations');
317
318
    #Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch'
319
    Koha::CirculationRules->set_rules(
320
        {
321
            branchcode => undef,
322
            itemtype   => undef,
323
            categorycode => undef,
324
            rules => {
325
                holdallowed => 1,
326
                hold_fulfillment_policy => 'holdgroup',
327
                returnbranch => 'any'
328
            }
329
        }
330
    );
331
332
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
333
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
334
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
335
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
336
337
    ok(scalar(@pl_1_1) == 2, 'Pickup location for patron 1 and item 1 renders all libraries in holdgroup that are pickup_locations');
338
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
339
340
    #Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup
341
    Koha::CirculationRules->set_rules(
342
        {
343
            branchcode => undef,
344
            itemtype   => undef,
345
            categorycode => undef,
346
            rules => {
347
                holdallowed => 3,
348
                hold_fulfillment_policy => 'holdgroup',
349
                returnbranch => 'any'
350
            }
351
        }
352
    );
353
354
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
355
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
356
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
357
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
358
359
    ok(scalar(@pl_1_1) == 2, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
360
    ok(scalar(@pl_3_4) == 1, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
361
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
362
363
    #Case 7: holdallowed any, hold_fulfillment_policy homebranch
364
    Koha::CirculationRules->set_rules(
365
        {
366
            branchcode => undef,
367
            itemtype   => undef,
368
            categorycode => undef,
369
            rules => {
370
                holdallowed => 2,
371
                hold_fulfillment_policy => 'homebranch',
372
                returnbranch => 'any'
373
            }
374
        }
375
    );
376
377
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
378
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
379
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
380
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
381
382
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_1_4) == 1 && $pl_1_1[0]->{branchcode} eq $library1->branchcode && $pl_1_4[0]->{branchcode} eq $library1->id, 'Pickup locations for item 1 renders item\'s homelibrary');
383
    ok(scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations, because library3 is not pickup_location');
384
385
    #Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch'
386
    Koha::CirculationRules->set_rules(
387
        {
388
            branchcode => undef,
389
            itemtype   => undef,
390
            categorycode => undef,
391
            rules => {
392
                holdallowed => 1,
393
                hold_fulfillment_policy => 'homebranch',
394
                returnbranch => 'any'
395
            }
396
        }
397
    );
398
399
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
400
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
401
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
402
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
403
404
    ok(scalar(@pl_1_1) == 1 && $pl_1_1[0]->{branchcode} eq $library1->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s homebranch');
405
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
406
407
    #Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch
408
    Koha::CirculationRules->set_rules(
409
        {
410
            branchcode => undef,
411
            itemtype   => undef,
412
            categorycode => undef,
413
            rules => {
414
                holdallowed => 3,
415
                hold_fulfillment_policy => 'homebranch',
416
                returnbranch => 'any'
417
            }
418
        }
419
    );
420
421
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
422
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
423
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
424
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
425
426
    ok(scalar(@pl_1_1) == 1, 'Pickup location for patron 1 and item 1 renders item\'s homebranch');
427
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
428
429
    #Case 10: holdallowed any, hold_fulfillment_policy holdingbranch
430
    Koha::CirculationRules->set_rules(
431
        {
432
            branchcode => undef,
433
            itemtype   => undef,
434
            categorycode => undef,
435
            rules => {
436
                holdallowed => 2,
437
                hold_fulfillment_policy => 'holdingbranch',
438
                returnbranch => 'any'
439
            }
440
        }
441
    );
442
443
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
444
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
445
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
446
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
447
448
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_1_4) == 1 && $pl_1_1[0]->{branchcode} eq $library2->branchcode && $pl_1_4[0]->{branchcode} eq $library2->branchcode, 'Pickup locations for item 1 renders item\'s holding branch');
449
    ok(scalar(@pl_3_1) == 1 && scalar(@pl_3_4) == 1 && $pl_3_1[0]->{branchcode} eq $library4->branchcode && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup locations for item 3 renders item\'s holding branch');
450
451
452
    #Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch'
453
    Koha::CirculationRules->set_rules(
454
        {
455
            branchcode => undef,
456
            itemtype   => undef,
457
            categorycode => undef,
458
            rules => {
459
                holdallowed => 1,
460
                hold_fulfillment_policy => 'holdingbranch',
461
                returnbranch => 'any'
462
            }
463
        }
464
    );
465
466
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
467
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
468
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
469
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
470
471
    ok(scalar(@pl_1_1) == 1 && $pl_1_1[0]->{branchcode} eq $library2->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s holding branch');
472
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
473
474
    #Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch
475
    Koha::CirculationRules->set_rules(
476
        {
477
            branchcode => undef,
478
            itemtype   => undef,
479
            categorycode => undef,
480
            rules => {
481
                holdallowed => 3,
482
                hold_fulfillment_policy => 'holdingbranch',
483
                returnbranch => 'any'
484
            }
485
        }
486
    );
487
488
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
489
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
490
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
491
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
492
493
    ok(scalar(@pl_1_1) == 1 && $pl_1_1[0]->{branchcode} eq $library2->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s holding branch');
494
    ok(scalar(@pl_3_4) == 1 && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 4 and item 3 renders item\'s holding branch');
495
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
496
497
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch');
498
499
    #Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch'
500
    Koha::CirculationRules->set_rules(
501
        {
502
            branchcode => undef,
503
            itemtype   => undef,
504
            categorycode => undef,
505
            rules => {
506
                holdallowed => 1,
507
                hold_fulfillment_policy => 'any',
508
                returnbranch => 'any'
509
            }
510
        }
511
    );
512
311
513
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
514
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
515
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
516
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
517
518
    ok(scalar(@pl_3_4) == 3, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
519
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
520
521
    #Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch'
522
    Koha::CirculationRules->set_rules(
523
        {
524
            branchcode => undef,
525
            itemtype   => undef,
526
            categorycode => undef,
527
            rules => {
528
                holdallowed => 1,
529
                hold_fulfillment_policy => 'holdgroup',
530
                returnbranch => 'any'
531
            }
532
        }
533
    );
534
312
535
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
313
    foreach my $item ($item1, $item3) {
536
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
314
        foreach my $patron ($patron1, $patron4) {
537
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
315
            #holdallowed 1: homebranch, 2: any, 3: holdgroup
538
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
316
            foreach my $ha (1, 2, 3) {
539
317
                foreach my $hfp ('any', 'holdgroup', 'patrongroup', 'homebranch', 'holdingbranch') {
540
    ok(scalar(@pl_3_4) == 1, 'Pickup location for patron 4 and item 3 renders all libraries in holdgroup that are pickup_locations');
318
                    _doTest($item, $patron, $ha, $hfp, $results);
541
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
319
                }
542
543
    #Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch'
544
    Koha::CirculationRules->set_rules(
545
        {
546
            branchcode => undef,
547
            itemtype   => undef,
548
            categorycode => undef,
549
            rules => {
550
                holdallowed => 1,
551
                hold_fulfillment_policy => 'homebranch',
552
                returnbranch => 'any'
553
            }
320
            }
554
        }
321
        }
555
    );
322
    }
556
557
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
558
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
559
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
560
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
561
562
    #ok(scalar(@pl_3_4) == 1 && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 4 and item 3 renders item\'s holding branch');
563
    ok(scalar(@pl_3_4) == 0 && scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any combination of patron/item renders no locations');
564
565
    #Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch'
566
    Koha::CirculationRules->set_rules(
567
        {
568
            branchcode => undef,
569
            itemtype   => undef,
570
            categorycode => undef,
571
            rules => {
572
                holdallowed => 1,
573
                hold_fulfillment_policy => 'holdingbranch',
574
                returnbranch => 'any'
575
            }
576
        }
577
    );
578
579
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
580
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
581
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
582
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
583
584
    ok(scalar(@pl_3_4) == 1 && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s holding branch');
585
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
586
323
587
    $schema->storage->txn_rollback;
324
    $schema->storage->txn_rollback;
588
};
325
};
(-)a/t/db_dependent/Koha/Libraries.t (-22 / +36 lines)
Lines 31-36 use Koha::Items; Link Here
31
use Koha::Library;
31
use Koha::Library;
32
use Koha::Libraries;
32
use Koha::Libraries;
33
use Koha::Database;
33
use Koha::Database;
34
use Koha::CirculationRules;
34
35
35
use t::lib::Mocks;
36
use t::lib::Mocks;
36
use t::lib::TestBuilder;
37
use t::lib::TestBuilder;
Lines 90-95 isa_ok( $srstages->next, 'Koha::StockRotationStage', "Relationship correctly cre Link Here
90
subtest 'pickup_locations' => sub {
91
subtest 'pickup_locations' => sub {
91
    plan tests => 2;
92
    plan tests => 2;
92
93
94
    Koha::CirculationRules->set_rules(
95
        {
96
            branchcode => undef,
97
            itemtype   => undef,
98
            categorycode => undef,
99
            rules => {
100
                holdallowed => 2,
101
                hold_fulfillment_policy => 'any',
102
                returnbranch => 'any'
103
            }
104
        }
105
    );
106
93
    my $from = Koha::Library->new({
107
    my $from = Koha::Library->new({
94
        branchcode => 'zzzfrom',
108
        branchcode => 'zzzfrom',
95
        branchname => 'zzzfrom',
109
        branchname => 'zzzfrom',
Lines 117-122 subtest 'pickup_locations' => sub { Link Here
117
    my $item3 = Koha::Items->find($itemnumber3);
131
    my $item3 = Koha::Items->find($itemnumber3);
118
    my $biblio = Koha::Biblios->find($bibnum);
132
    my $biblio = Koha::Biblios->find($bibnum);
119
    my $itemtype = $biblio->itemtype;
133
    my $itemtype = $biblio->itemtype;
134
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $from->branchcode } } );
120
135
121
    subtest 'UseBranchTransferLimits = OFF' => sub {
136
    subtest 'UseBranchTransferLimits = OFF' => sub {
122
        plan tests => 5;
137
        plan tests => 5;
Lines 133-139 subtest 'pickup_locations' => sub { Link Here
133
        my $total_pickup = Koha::Libraries->search({
148
        my $total_pickup = Koha::Libraries->search({
134
            pickup_location => 1
149
            pickup_location => 1
135
        })->count;
150
        })->count;
136
        my $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum });
151
        my $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum, patron => $patron1 });
137
        is(C4::Context->preference('UseBranchTransferLimits'), 0, 'Given system '
152
        is(C4::Context->preference('UseBranchTransferLimits'), 0, 'Given system '
138
           .'preference UseBranchTransferLimits is switched OFF,');
153
           .'preference UseBranchTransferLimits is switched OFF,');
139
        is(@{$pickup}, $total_pickup, 'Then the total number of pickup locations '
154
        is(@{$pickup}, $total_pickup, 'Then the total number of pickup locations '
Lines 141-155 subtest 'pickup_locations' => sub { Link Here
141
156
142
        t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
157
        t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
143
        t::lib::Mocks::mock_preference('item-level_itypes', 1);
158
        t::lib::Mocks::mock_preference('item-level_itypes', 1);
144
        $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum });
159
        $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum, patron => $patron1 });
145
        is(@{$pickup}, $total_pickup, '...when '
160
        is(@{$pickup}, $total_pickup, '...when '
146
           .'BranchTransferLimitsType = itemtype and item-level_itypes = 1');
161
           .'BranchTransferLimitsType = itemtype and item-level_itypes = 1');
147
        t::lib::Mocks::mock_preference('item-level_itypes', 0);
162
        t::lib::Mocks::mock_preference('item-level_itypes', 0);
148
        $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum });
163
        $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum, patron => $patron1 });
149
        is(@{$pickup}, $total_pickup, '...as well as when '
164
        is(@{$pickup}, $total_pickup, '...as well as when '
150
           .'BranchTransferLimitsType = itemtype and item-level_itypes = 0');
165
           .'BranchTransferLimitsType = itemtype and item-level_itypes = 0');
151
        t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
166
        t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
152
        $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum });
167
        $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum, patron => $patron1 });
153
        is(@{$pickup}, $total_pickup, '...as well as when '
168
        is(@{$pickup}, $total_pickup, '...as well as when '
154
           .'BranchTransferLimitsType = ccode');
169
           .'BranchTransferLimitsType = ccode');
155
        t::lib::Mocks::mock_preference('item-level_itypes', 1);
170
        t::lib::Mocks::mock_preference('item-level_itypes', 1);
Lines 179-185 subtest 'pickup_locations' => sub { Link Here
179
               'Given all items of a biblio have same the itemtype,');
194
               'Given all items of a biblio have same the itemtype,');
180
            is($limit->itemtype, $item1->effective_itemtype, 'and given there '
195
            is($limit->itemtype, $item1->effective_itemtype, 'and given there '
181
               .'is an existing transfer limit for that itemtype,');
196
               .'is an existing transfer limit for that itemtype,');
182
            my $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum });
197
            my $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum, patron => $patron1 });
183
            my $found = 0;
198
            my $found = 0;
184
            foreach my $lib (@{$pickup}) {
199
            foreach my $lib (@{$pickup}) {
185
                if ($lib->{'branchcode'} eq $limit->toBranch) {
200
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 188-194 subtest 'pickup_locations' => sub { Link Here
188
            }
203
            }
189
            is($found, 0, 'Then the to-library of which the limit applies for, '
204
            is($found, 0, 'Then the to-library of which the limit applies for, '
190
               .'is not included in the list of pickup libraries.');
205
               .'is not included in the list of pickup libraries.');
191
            $pickup = Koha::Libraries->pickup_locations({ item => $item1 });
206
            $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
192
            $found = 0;
207
            $found = 0;
193
            foreach my $lib (@{$pickup}) {
208
            foreach my $lib (@{$pickup}) {
194
                if ($lib->{'branchcode'} eq $limit->toBranch) {
209
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 208-214 subtest 'pickup_locations' => sub { Link Here
208
            is(Koha::Item::Transfer::Limits->search({
223
            is(Koha::Item::Transfer::Limits->search({
209
                itemtype => $item2->effective_itemtype })->count, 0, 'and it is'
224
                itemtype => $item2->effective_itemtype })->count, 0, 'and it is'
210
               .' not restricted by transfer limits,');
225
               .' not restricted by transfer limits,');
211
            $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum });
226
            $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum, patron => $patron1 });
212
            $found = 0;
227
            $found = 0;
213
            foreach my $lib (@{$pickup}) {
228
            foreach my $lib (@{$pickup}) {
214
                if ($lib->{'branchcode'} eq $limit->toBranch) {
229
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 217-223 subtest 'pickup_locations' => sub { Link Here
217
            }
232
            }
218
            is($found, 1, 'Then the to-library of which the limit applies for, '
233
            is($found, 1, 'Then the to-library of which the limit applies for, '
219
               .'is included in the list of pickup libraries.');
234
               .'is included in the list of pickup libraries.');
220
            $pickup = Koha::Libraries->pickup_locations({ item => $item2 });
235
            $pickup = Koha::Libraries->pickup_locations({ item => $item2, patron => $patron1 });
221
            $found = 0;
236
            $found = 0;
222
            foreach my $lib (@{$pickup}) {
237
            foreach my $lib (@{$pickup}) {
223
                if ($lib->{'branchcode'} eq $limit->toBranch) {
238
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 227-233 subtest 'pickup_locations' => sub { Link Here
227
            is($found, 1, 'The same applies when asking pickup locations of '
242
            is($found, 1, 'The same applies when asking pickup locations of '
228
               .'a that particular item.');
243
               .'a that particular item.');
229
            Koha::Item::Transfer::Limits->delete;
244
            Koha::Item::Transfer::Limits->delete;
230
            $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum });
245
            $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum, patron => $patron1 });
231
            $found = 0;
246
            $found = 0;
232
            foreach my $lib (@{$pickup}) {
247
            foreach my $lib (@{$pickup}) {
233
                if ($lib->{'branchcode'} eq $limit->toBranch) {
248
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 236-242 subtest 'pickup_locations' => sub { Link Here
236
            }
251
            }
237
            is($found, 1, 'Given we deleted transfer limit, the previously '
252
            is($found, 1, 'Given we deleted transfer limit, the previously '
238
               .'transfer-limited library is included in the list.');
253
               .'transfer-limited library is included in the list.');
239
            $pickup = Koha::Libraries->pickup_locations({ item => $item1 });
254
            $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
240
            $found = 0;
255
            $found = 0;
241
            foreach my $lib (@{$pickup}) {
256
            foreach my $lib (@{$pickup}) {
242
                if ($lib->{'branchcode'} eq $limit->toBranch) {
257
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 265-271 subtest 'pickup_locations' => sub { Link Here
265
               'Given items use biblio-level itemtype,');
280
               'Given items use biblio-level itemtype,');
266
            is($limit->itemtype, $item1->effective_itemtype, 'and given there '
281
            is($limit->itemtype, $item1->effective_itemtype, 'and given there '
267
               .'is an existing transfer limit for that itemtype,');
282
               .'is an existing transfer limit for that itemtype,');
268
            my $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum });
283
            my $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum, patron => $patron1 });
269
            my $found = 0;
284
            my $found = 0;
270
            foreach my $lib (@{$pickup}) {
285
            foreach my $lib (@{$pickup}) {
271
                if ($lib->{'branchcode'} eq $limit->toBranch) {
286
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 274-280 subtest 'pickup_locations' => sub { Link Here
274
            }
289
            }
275
            is($found, 0, 'Then the to-library of which the limit applies for, '
290
            is($found, 0, 'Then the to-library of which the limit applies for, '
276
               .'is not included in the list of pickup libraries.');
291
               .'is not included in the list of pickup libraries.');
277
            $pickup = Koha::Libraries->pickup_locations({ item => $item1 });
292
            $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
278
            $found = 0;
293
            $found = 0;
279
            foreach my $lib (@{$pickup}) {
294
            foreach my $lib (@{$pickup}) {
280
                if ($lib->{'branchcode'} eq $limit->toBranch) {
295
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 289-295 subtest 'pickup_locations' => sub { Link Here
289
            is(@{$pickup}, $others, 'However, the number of other pickup '
304
            is(@{$pickup}, $others, 'However, the number of other pickup '
290
               .'libraries is correct.');
305
               .'libraries is correct.');
291
            Koha::Item::Transfer::Limits->delete;
306
            Koha::Item::Transfer::Limits->delete;
292
            $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum });
307
            $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum, patron => $patron1 });
293
            $found = 0;
308
            $found = 0;
294
            foreach my $lib (@{$pickup}) {
309
            foreach my $lib (@{$pickup}) {
295
                if ($lib->{'branchcode'} eq $limit->toBranch) {
310
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 306-312 subtest 'pickup_locations' => sub { Link Here
306
            ok($item1->itype ne $item1->effective_itemtype
321
            ok($item1->itype ne $item1->effective_itemtype
307
               && $limit->itemtype eq $item1->itype, 'Given we have added a limit'
322
               && $limit->itemtype eq $item1->itype, 'Given we have added a limit'
308
               .' matching ITEM-level itemtype,');
323
               .' matching ITEM-level itemtype,');
309
            $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum });
324
            $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum, patron => $patron1 });
310
            $found = 0;
325
            $found = 0;
311
            foreach my $lib (@{$pickup}) {
326
            foreach my $lib (@{$pickup}) {
312
                if ($lib->{'branchcode'} eq $limit->toBranch) {
327
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 315-321 subtest 'pickup_locations' => sub { Link Here
315
            }
330
            }
316
            is($found, 1, 'Then the limited branch is still included as a pickup'
331
            is($found, 1, 'Then the limited branch is still included as a pickup'
317
               .' library.');
332
               .' library.');
318
            $pickup = Koha::Libraries->pickup_locations({ item => $item1 });
333
            $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
319
            $found = 0;
334
            $found = 0;
320
            foreach my $lib (@{$pickup}) {
335
            foreach my $lib (@{$pickup}) {
321
                if ($lib->{'branchcode'} eq $limit->toBranch) {
336
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 342-348 subtest 'pickup_locations' => sub { Link Here
342
357
343
            is($limit->ccode, $item1->ccode, 'Given there '
358
            is($limit->ccode, $item1->ccode, 'Given there '
344
               .'is an existing transfer limit for that ccode,');
359
               .'is an existing transfer limit for that ccode,');
345
            my $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum });
360
            my $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum, patron => $patron1 });
346
            my $found = 0;
361
            my $found = 0;
347
            foreach my $lib (@{$pickup}) {
362
            foreach my $lib (@{$pickup}) {
348
                if ($lib->{'branchcode'} eq $limit->toBranch) {
363
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 351-357 subtest 'pickup_locations' => sub { Link Here
351
            }
366
            }
352
            is($found, 0, 'Then the to-library of which the limit applies for, '
367
            is($found, 0, 'Then the to-library of which the limit applies for, '
353
               .'is not included in the list of pickup libraries.');
368
               .'is not included in the list of pickup libraries.');
354
            $pickup = Koha::Libraries->pickup_locations({ item => $item1 });
369
            $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
355
            $found = 0;
370
            $found = 0;
356
            foreach my $lib (@{$pickup}) {
371
            foreach my $lib (@{$pickup}) {
357
                if ($lib->{'branchcode'} eq $limit->toBranch) {
372
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 371-377 subtest 'pickup_locations' => sub { Link Here
371
            is(Koha::Item::Transfer::Limits->search({
386
            is(Koha::Item::Transfer::Limits->search({
372
                ccode => $item3->ccode })->count, 0, 'and it is'
387
                ccode => $item3->ccode })->count, 0, 'and it is'
373
               .' not restricted by transfer limits,');
388
               .' not restricted by transfer limits,');
374
            $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum });
389
            $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum, patron => $patron1 });
375
            $found = 0;
390
            $found = 0;
376
            foreach my $lib (@{$pickup}) {
391
            foreach my $lib (@{$pickup}) {
377
                if ($lib->{'branchcode'} eq $limit->toBranch) {
392
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 380-386 subtest 'pickup_locations' => sub { Link Here
380
            }
395
            }
381
            is($found, 1, 'Then the to-library of which the limit applies for, '
396
            is($found, 1, 'Then the to-library of which the limit applies for, '
382
               .'is included in the list of pickup libraries.');
397
               .'is included in the list of pickup libraries.');
383
            $pickup = Koha::Libraries->pickup_locations({ item => $item3 });
398
            $pickup = Koha::Libraries->pickup_locations({ item => $item3, patron => $patron1 });
384
            $found = 0;
399
            $found = 0;
385
            foreach my $lib (@{$pickup}) {
400
            foreach my $lib (@{$pickup}) {
386
                if ($lib->{'branchcode'} eq $limit->toBranch) {
401
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 390-396 subtest 'pickup_locations' => sub { Link Here
390
            is($found, 1, 'The same applies when asking pickup locations of '
405
            is($found, 1, 'The same applies when asking pickup locations of '
391
               .'a that particular item.');
406
               .'a that particular item.');
392
            Koha::Item::Transfer::Limits->delete;
407
            Koha::Item::Transfer::Limits->delete;
393
            $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum });
408
            $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum, patron => $patron1 });
394
            $found = 0;
409
            $found = 0;
395
            foreach my $lib (@{$pickup}) {
410
            foreach my $lib (@{$pickup}) {
396
                if ($lib->{'branchcode'} eq $limit->toBranch) {
411
                if ($lib->{'branchcode'} eq $limit->toBranch) {
Lines 399-405 subtest 'pickup_locations' => sub { Link Here
399
            }
414
            }
400
            is($found, 1, 'Given we deleted transfer limit, the previously '
415
            is($found, 1, 'Given we deleted transfer limit, the previously '
401
               .'transfer-limited library is included in the list.');
416
               .'transfer-limited library is included in the list.');
402
            $pickup = Koha::Libraries->pickup_locations({ item => $item1 });
417
            $pickup = Koha::Libraries->pickup_locations({ item => $item1, patron => $patron1 });
403
            $found = 0;
418
            $found = 0;
404
            foreach my $lib (@{$pickup}) {
419
            foreach my $lib (@{$pickup}) {
405
                if ($lib->{'branchcode'} eq $limit->toBranch) {
420
                if ($lib->{'branchcode'} eq $limit->toBranch) {
406
- 

Return to bug 22284