From 0527196a8eb77ad6ccbaf8ba0637f2ac37a63c26 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 + check maxreserves improve t/db_dependent/Reserves.t to make tests pass on UNIMARC installation --- t/db_dependent/Reserves.t | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 5d661ee97f..068955e9b8 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -62,7 +62,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"); @@ -1192,6 +1196,39 @@ subtest 'AllowHoldOnPatronPossession test' => sub { 'Patron can place hold on an item loaned to itself'); }; +subtest 'check maxreserve test' => sub { + + plan tests => 2; + + t::lib::Mocks::mock_preference('maxreserves', 1); + # Create the items and patrons we need + my $biblio_1 = $builder->build_sample_biblio(); + my $biblio_2 = $builder->build_sample_biblio(); + 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", + value => { branchcode => $item_2->homebranch }}); + + + # Place a hold on the title for both patrons + my $reserve = AddReserve( + { + branchcode => $item_1->homebranch, + borrowernumber => $patron->borrowernumber, + biblionumber => $biblio_1->biblionumber, + priority => 1, + itemnumber => $item_1->itemnumber, + } + ); + + my $borrowernumber = $patron->borrowernumber; + + 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"); + +}; + subtest 'MergeHolds' => sub { plan tests => 1; -- 2.30.2