From 05587d0186226c88182ab9389ed1c80b60599a1d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 30 Apr 2021 11:19:05 +0200 Subject: [PATCH] Bug 28206: Move tests to a subtest --- t/db_dependent/Holds.t | 75 +++++++++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 19 deletions(-) diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 64419b5fee8..a17a173c95b 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -7,7 +7,7 @@ use t::lib::TestBuilder; use C4::Context; -use Test::More tests => 71; +use Test::More tests => 67; use MARC::Record; use C4::Biblio; @@ -325,26 +325,63 @@ ok( is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" ); } -Koha::Items->find($itemnumber)->damaged(1)->store; # FIXME The $itemnumber is a bit confusing here -t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 ); -is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" ); -ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" ); +subtest 'AllowHoldsOnDamagedItems' => sub { + plan tests => 5; -$hold = Koha::Hold->new( - { - borrowernumber => $borrowernumbers[0], - itemnumber => $itemnumber, - biblionumber => $biblio->biblionumber, - } -)->store(); -is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, - 'itemAlreadyOnHold', - "Patron cannot place a second item level hold for a given item" ); -$hold->delete(); + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $biblio = $builder->build_sample_biblio; + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $reserveid1 = AddReserve( + { + branchcode => $library->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $biblio->biblionumber, + priority => 1 + } + ); -t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 ); -ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'damaged', "Patron cannot reserve damaged item with AllowHoldsOnDamagedItems disabled" ); -ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" ); + my $itemnumber = $builder->build_sample_item( + { + library => $library->branchcode, + biblionumber => $biblio->biblionumber, + damaged => 1 + } + )->itemnumber; + t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 ); + is( + CanItemBeReserved( $patron->borrowernumber, $itemnumber )->{status}, + 'OK', + "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" + ); + ok( + defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" + ); + + $hold = Koha::Hold->new( + { + borrowernumber => $patron->borrowernumber, + itemnumber => $itemnumber, + biblionumber => $biblio->biblionumber, + } + )->store(); + is( + CanItemBeReserved( $patron->borrowernumber, $itemnumber )->{status}, + 'itemAlreadyOnHold', + "Patron cannot place a second item level hold for a given item" + ); + $hold->delete(); + + t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 ); + is( + CanItemBeReserved( $patron->borrowernumber, $itemnumber )->{status}, + 'damaged', + "Patron cannot reserve damaged item with AllowHoldsOnDamagedItems disabled" + ); + ok( + !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" + ); + +}; # Items that are not for loan, but holdable should not be trapped until they are available for loan t::lib::Mocks::mock_preference( 'TrapHoldsOnOrder', 0 ); -- 2.20.1