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

(-)a/t/db_dependent/Reserves.t (-14 / +44 lines)
Lines 1028-1042 subtest 'reserves.item_level_hold' => sub { Link Here
1028
1028
1029
subtest 'MoveReserve additional test' => sub {
1029
subtest 'MoveReserve additional test' => sub {
1030
1030
1031
    plan tests => 4;
1031
    plan tests => 8;
1032
1032
1033
    # Create the items and patrons we need
1033
    # Create the items and patrons we need
1034
    my $biblio = $builder->build_sample_biblio();
1034
    my $biblio = $builder->build_sample_biblio();
1035
    my $itype = $builder->build_object({ class => "Koha::ItemTypes", value => { notforloan => 0 } });
1035
    my $itype  = $builder->build_object( { class => "Koha::ItemTypes", value => { notforloan => 0 } } );
1036
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber,notforloan => 0, itype => $itype->itemtype });
1036
    my $item_1 = $builder->build_sample_item(
1037
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, notforloan => 0, itype => $itype->itemtype });
1037
        { biblionumber => $biblio->biblionumber, notforloan => 0, itype => $itype->itemtype } );
1038
    my $patron_1 = $builder->build_object({ class => "Koha::Patrons" });
1038
    my $item_2 = $builder->build_sample_item(
1039
    my $patron_2 = $builder->build_object({ class => "Koha::Patrons" });
1039
        { biblionumber => $biblio->biblionumber, notforloan => 0, itype => $itype->itemtype } );
1040
    my $patron_1 = $builder->build_object( { class => "Koha::Patrons" } );
1041
    my $patron_2 = $builder->build_object( { class => "Koha::Patrons" } );
1040
1042
1041
    # Place a hold on the title for both patrons
1043
    # Place a hold on the title for both patrons
1042
    my $reserve_1 = AddReserve(
1044
    my $reserve_1 = AddReserve(
Lines 1057-1072 subtest 'MoveReserve additional test' => sub { Link Here
1057
            itemnumber     => $item_1->itemnumber,
1059
            itemnumber     => $item_1->itemnumber,
1058
        }
1060
        }
1059
    );
1061
    );
1060
    is($patron_1->holds->next()->reserve_id, $reserve_1, "The 1st patron has a hold");
1062
    is( $patron_1->holds->next()->reserve_id, $reserve_1, "The 1st patron has a hold" );
1061
    is($patron_2->holds->next()->reserve_id, $reserve_2, "The 2nd patron has a hold");
1063
    is( $patron_2->holds->next()->reserve_id, $reserve_2, "The 2nd patron has a hold" );
1062
1064
1063
    # Fake the holds queue
1065
    # Fake the holds queue
1064
    $dbh->do(q{INSERT INTO hold_fill_targets VALUES (?, ?, ?, ?, ?,?)},undef,($patron_1->borrowernumber,$biblio->biblionumber,$item_1->itemnumber,$item_1->homebranch,0,$reserve_1));
1066
    $dbh->do(
1067
        q{INSERT INTO hold_fill_targets VALUES (?, ?, ?, ?, ?,?)}, undef,
1068
        ( $patron_1->borrowernumber, $biblio->biblionumber, $item_1->itemnumber, $item_1->homebranch, 0, $reserve_1 )
1069
    );
1070
1071
    # The 2nd hold should be filled even if the item is preselected for the first hold
1072
    MoveReserve( $item_1->itemnumber, $patron_2->borrowernumber );
1073
    is( $patron_2->holds->count, 0, "The 2nd patrons no longer has a hold" );
1074
    is(
1075
        $patron_2->old_holds->next()->reserve_id, $reserve_2,
1076
        "The 2nd patrons hold was filled and moved to old holds"
1077
    );
1078
1079
    my $reserve_3 = AddReserve(
1080
        {
1081
            branchcode     => $item_2->homebranch,
1082
            borrowernumber => $patron_2->borrowernumber,
1083
            biblionumber   => $biblio->biblionumber,
1084
            priority       => 1,
1085
            itemnumber     => $item_2->itemnumber,
1086
        }
1087
    );
1088
1089
    # The 3rd hold should not be filled as it is an item level hold on a different item
1090
    MoveReserve( $item_1->itemnumber, $patron_2->borrowernumber );
1091
    is( $patron_2->holds->count,     1, "The 2nd patron still has a hold" );
1092
    is( $patron_2->old_holds->count, 1, "The 2nd patron has only 1 old holds" );
1093
1094
    my $hold_3 = Koha::Holds->find($reserve_3);
1095
    $hold_3->item_level_hold(0)->store();
1065
1096
1066
    # The 2nd hold should be filed even if the item is preselected for the first hold
1097
    # The 3rd hold should now be filled as it is a title level hold, even though associated with a different item
1067
    MoveReserve($item_1->itemnumber,$patron_2->borrowernumber);
1098
    MoveReserve( $item_1->itemnumber, $patron_2->borrowernumber );
1068
    is($patron_2->holds->count, 0, "The 2nd patrons no longer has a hold");
1099
    is( $patron_2->holds->count,       0, "The 2nd patron no longer has a hold" );
1069
    is($patron_2->old_holds->next()->reserve_id, $reserve_2, "The 2nd patrons hold was filled and moved to old holds");
1100
    is( $patron_2->old_holds->count(), 2, "The 2nd patron's hold was filled and moved to old holds" );
1070
1101
1071
};
1102
};
1072
1103
1073
- 

Return to bug 38650