From a89975ab1894f733f193b366d4152375d246fa3b Mon Sep 17 00:00:00 2001
From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Date: Thu, 30 Jan 2014 14:16:03 +0100
Subject: [PATCH] Bug 8918: Follow-up for some more unit tests for
 CalculatePriority
Content-Type: text/plain; charset=utf-8

Adding a few unit tests, including the following situations:
Placing a hold when there is a wait.
Placing a hold when there is a future hold.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
---
 t/db_dependent/Reserves.t |   37 +++++++++++++++++++++++++++++++++++--
 1 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t
index 7f43986..ee61b84 100755
--- a/t/db_dependent/Reserves.t
+++ b/t/db_dependent/Reserves.t
@@ -2,7 +2,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 25;
+use Test::More tests => 31;
 use MARC::Record;
 use DateTime::Duration;
 
@@ -320,11 +320,44 @@ is(defined $results[3]?1:0, 1, 'GetReservesFromItemnumber returns a future wait
 # 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,
-           $constraint, $bibitems,  $p, undef, $expdate, $notes,
+           $constraint, $bibitems,  $p, $resdate, $expdate, $notes,
            $title,      $checkitem, $found);
 $p = C4::Reserves::CalculatePriority($bibnum2);
 is($p, 5, 'CalculatePriority should now return priority 5');
+#some tests on bibnum
+$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
+$p = C4::Reserves::CalculatePriority($bibnum);
+is($p, 1, 'CalculatePriority  should now return priority 1');
+#add a new reserve and confirm it to waiting
+AddReserve('CPL',  $requesters{'CPL'}, $bibnum,
+           $constraint, $bibitems,  $p, $resdate, $expdate, $notes,
+           $title,      $itemnumber, $found);
+$p = C4::Reserves::CalculatePriority($bibnum);
+is($p, 2, 'CalculatePriority  should now return priority 2');
+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,
+           $constraint, $bibitems,  $p, $resdate, $expdate, $notes,
+           $title,      $checkitem, $found);
+$p = C4::Reserves::CalculatePriority($bibnum);
+is($p, 2, 'CalculatePriority  should now return priority 2');
+#add another future hold
+C4::Context->set_preference('AllowHoldDateInFuture', 1);
+$resdate= dt_from_string();
+$resdate->add_duration(DateTime::Duration->new(days => 1));
+$resdate=output_pref($resdate);
+AddReserve('CPL',  $requesters{'CPL'}, $bibnum,
+           $constraint, $bibitems,  $p, $resdate, $expdate, $notes,
+           $title,      $checkitem, $found);
+$p = C4::Reserves::CalculatePriority($bibnum);
+is($p, 2, 'CalculatePriority  should now still return priority 2');
+#calc priority with future resdate
+$p = C4::Reserves::CalculatePriority($bibnum, $resdate);
+is($p, 3, 'CalculatePriority  should now return priority 3');
 # End of tests for bug 8918
 
 $dbh->rollback;
-- 
1.7.7.6