From ed5d8e1c5a2b0055853a1331b7f6d3764f81d0f1 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 5 Oct 2015 07:50:03 -0400 Subject: [PATCH] Bug 5144: Add unit test Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Holds.t | 10 +++++----- t/db_dependent/Reserves.t | 22 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 57cb386503..9a44084e13 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -155,7 +155,7 @@ ok( !$reserve->{'suspend'}, "Test AutoUnsuspendReserves()" ); # Add a new hold for the borrower whose hold we canceled earlier, this time at the bib level AddReserve( $branch_1, - $borrowernumber, + $borrowernumbers[0], $biblionumber, my $bibitems = q{}, my $priority, @@ -187,19 +187,19 @@ $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dat $reserve = $reserves->[1]; AlterPriority( 'top', $reserve->{'reserve_id'} ); $reserve = GetReserve( $reserve->{'reserve_id'} ); -ok( $reserve->{'priority'} eq '1', "Test AlterPriority(), move to top" ); +is( $reserve->{'priority'}, '1', "Test AlterPriority(), move to top" ); AlterPriority( 'down', $reserve->{'reserve_id'} ); $reserve = GetReserve( $reserve->{'reserve_id'} ); -ok( $reserve->{'priority'} eq '2', "Test AlterPriority(), move down" ); +is( $reserve->{'priority'}, '2', "Test AlterPriority(), move down" ); AlterPriority( 'up', $reserve->{'reserve_id'} ); $reserve = GetReserve( $reserve->{'reserve_id'} ); -ok( $reserve->{'priority'} eq '1', "Test AlterPriority(), move up" ); +is( $reserve->{'priority'}, '1', "Test AlterPriority(), move up" ); AlterPriority( 'bottom', $reserve->{'reserve_id'} ); $reserve = GetReserve( $reserve->{'reserve_id'} ); -ok( $reserve->{'priority'} eq '5', "Test AlterPriority(), move to bottom" ); +is( $reserve->{'priority'}, '5', "Test AlterPriority(), move to bottom" ); # Regression test for bug 2394 # diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index bb534c2f4b..4e6fd6f31e 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 71; +use Test::More tests => 72; use MARC::Record; use DateTime::Duration; @@ -153,6 +153,13 @@ $requesters{'CPL'} = AddMember( categorycode => 'PT', surname => 'borrower from CPL', ); +for my $i ( 2 .. 5 ) { + $requesters{"CPL$i"} = AddMember( + branchcode => 'CPL', + categorycode => 'PT', + surname => 'borrower $i from CPL', + ); +} $requesters{'FPL'} = AddMember( branchcode => 'FPL', categorycode => 'PT', @@ -393,11 +400,12 @@ ModReserveAffect( $itemnumber, $requesters{'CPL'} , 0); #confirm hold is(defined $results[3]?1:0, 1, 'GetReservesFromItemnumber returns a future wait (confirmed future hold)'); # End of tests for bug 9788 +$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum)); # Tests for CalculatePriority (bug 8918) my $p = C4::Reserves::CalculatePriority($bibnum2); is($p, 4, 'CalculatePriority should now return priority 4'); $resdate=undef; -AddReserve('CPL', $requesters{'CPL'}, $bibnum2, +AddReserve('CPL', $requesters{'CPL2'}, $bibnum2, $bibitems, $p, $resdate, $expdate, $notes, $title, $checkitem, $found); $p = C4::Reserves::CalculatePriority($bibnum2); @@ -416,7 +424,7 @@ ModReserveAffect( $itemnumber, $requesters{'CPL'} , 0); $p = C4::Reserves::CalculatePriority($bibnum); is($p, 1, 'CalculatePriority should now return priority 1'); #add another biblio hold, no resdate -AddReserve('CPL', $requesters{'CPL'}, $bibnum, +AddReserve('CPL', $requesters{'CPL2'}, $bibnum, $bibitems, $p, $resdate, $expdate, $notes, $title, $checkitem, $found); $p = C4::Reserves::CalculatePriority($bibnum); @@ -425,7 +433,7 @@ is($p, 2, 'CalculatePriority should now return priority 2'); C4::Context->set_preference('AllowHoldDateInFuture', 1); $resdate= dt_from_string(); $resdate->add_duration(DateTime::Duration->new(days => 1)); -AddReserve('CPL', $requesters{'CPL'}, $bibnum, +AddReserve('CPL', $requesters{'CPL3'}, $bibnum, $bibitems, $p, output_pref($resdate), $expdate, $notes, $title, $checkitem, $found); $p = C4::Reserves::CalculatePriority($bibnum); @@ -435,6 +443,12 @@ $p = C4::Reserves::CalculatePriority($bibnum, $resdate); is($p, 3, 'CalculatePriority should now return priority 3'); # End of tests for bug 8918 +# Test for bug 5144 +$reserve_id = AddReserve('CPL', $requesters{'CPL3'}, $bibnum, + $bibitems, $p, output_pref($resdate), $expdate, $notes, + $title, $checkitem, $found); +is( $reserve_id, undef, 'Attempt to add a second reserve on a given record for the same patron fails.' ); + # Tests for cancel reserves by users from OPAC. $dbh->do('DELETE FROM reserves', undef, ($bibnum)); AddReserve('CPL', $requesters{'CPL'}, $item_bibnum, -- 2.11.4.GIT