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

(-)a/t/db_dependent/Koha/Biblio.t (-20 / +65 lines)
Lines 243-249 subtest 'is_serial() tests' => sub { Link Here
243
243
244
subtest 'pickup_locations() tests' => sub {
244
subtest 'pickup_locations() tests' => sub {
245
245
246
    plan tests => 11;
246
    plan tests => 19;
247
247
248
    $schema->storage->txn_begin;
248
    $schema->storage->txn_begin;
249
249
Lines 442-472 subtest 'pickup_locations() tests' => sub { Link Here
442
        "PatronLibrary-2-8" => 3,
442
        "PatronLibrary-2-8" => 3,
443
    };
443
    };
444
444
445
    my $items_results = {
446
        "ItemHomeLibrary-1-1" => {
447
            $library1->branchcode => [ $item1_1->itemnumber ],
448
            $library2->branchcode => [ $item1_1->itemnumber ],
449
            $library4->branchcode => [ $item1_1->itemnumber ],
450
            $library5->branchcode => [ $item1_1->itemnumber ],
451
            $library6->branchcode => [ $item1_1->itemnumber ],
452
            $library7->branchcode => [ $item1_1->itemnumber ]
453
        },
454
        "ItemHomeLibrary-1-8" => {
455
            $library4->branchcode => [ $item1_7->itemnumber ],
456
        },
457
        "ItemHomeLibrary-2-1" => {
458
            $library1->branchcode => [ $item2_2->itemnumber ],
459
            $library2->branchcode => [ $item2_2->itemnumber ],
460
        },
461
        "ItemHomeLibrary-2-8" => {},
462
        "PatronLibrary-1-1"   => {
463
            $library1->branchcode => [ $item1_1->itemnumber ],
464
            $library2->branchcode => [ $item1_1->itemnumber ],
465
            $library4->branchcode => [ $item1_1->itemnumber ],
466
            $library5->branchcode => [ $item1_1->itemnumber ],
467
            $library6->branchcode => [ $item1_1->itemnumber ],
468
            $library7->branchcode => [ $item1_1->itemnumber ]
469
        },
470
        "PatronLibrary-1-8" => {
471
            $library5->branchcode => [ $item1_1->itemnumber, $item1_3->itemnumber, $item1_7->itemnumber ],
472
            $library6->branchcode => [ $item1_1->itemnumber, $item1_3->itemnumber, $item1_7->itemnumber ],
473
            $library7->branchcode => [ $item1_1->itemnumber, $item1_3->itemnumber, $item1_7->itemnumber ],
474
        },
475
        "PatronLibrary-2-1" => {},
476
        "PatronLibrary-2-8" => {
477
            $library5->branchcode => [ $item2_2->itemnumber, $item2_4->itemnumber, $item2_6->itemnumber ],
478
            $library6->branchcode => [ $item2_2->itemnumber, $item2_4->itemnumber, $item2_6->itemnumber ],
479
            $library7->branchcode => [ $item2_2->itemnumber, $item2_4->itemnumber, $item2_6->itemnumber ],
480
        }
481
    };
482
445
    sub _doTest {
483
    sub _doTest {
446
        my ( $cbranch, $biblio, $patron, $results ) = @_;
484
        my ( $cbranch, $biblio, $patron, $results, $items_results ) = @_;
447
        t::lib::Mocks::mock_preference('ReservesControlBranch', $cbranch);
485
        t::lib::Mocks::mock_preference( 'ReservesControlBranch', $cbranch );
486
487
        my $pl = $biblio->pickup_locations( { patron => $patron } );
448
488
489
        # Filter to just test branches
449
        my @pl = map {
490
        my @pl = map {
450
            my $pickup_location = $_;
491
            my $pickup_location = $_;
451
            grep { $pickup_location->branchcode eq $_ } @branchcodes
492
            grep { $pickup_location->branchcode eq $_ } @branchcodes
452
        } $biblio->pickup_locations( { patron => $patron } )->as_list;
493
        } $pl->as_list;
453
494
454
        ok(
495
        ok(
455
            scalar(@pl) == $results->{ $cbranch . '-'
496
            scalar(@pl) == $results->{ $cbranch . '-' . $biblio->title . '-' . $patron->firstname },
456
                  . $biblio->title . '-'
457
                  . $patron->firstname },
458
            'ReservesControlBranch: '
497
            'ReservesControlBranch: '
459
              . $cbranch
498
                . $cbranch
460
              . ', biblio'
499
                . ', biblio'
461
              . $biblio->title
500
                . $biblio->title
462
              . ', patron'
501
                . ', patron'
463
              . $patron->firstname
502
                . $patron->firstname
464
              . ' should return '
503
                . ' should return '
465
              . $results->{ $cbranch . '-'
504
                . $results->{ $cbranch . '-' . $biblio->title . '-' . $patron->firstname }
466
                  . $biblio->title . '-'
505
                . ' and returns '
467
                  . $patron->firstname }
506
                . scalar(@pl)
468
              . ' but returns '
507
        );
469
              . scalar(@pl)
508
509
        my %filtered_location_items = map { $_ => $pl->{_pickup_location_items}->{$_} }
510
            grep { exists $pl->{_pickup_location_items}->{$_} } @branchcodes;
511
512
        is_deeply(
513
            \%filtered_location_items, \%{ $items_results->{ $cbranch . '-'
514
                        . $biblio->title . '-'
515
                        . $patron->firstname } }, 'Items per location correctly cached in resultset'
470
        );
516
        );
471
    }
517
    }
472
518
Lines 475-481 subtest 'pickup_locations() tests' => sub { Link Here
475
        $cache->flush(); # needed since we change ReservesControlBranch
521
        $cache->flush(); # needed since we change ReservesControlBranch
476
        foreach my $biblio ($biblio1, $biblio2) {
522
        foreach my $biblio ($biblio1, $biblio2) {
477
            foreach my $patron ($patron1, $patron8) {
523
            foreach my $patron ($patron1, $patron8) {
478
                _doTest($cbranch, $biblio, $patron, $results);
524
                _doTest($cbranch, $biblio, $patron, $results, $items_results);
479
            }
525
            }
480
        }
526
        }
481
    }
527
    }
482
- 

Return to bug 36120