From 4d3b96ab0a634fb59eb8fcf89b5068caa45e7ad6 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Tue, 16 Jun 2015 11:48:08 +0200 Subject: [PATCH] Bug 14155 - Add tests in t/db_dependent/Reserves.t - add tests for C4::Reserves::AlreadyReserved(), - add tests for C4::Reserves::ReachedMaxReserves(), Signed-off-by: Indranil Das Gupta (L2C2 Technologies) --- t/db_dependent/Reserves.t | 54 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 7301757..1c94b73 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 73; +use Test::More tests => 77; use Test::Warn; use MARC::Record; @@ -82,6 +82,38 @@ else { my ($bibnum, $bibitemnum); ($bibnum, $title, $bibitemnum) = AddBiblio($bib, ''); +my $miniaturist = MARC::Record->new(); +my $title = 'The Miniaturist'; +if( C4::Context->preference('marcflavour') eq 'UNIMARC' ) { + $miniaturist->append_fields( + MARC::Field->new('600', '', '1', a => 'Burton, Jessie'), + MARC::Field->new('200', '', '', a => $title), + ); +} +else { + $miniaturist->append_fields( + MARC::Field->new('100', '', '', a => 'Burton, Jessie'), + MARC::Field->new('245', '', '', a => $title), + ); +} +my ($miniaturist_id, $title, $bibitemnum) = AddBiblio($miniaturist, ''); + +my $broken = MARC::Record->new(); +my $title = 'The broken'; +if( C4::Context->preference('marcflavour') eq 'UNIMARC' ) { + $broken->append_fields( + MARC::Field->new('600', '', '1', a => 'Cohen, Tamar'), + MARC::Field->new('200', '', '', a => $title), + ); +} +else { + $broken->append_fields( + MARC::Field->new('100', '', '', a => 'Cohen, Tamar'), + MARC::Field->new('245', '', '', a => $title), + ); +} +my ($broken_id, $title, $bibitemnum) = AddBiblio($miniaturist, ''); + # Create a helper item instance for testing my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum); @@ -128,6 +160,24 @@ is($status, "Reserved", "CheckReserves Test 2"); ($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode); is($status, "Reserved", "CheckReserves Test 3"); +ok(AlreadyReserved($biblionumber, $borrowernumber), 'First borrower already reserved first biblio'); + +t::lib::Mocks::mock_preference('maxreserves', 3); + +ok(!ReachedMaxReserves($borrowernumber), 'First borrower doesn\'t reached max reserves'); + +AddReserve($branch, $borrowernumber, $miniaturist_id, + $constraint, $bibitems, $priority, $resdate, $expdate, $notes, + $title, $checkitem, $found); + +AddReserve($branch, $borrowernumber, $broken_id, + $constraint, $bibitems, $priority, $resdate, $expdate, $notes, + $title, $checkitem, $found); + +ok(ReachedMaxReserves($borrowernumber), 'First borrower reached max reserves'); + +t::lib::Mocks::mock_preference('maxreserves', 15); + my $ReservesControlBranch = C4::Context->preference('ReservesControlBranch'); C4::Context->set_preference( 'ReservesControlBranch', 'ItemHomeLibrary' ); ok( @@ -304,6 +354,8 @@ is($reserve, undef, "GetReserve returns undef after deletion"); $reserve = CancelReserve({reserve_id => $reserve_id}); is($reserve, undef, "CancelReserve return undef if reserve does not exist"); +ok(!AlreadyReserved($bibnum2, $borrowernumber), 'First borrower does not already reserved second biblio'); + # Tests for bug 9761 (ConfirmFutureHolds): new CheckReserves lookahead parameter, and corresponding change in AddReturn # Note that CheckReserve uses its lookahead parameter and does not check ConfirmFutureHolds pref (it should be passed if needed like AddReturn does) -- 1.7.10.4