From bb71ae240ddcc150dcfd5771f25b8b9d8b910e9b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 19 Jul 2017 16:30:24 -0300 Subject: [PATCH] Bug 15486: Unit tests This patch introduces unit tests for the new circulation rules option that allows setting a max holds per day limit. To test: - Apply the patch - Run: $ sudo koha-shell kohadev k$ cd kohaclone k$ prove t/db_dependent/Holds.t => FAIL: CanItemBeReserved doesn't check the amount of holds per day and the introduced error code is not returned. OK is returned instead. --- t/db_dependent/Holds.t | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index ad87b26129..67bfb3bd50 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 => 58; +use Test::More tests => 61; use MARC::Record; use C4::Biblio; use C4::Items; @@ -449,10 +449,10 @@ $dbh->do('DELETE FROM biblio'); = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $bibnum ); $dbh->do( - q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) - VALUES (?, ?, ?, ?, ?)}, + q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record, holds_per_day) + VALUES (?, ?, ?, ?, ?, ?)}, {}, - '*', '*', 'ONLY1', 1, 99 + '*', '*', 'ONLY1', 1, 99, 2 ); is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ), 'OK', 'Patron can reserve item with hold limit of 1, no holds placed' ); @@ -462,6 +462,33 @@ my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, ); is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ), 'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); +# Add two more items +my ( $bibnum_2, undef, $bibitemnum_2 ) = create_helper_biblio('ONLY1'); +my ( undef, undef, $itemnumber_2 ) + = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $bibnum_2 ); +my ( $bibnum_3, undef, $bibitemnum_3 ) = create_helper_biblio('ONLY1'); +my ( undef, undef, $itemnumber_3 ) + = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $bibnum_3 ); +# Raise reservesallowed to avoid tooManyReserves +$dbh->do(q{ + UPDATE issuingrules SET reservesallowed=3 WHERE itemtype='ONLY1' +}); + +is( CanItemBeReserved( $borrowernumbers[0], $itemnumber_2 ), + 'OK', 'Patron can reserve item with hold limit of 1, 1 bib level hold placed, 2 reserves daily cap' ); + +# Add a second reserve +$res_id = AddReserve( $branch_1, $borrowernumbers[0], $bibnum_2, '', 1, ); +is( CanItemBeReserved( $borrowernumbers[0], $itemnumber_2 ), + 'tooManyReservesToday', 'Patron cannot reserve item with hold limit of 3, 2 bib level hold placed on the same day, 2 reserves daily cap' ); + +# Update last hold so reservedate is in the past, so 2 holds, but different day +$hold = Koha::Holds->find( $res_id ); +my $yesterday = dt_from_string() - DateTime::Duration->new( days => 1 ) ; +$hold->reservedate( $yesterday )->store; + +is( CanItemBeReserved( $borrowernumbers[0], $itemnumber_2 ), + 'OK', 'Patron can reserve item with hold limit of 3, 2 bib level hold placed on different days, 2 reserves daily cap' ); # Helper method to set up a Biblio. sub create_helper_biblio { -- 2.13.3