From 3f949e15304967271407e981e8785d03da9f739c 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 4aee01b..cd93bfe 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 => 38; +use Test::More tests => 40; use MARC::Record; use C4::Biblio; use C4::Items; @@ -34,6 +34,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 @@ -193,19 +194,25 @@ 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 +); +$dbh->do( + q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) + VALUES (?, ?, ?, ?)}, + {}, + '*', '*', 'ONLY1', 1 ); # 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 @@ -365,6 +372,27 @@ 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 ); + +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 can reserve item with hold limit of 1, no holds placed' ); + + # Helper method to set up a Biblio. sub create_helper_biblio { my $itemtype = shift; -- 1.7.2.5