Bug 7288: (follow-up) set a boolean if the invoice if linked to subscriptions
[koha_fer] / t / db_dependent / Reserves.t
index 31708c2..af9d7a9 100755 (executable)
@@ -2,7 +2,8 @@
 
 use Modern::Perl;
 
-use Test::More tests => 31;
+use Test::More tests => 35;
+
 use MARC::Record;
 use DateTime::Duration;
 
@@ -15,6 +16,7 @@ use t::lib::Mocks;
 
 use Koha::DateUtils;
 
+use Data::Dumper;
 BEGIN {
     use_ok('C4::Reserves');
 }
@@ -46,10 +48,18 @@ foreach my $addcat ('S', 'PT') {
 diag("\nCreating biblio instance for testing.");
 my $bib = MARC::Record->new();
 my $title = 'Silence in the library';
-$bib->append_fields(
-    MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
-    MARC::Field->new('245', ' ', ' ', a => $title),
-);
+if( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
+    $bib->append_fields(
+        MARC::Field->new('600', '', '1', a => 'Moffat, Steven'),
+        MARC::Field->new('200', '', '', a => $title),
+    );
+}
+else {
+    $bib->append_fields(
+        MARC::Field->new('100', '', '', a => 'Moffat, Steven'),
+        MARC::Field->new('245', '', '', a => $title),
+    );
+}
 my ($bibnum, $bibitemnum);
 ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
 
@@ -93,6 +103,8 @@ my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode);
 
 is($status, "Reserved", "CheckReserves Test 1");
 
+ok(exists($reserve->{reserve_id}), 'CheckReserves() include reserve_id in its response');
+
 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
 is($status, "Reserved", "CheckReserves Test 2");
 
@@ -191,6 +203,30 @@ my ($itemnum_cpl, $itemnum_fpl);
         barcode => 'bug10272_FPL'
     } , $bibnum2);
 
+# Ensure that priorities are numbered correcly when a hold is moved to waiting
+# (bug 11947)
+$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
+AddReserve('RPL',  $requesters{'RPL'}, $bibnum2,
+           $constraint, $bibitems,  1, $resdate, $expdate, $notes,
+           $title,      $checkitem, $found);
+AddReserve('FPL',  $requesters{'FPL'}, $bibnum2,
+           $constraint, $bibitems,  2, $resdate, $expdate, $notes,
+           $title,      $checkitem, $found);
+AddReserve('CPL',  $requesters{'CPL'}, $bibnum2,
+           $constraint, $bibitems,  3, $resdate, $expdate, $notes,
+           $title,      $checkitem, $found);
+ModReserveAffect($itemnum_cpl, $requesters{'RPL'}, 0);
+
+# Now it should have different priorities.
+my $title_reserves = GetReservesFromBiblionumber({biblionumber => $bibnum2});
+# Sort by reserve number in case the database gives us oddly ordered results
+my @reserves = sort { $a->{reserve_id} <=> $b->{reserve_id} } @$title_reserves;
+is($reserves[0]{priority}, 0, 'Item is correctly waiting');
+is($reserves[1]{priority}, 1, 'Item is correctly priority 1');
+is($reserves[2]{priority}, 2, 'Item is correctly priority 2');
+
+
+$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
 AddReserve('RPL',  $requesters{'RPL'}, $bibnum2,
            $constraint, $bibitems,  1, $resdate, $expdate, $notes,
            $title,      $checkitem, $found);