From 1c8993755971a5601a4e4db6ed4e290ea798ab3a Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 14 Jan 2015 11:42:29 -0500 Subject: [PATCH] Bug 12632 - Unit Tests --- t/db_dependent/Holds.t | 38 +++++++++++++++++++++++++++++++++----- 1 files changed, 33 insertions(+), 5 deletions(-) diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 01e67db..14c1bf0 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -6,7 +6,7 @@ use t::lib::Mocks; use C4::Context; use C4::Branch; -use Test::More tests => 49; +use Test::More tests => 51; use MARC::Record; use C4::Biblio; use C4::Items; @@ -37,6 +37,7 @@ my $insert_sth = $dbh->prepare('INSERT INTO itemtypes (itemtype) VALUES (?)'); $insert_sth->execute('CAN'); $insert_sth->execute('CANNOT'); $insert_sth->execute('DUMMY'); +$insert_sth->execute('ONLY1'); # Setup Test------------------------ # Create a biblio instance for testing @@ -210,19 +211,19 @@ my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber) $dbh->do('DELETE FROM issuingrules'); $dbh->do( q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) - VALUES (?, ?, ?, ?)}, + VALUES (?, ?, ?, ?)}, {}, '*', '*', '*', 25 ); $dbh->do( q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) - VALUES (?, ?, ?, ?)}, + VALUES (?, ?, ?, ?)}, {}, - '*', '*', 'CANNOT', 0 + '*', '*', 'CANNOT', 0 ); # make sure some basic sysprefs are set -t::lib::Mocks::mock_preference('ReservesControlBranch', 'homebranch'); +t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); t::lib::Mocks::mock_preference('item-level_itypes', 1); # if IndependentBranches is OFF, a CPL patron can reserve an MPL item @@ -422,6 +423,33 @@ CancelExpiredReserves(); $count = $dbh->selectrow_array("SELECT COUNT(*) FROM reserves WHERE reserve_id = ?", undef, $reserve_id ); is( $count, 0, "Reserve with manual expiration date canceled correctly" ); +# Bug 12632 +t::lib::Mocks::mock_preference( 'item-level_itypes', 1 ); +t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' ); + +$dbh->do('DELETE FROM reserves'); +$dbh->do('DELETE FROM issues'); +$dbh->do('DELETE FROM items'); +$dbh->do('DELETE FROM biblio'); + +( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1'); +( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( { homebranch => 'CPL', holdingbranch => 'CPL' }, $bibnum ); + +$dbh->do( + q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) + VALUES (?, ?, ?, ?)}, + {}, + '*', '*', 'ONLY1', 1 +); +is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ), + 'OK', 'Patron can reserve item with hold limit of 1, no holds placed' ); + +my $res_id = AddReserve( $branch, $borrowernumbers[0], $bibnum, 'a', '', 1, ); + +is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ), + 'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); + + # Helper method to set up a Biblio. sub create_helper_biblio { my $itemtype = shift; -- 1.7.2.5