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 188-194 is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted th Link Here
188
$schema->storage->txn_rollback;
188
$schema->storage->txn_rollback;
189
189
190
subtest 'pickup_locations' => sub {
190
subtest 'pickup_locations' => sub {
191
    plan tests => 33;
191
    plan tests => 60;
192
192
193
    $schema->storage->txn_begin;
193
    $schema->storage->txn_begin;
194
194
Lines 228-235 subtest 'pickup_locations' => sub { Link Here
228
        biblioitemnumber => $biblioitem->{biblioitemnumber},
228
        biblioitemnumber => $biblioitem->{biblioitemnumber},
229
        homebranch       => $library1->branchcode,
229
        homebranch       => $library1->branchcode,
230
        holdingbranch    => $library2->branchcode,
230
        holdingbranch    => $library2->branchcode,
231
        barcode          => '1',
231
        itype            => 'test',
232
        itype            => 'test',
232
        barcode          => "item1barcode",
233
    })->store;
233
    })->store;
234
234
235
    my $item3  = Koha::Item->new({
235
    my $item3  = Koha::Item->new({
Lines 237-607 subtest 'pickup_locations' => sub { Link Here
237
        biblioitemnumber => $biblioitem->{biblioitemnumber},
237
        biblioitemnumber => $biblioitem->{biblioitemnumber},
238
        homebranch       => $library3->branchcode,
238
        homebranch       => $library3->branchcode,
239
        holdingbranch    => $library4->branchcode,
239
        holdingbranch    => $library4->branchcode,
240
        barcode          => '3',
240
        itype            => 'test',
241
        itype            => 'test',
241
        barcode          => "item3barcode",
242
    })->store;
242
    })->store;
243
243
244
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode } } );
244
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode, firstname => '1' } } );
245
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode } } );
245
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } );
246
246
247
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
247
    my $results = {
248
248
        "1-1-1-any" => 3,
249
    #Case 1: holdallowed any, hold_fulfillment_policy any
249
        "1-1-1-holdgroup" => 2,
250
    Koha::CirculationRules->set_rules(
250
        "1-1-1-patrongroup" => 2,
251
        {
251
        "1-1-1-homebranch" => 1,
252
            branchcode => undef,
252
        "1-1-1-holdingbranch" => 1,
253
            itemtype   => undef,
253
        "1-1-2-any" => 3,
254
            categorycode => undef,
254
        "1-1-2-holdgroup" => 2,
255
            rules => {
255
        "1-1-2-patrongroup" => 2,
256
                holdallowed => 2,
256
        "1-1-2-homebranch" => 1,
257
                hold_fulfillment_policy => 'any',
257
        "1-1-2-holdingbranch" => 1,
258
                returnbranch => 'any'
258
        "1-1-3-any" => 3,
259
        "1-1-3-holdgroup" => 2,
260
        "1-1-3-patrongroup" => 2,
261
        "1-1-3-homebranch" => 1,
262
        "1-1-3-holdingbranch" => 1,
263
        "1-4-1-any" => 0,
264
        "1-4-1-holdgroup" => 0,
265
        "1-4-1-patrongroup" => 0,
266
        "1-4-1-homebranch" => 0,
267
        "1-4-1-holdingbranch" => 0,
268
        "1-4-2-any" => 3,
269
        "1-4-2-holdgroup" => 2,
270
        "1-4-2-patrongroup" => 1,
271
        "1-4-2-homebranch" => 1,
272
        "1-4-2-holdingbranch" => 1,
273
        "1-4-3-any" => 0,
274
        "1-4-3-holdgroup" => 0,
275
        "1-4-3-patrongroup" => 0,
276
        "1-4-3-homebranch" => 0,
277
        "1-4-3-holdingbranch" => 0,
278
        "3-1-1-any" => 0,
279
        "3-1-1-holdgroup" => 0,
280
        "3-1-1-patrongroup" => 0,
281
        "3-1-1-homebranch" => 0,
282
        "3-1-1-holdingbranch" => 0,
283
        "3-1-2-any" => 3,
284
        "3-1-2-holdgroup" => 1,
285
        "3-1-2-patrongroup" => 2,
286
        "3-1-2-homebranch" => 0,
287
        "3-1-2-holdingbranch" => 1,
288
        "3-1-3-any" => 0,
289
        "3-1-3-holdgroup" => 0,
290
        "3-1-3-patrongroup" => 0,
291
        "3-1-3-homebranch" => 0,
292
        "3-1-3-holdingbranch" => 0,
293
        "3-4-1-any" => 0,
294
        "3-4-1-holdgroup" => 0,
295
        "3-4-1-patrongroup" => 0,
296
        "3-4-1-homebranch" => 0,
297
        "3-4-1-holdingbranch" => 0,
298
        "3-4-2-any" => 3,
299
        "3-4-2-holdgroup" => 1,
300
        "3-4-2-patrongroup" => 1,
301
        "3-4-2-homebranch" => 0,
302
        "3-4-2-holdingbranch" => 1,
303
        "3-4-3-any" => 3,
304
        "3-4-3-holdgroup" => 1,
305
        "3-4-3-patrongroup" => 1,
306
        "3-4-3-homebranch" => 0,
307
        "3-4-3-holdingbranch" => 1
308
    };
309
310
    sub _doTest {
311
        my ( $item, $patron, $ha, $hfp, $results ) = @_;
312
313
        Koha::CirculationRules->set_rules(
314
            {
315
                branchcode => undef,
316
                itemtype   => undef,
317
                categorycode => undef,
318
                rules => {
319
                    holdallowed => $ha,
320
                    hold_fulfillment_policy => $hfp,
321
                    returnbranch => 'any'
322
                }
259
            }
323
            }
260
        }
324
        );
261
    );
325
        my @pl = $item->pickup_locations( { patron => $patron} );
262
326
        my $ha_value=$ha==3?'holdgroup':($ha==2?'any':'homebranch');
263
    my @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
264
    my @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
265
    my @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
266
    my @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
267
268
    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');
269
270
    #Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch'
271
    Koha::CirculationRules->set_rules(
272
        {
273
            branchcode => undef,
274
            itemtype   => undef,
275
            categorycode => undef,
276
            rules => {
277
                holdallowed => 1,
278
                hold_fulfillment_policy => 'any',
279
                returnbranch => 'any'
280
            }
281
        }
282
    );
283
284
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
285
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
286
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
287
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
288
289
    ok(scalar(@pl_1_1) == 3, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
290
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
291
292
    #Case 3: holdallowed holdgroup, hold_fulfillment_policy any
293
    Koha::CirculationRules->set_rules(
294
        {
295
            branchcode => undef,
296
            itemtype   => undef,
297
            categorycode => undef,
298
            rules => {
299
                holdallowed => 3,
300
                hold_fulfillment_policy => 'any',
301
                returnbranch => 'any'
302
            }
303
        }
304
    );
305
306
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
307
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
308
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
309
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
310
311
    ok(scalar(@pl_1_1) == 3, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
312
    ok(scalar(@pl_3_4) == 3, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
313
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
314
315
    #Case 4: holdallowed any, hold_fulfillment_policy holdgroup
316
    Koha::CirculationRules->set_rules(
317
        {
318
            branchcode => undef,
319
            itemtype   => undef,
320
            categorycode => undef,
321
            rules => {
322
                holdallowed => 2,
323
                hold_fulfillment_policy => 'holdgroup',
324
                returnbranch => 'any'
325
            }
326
        }
327
    );
328
327
329
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
328
        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));
330
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
329
    }
331
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
332
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
333
334
    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');
335
    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');
336
337
    #Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch'
338
    Koha::CirculationRules->set_rules(
339
        {
340
            branchcode => undef,
341
            itemtype   => undef,
342
            categorycode => undef,
343
            rules => {
344
                holdallowed => 1,
345
                hold_fulfillment_policy => 'holdgroup',
346
                returnbranch => 'any'
347
            }
348
        }
349
    );
350
351
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
352
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
353
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
354
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
355
356
    ok(scalar(@pl_1_1) == 2, 'Pickup location for patron 1 and item 1 renders all libraries in holdgroup that are pickup_locations');
357
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
358
359
    #Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup
360
    Koha::CirculationRules->set_rules(
361
        {
362
            branchcode => undef,
363
            itemtype   => undef,
364
            categorycode => undef,
365
            rules => {
366
                holdallowed => 3,
367
                hold_fulfillment_policy => 'holdgroup',
368
                returnbranch => 'any'
369
            }
370
        }
371
    );
372
373
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
374
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
375
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
376
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
377
378
    ok(scalar(@pl_1_1) == 2, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
379
    ok(scalar(@pl_3_4) == 1, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
380
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
381
382
    #Case 7: holdallowed any, hold_fulfillment_policy homebranch
383
    Koha::CirculationRules->set_rules(
384
        {
385
            branchcode => undef,
386
            itemtype   => undef,
387
            categorycode => undef,
388
            rules => {
389
                holdallowed => 2,
390
                hold_fulfillment_policy => 'homebranch',
391
                returnbranch => 'any'
392
            }
393
        }
394
    );
395
396
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
397
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
398
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
399
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
400
401
    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');
402
    ok(scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations, because library3 is not pickup_location');
403
404
    #Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch'
405
    Koha::CirculationRules->set_rules(
406
        {
407
            branchcode => undef,
408
            itemtype   => undef,
409
            categorycode => undef,
410
            rules => {
411
                holdallowed => 1,
412
                hold_fulfillment_policy => 'homebranch',
413
                returnbranch => 'any'
414
            }
415
        }
416
    );
417
418
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
419
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
420
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
421
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
422
423
    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');
424
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
425
426
    #Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch
427
    Koha::CirculationRules->set_rules(
428
        {
429
            branchcode => undef,
430
            itemtype   => undef,
431
            categorycode => undef,
432
            rules => {
433
                holdallowed => 3,
434
                hold_fulfillment_policy => 'homebranch',
435
                returnbranch => 'any'
436
            }
437
        }
438
    );
439
440
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
441
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
442
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
443
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
444
445
    ok(scalar(@pl_1_1) == 1, 'Pickup location for patron 1 and item 1 renders item\'s homebranch');
446
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
447
448
    #Case 10: holdallowed any, hold_fulfillment_policy holdingbranch
449
    Koha::CirculationRules->set_rules(
450
        {
451
            branchcode => undef,
452
            itemtype   => undef,
453
            categorycode => undef,
454
            rules => {
455
                holdallowed => 2,
456
                hold_fulfillment_policy => 'holdingbranch',
457
                returnbranch => 'any'
458
            }
459
        }
460
    );
461
462
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
463
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
464
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
465
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
466
467
    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');
468
    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');
469
470
471
    #Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch'
472
    Koha::CirculationRules->set_rules(
473
        {
474
            branchcode => undef,
475
            itemtype   => undef,
476
            categorycode => undef,
477
            rules => {
478
                holdallowed => 1,
479
                hold_fulfillment_policy => 'holdingbranch',
480
                returnbranch => 'any'
481
            }
482
        }
483
    );
484
485
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
486
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
487
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
488
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
489
490
    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');
491
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
492
493
    #Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch
494
    Koha::CirculationRules->set_rules(
495
        {
496
            branchcode => undef,
497
            itemtype   => undef,
498
            categorycode => undef,
499
            rules => {
500
                holdallowed => 3,
501
                hold_fulfillment_policy => 'holdingbranch',
502
                returnbranch => 'any'
503
            }
504
        }
505
    );
506
507
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
508
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
509
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
510
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
511
512
    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');
513
    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');
514
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
515
516
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch');
517
518
    #Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch'
519
    Koha::CirculationRules->set_rules(
520
        {
521
            branchcode => undef,
522
            itemtype   => undef,
523
            categorycode => undef,
524
            rules => {
525
                holdallowed => 1,
526
                hold_fulfillment_policy => 'any',
527
                returnbranch => 'any'
528
            }
529
        }
530
    );
531
330
532
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
533
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
534
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
535
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
536
537
    ok(scalar(@pl_3_4) == 3, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
538
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
539
540
    #Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch'
541
    Koha::CirculationRules->set_rules(
542
        {
543
            branchcode => undef,
544
            itemtype   => undef,
545
            categorycode => undef,
546
            rules => {
547
                holdallowed => 1,
548
                hold_fulfillment_policy => 'holdgroup',
549
                returnbranch => 'any'
550
            }
551
        }
552
    );
553
331
554
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
332
    foreach my $item ($item1, $item3) {
555
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
333
        foreach my $patron ($patron1, $patron4) {
556
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
334
            #holdallowed 1: homebranch, 2: any, 3: holdgroup
557
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
335
            foreach my $ha (1, 2, 3) {
558
336
                foreach my $hfp ('any', 'holdgroup', 'patrongroup', 'homebranch', 'holdingbranch') {
559
    ok(scalar(@pl_3_4) == 1, 'Pickup location for patron 4 and item 3 renders all libraries in holdgroup that are pickup_locations');
337
                    _doTest($item, $patron, $ha, $hfp, $results);
560
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
338
                }
561
562
    #Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch'
563
    Koha::CirculationRules->set_rules(
564
        {
565
            branchcode => undef,
566
            itemtype   => undef,
567
            categorycode => undef,
568
            rules => {
569
                holdallowed => 1,
570
                hold_fulfillment_policy => 'homebranch',
571
                returnbranch => 'any'
572
            }
339
            }
573
        }
340
        }
574
    );
341
    }
575
576
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
577
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
578
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
579
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
580
581
    #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');
582
    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');
583
584
    #Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch'
585
    Koha::CirculationRules->set_rules(
586
        {
587
            branchcode => undef,
588
            itemtype   => undef,
589
            categorycode => undef,
590
            rules => {
591
                holdallowed => 1,
592
                hold_fulfillment_policy => 'holdingbranch',
593
                returnbranch => 'any'
594
            }
595
        }
596
    );
597
598
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
599
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
600
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
601
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
602
603
    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');
604
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
605
342
606
    $schema->storage->txn_rollback;
343
    $schema->storage->txn_rollback;
607
};
344
};
(-)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