Bug 21738: make call of CanBookBeReserved more safe
authorAlex Arnaud <alex.arnaud@biblibre.com>
Fri, 4 Jan 2019 15:33:39 +0000 (16:33 +0100)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 8 Feb 2019 20:44:07 +0000 (20:44 +0000)
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

C4/Reserves.pm
reserve/request.pl
t/db_dependent/Reserves.t

index 77880dc..974168f 100644 (file)
@@ -284,7 +284,7 @@ sub CanBookBeReserved{
         push (@itemnumbers, @hostitems);
     }
 
-    my $canReserve;
+    my $canReserve = { status => '' };
     foreach my $itemnumber (@itemnumbers) {
         $canReserve = CanItemBeReserved( $borrowernumber, $itemnumber, $pickup_branchcode );
         return { status => 'OK' } if $canReserve->{status} eq 'OK';
index 91b6ffd..2ef00c8 100755 (executable)
@@ -222,7 +222,6 @@ foreach my $biblionumber (@biblionumbers) {
     if ( $patron ) {
         { # CanBookBeReserved
             my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber );
-            $canReserve->{status} //= '';
             if ( $canReserve->{status} eq 'OK' ) {
 
                 #All is OK and we can continue
index 92f7303..5b4c681 100755 (executable)
@@ -17,7 +17,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 58;
+use Test::More tests => 59;
 use Test::MockModule;
 use Test::Warn;
 
@@ -90,6 +90,10 @@ my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
     $bibnum
 );
 
+my $biblio_with_no_item = $builder->build({
+    source => 'Biblio'
+});
+
 
 # Modify item; setting barcode.
 my $testbarcode = '97531';
@@ -511,6 +515,8 @@ $borrower->{dateofbirth} = DateTime->now->add( years => -30 );
 Koha::Patrons->find( $borrowernumber )->set({ dateofbirth => $borrower->{dateofbirth} })->store;
 
 is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber)->{status} , 'OK', "Reserving a 'PEGI 16' Biblio by a 30 year old borrower succeeds");
+
+is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_with_no_item->{biblionumber})->{status} , '', "Biblio with no item. Status is empty");
        ####
 ####### EO Bug 13113 <<<
        ####