From f955c899a949e87c7b55ae6581f3c3d2b08e82e8 Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Fri, 3 Jul 2020 11:58:49 +0200 Subject: [PATCH] Bug 11999: (QA follow-up) --- C4/Reserves.pm | 19 ++++--------------- t/db_dependent/Reserves.t | 15 ++++++++------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 026b6467a2..519de7641a 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -330,7 +330,7 @@ sub CanBookBeReserved{ # Check if borrower has reached the maximum number of holds allowed my $maxreserves = C4::Context->preference('maxreserves'); if ($maxreserves && $holds->count >= $maxreserves) { - return { status => 'tooManyReserves' }; + return { status => 'tooManyReserves', limit => $maxreserves }; } my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber"); @@ -403,18 +403,17 @@ sub CanItemBeReserved { return { status =>'itemAlreadyOnHold' } if Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count(); -<<<<<<< HEAD # Check that patron have not checked out this biblio (if AllowHoldsOnPatronsPossessions set) if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions') && C4::Circulation::CheckIfIssuedToPatron( $patron->borrowernumber, $biblio->biblionumber ) ) { return { status =>'alreadypossession' }; -======= + } + # Check if borrower has reached the maximum number of holds allowed my $maxreserves = C4::Context->preference('maxreserves'); my $holds = Koha::Holds->search( { borrowernumber => $borrowernumber } ); if ($maxreserves && $holds->count >= $maxreserves) { return { status => 'tooManyReserves', limit => $maxreserves }; ->>>>>>> Bug 11999: Add maxreserves check in CanBookBeReserved and CanItemBeReserved } my $controlbranch = C4::Context->preference('ReservesControlBranch'); @@ -451,25 +450,15 @@ sub CanItemBeReserved { $ruleitemtype = undef; } -<<<<<<< HEAD my $search_params = { borrowernumber => $borrowernumber, biblionumber => $item->biblionumber, }; $search_params->{found} = undef if $params->{ignore_found_holds}; - my $holds = Koha::Holds->search($search_params); + $holds = Koha::Holds->search($search_params); if ( defined $holds_per_record && $holds_per_record ne '' && $holds->count() >= $holds_per_record ) { -======= - $holds = Koha::Holds->search( - { - borrowernumber => $borrowernumber, - biblionumber => $item->biblionumber, - } - ); - if ( $holds->count() >= $holds_per_record ) { ->>>>>>> Bug 11999: Add maxreserves check in CanBookBeReserved and CanItemBeReserved return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record }; } diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index fe31164c74..12474f2768 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 65; +use Test::More tests => 66; use Test::MockModule; use Test::Warn; @@ -1156,7 +1156,6 @@ subtest 'CheckReserves additional test' => sub { is( scalar @$possible_reserves, 2, 'We do get both reserves' ); }; -<<<<<<< HEAD subtest 'AllowHoldOnPatronPossession test' => sub { plan tests => 4; @@ -1193,7 +1192,8 @@ subtest 'AllowHoldOnPatronPossession test' => sub { $item->itemnumber)->{status}, 'OK', 'Patron can place hold on an item loaned to itself'); -======= +}; + subtest 'check maxreserve test' => sub { plan tests => 2; @@ -1205,7 +1205,8 @@ subtest 'check maxreserve test' => sub { my $itype = $builder->build_object({ class => "Koha::ItemTypes", value => { notforloan => 0 } }); my $item_1 = $builder->build_sample_item({ biblionumber => $biblio_1->biblionumber,notforloan => 0, itype => $itype->itemtype }); my $item_2 = $builder->build_sample_item({ biblionumber => $biblio_2->biblionumber, notforloan => 0, itype => $itype->itemtype }); - my $patron = $builder->build_object({ class => "Koha::Patrons" }); + my $patron = $builder->build_object({ class => "Koha::Patrons", + value => { branchcode => $item_2->homebranch }}); # Place a hold on the title for both patrons @@ -1221,9 +1222,9 @@ subtest 'check maxreserve test' => sub { my $borrowernumber = $patron->borrowernumber; - is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_2->biblionumber)->{status} , 'tooManyReserves', "Reserving more than maxreserves is forbidden"); - is( C4::Reserves::CanItemBeReserved($borrowernumber, $item_2->itemnumber, $item_2->homebranch)->{status} , 'tooManyReserves', "Reserving more than maxreserves is forbidden"); ->>>>>>> Bug 11999: Test improvements + check maxreserves + is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_2->biblionumber)->{status} , 'tooManyReserves', "CanBookBeReserved: Reserving more than maxreserves is forbidden"); + is( C4::Reserves::CanItemBeReserved($borrowernumber, $item_2->itemnumber, $item_2->homebranch)->{status} , 'tooManyReserves', "CanItemBeReserved: Reserving more than maxreserves is forbidden"); + }; sub count_hold_print_messages { -- 2.11.0