From 96c2b9b83327c145f08bb1a10b69b5db54e6a6f6 Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Thu, 18 Jul 2019 15:03:40 +0200 Subject: [PATCH] Bug 11999: Test improvements improve t/db_dependent/Reserves.t to make tests pass on UNIMARC installation --- t/db_dependent/Holds.t | 62 +++++++++++++++++++++++++++++------------------ t/db_dependent/Reserves.t | 6 ++++- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 1515b4bef4..225e3bdea6 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 => 59; +use Test::More tests => 62; use MARC::Record; use C4::Biblio; @@ -282,27 +282,28 @@ ok( '... unless canreservefromotherbranches is ON (bug 2394)' ); -{ - # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities - $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); - ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); - my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1); - ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); - my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2); - ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); - my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3); - my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber }); - my $hold3 = Koha::Holds->find( $reserveid3 ); - is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" ); - ModReserve({ reserve_id => $reserveid1, rank => 'del' }); - ModReserve({ reserve_id => $reserveid2, rank => 'del' }); - is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" ); -} +# Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities +$biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); +($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); +my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1); +($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); +my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2); +($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); +my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3); +my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber }); +my $hold3 = Koha::Holds->find( $reserveid3 ); +is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" ); +ModReserve({ reserve_id => $reserveid1, rank => 'del' }); +ModReserve({ reserve_id => $reserveid2, rank => 'del' }); +is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" ); + +ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" ); ModItem({ damaged => 1 }, $item_bibnum, $itemnumber); +$hold = Koha::Holds->find( $reserveid3 ); +$hold->cancel; 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" ); $hold = Koha::Hold->new( { @@ -330,23 +331,36 @@ AddReserve( '', 1, ); +my $biblio2 = $builder->build_sample_biblio({ itemtype => 'CANNOT' }); +my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio2->biblionumber); is( - CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves', + CanItemBeReserved( $borrowernumbers[0], $itemnumber2)->{status}, 'tooManyReserves', "cannot request item if policy that matches on item-level item type forbids it" ); -ModItem({ itype => 'CAN' }, $item_bibnum, $itemnumber); +ModItem({ itype => 'CAN' }, $item_bibnum2, $itemnumber2); ok( - CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK', + CanItemBeReserved( $borrowernumbers[0], $itemnumber2)->{status} eq 'OK', "can request item if policy that matches on item type allows it" ); t::lib::Mocks::mock_preference('item-level_itypes', 0); -ModItem({ itype => undef }, $item_bibnum, $itemnumber); -ok( - CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves', +ModItem({ itype => undef }, $item_bibnum, $itemnumber2); +is( + CanItemBeReserved( $borrowernumbers[0], $itemnumber2)->{status}, 'tooManyReserves', "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)" ); +is(CanBookBeReserved($borrowernumbers[0], $biblio->biblionumber)->{status}, 'OK'); + +C4::Context->set_preference('maxreserves', 1); +is(CanBookBeReserved($borrowernumbers[0], $biblio->biblionumber)->{status}, 'tooManyReserves'); + +C4::Context->set_preference('maxreserves', 0); +t::lib::Mocks::mock_preference('IndependentBranches', 1); +t::lib::Mocks::mock_preference('canreservefromotherbranches', 0); +ok(CanBookBeReserved($borrowernumbers[0], $foreign_biblio->biblionumber)->{status} eq 'none_available'); +t::lib::Mocks::mock_preference('IndependentBranches', 0); +t::lib::Mocks::mock_preference('canreservefromotherbranches', 1); # Test branch item rules diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 27b2701ab6..76b5baa210 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -59,7 +59,11 @@ my $frameworkcode = q//; t::lib::Mocks::mock_preference('ReservesNeedReturns', 1); # Somewhat arbitrary field chosen for age restriction unit tests. Must be added to db before the framework is cached -$dbh->do("update marc_subfield_structure set kohafield='biblioitems.agerestriction' where tagfield='521' and tagsubfield='a' and frameworkcode=?", undef, $frameworkcode); +$dbh->do(q| + INSERT INTO marc_subfield_structure (frameworkcode, tagfield, tagsubfield, kohafield) + VALUES ('', '521', 'a', 'biblioitems.agerestriction') + ON DUPLICATE KEY UPDATE kohafield = VALUES(kohafield) +|); my $cache = Koha::Caches->get_instance; $cache->clear_from_cache("MarcStructure-0-$frameworkcode"); $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); -- 2.11.0