Bug 12632: (regression tests) Unit Tests

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Kyle M Hall 2015-01-14 11:42:29 -05:00 committed by Tomas Cohen Arazi
parent 6f95acd1a6
commit 34c11ee8ee
1 changed files with 33 additions and 5 deletions

View File

@ -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
@ -208,19 +209,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
@ -416,6 +417,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, '', 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;