Bug 12876: Improve unit tests for CanReserveBeCanceledFromOpac
authorJonathan Druart <jonathan.druart@biblibre.com>
Fri, 5 Sep 2014 15:40:05 +0000 (17:40 +0200)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Tue, 23 Sep 2014 23:46:57 +0000 (20:46 -0300)
This patch fix the subroutine name and add a restriction on the
arguments: both argument are mandatory!

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
C4/Reserves.pm
t/db_dependent/Reserves.t

index 4875c9c..7a075a4 100644 (file)
@@ -587,6 +587,7 @@ sub CanItemBeReserved{
 sub CanReserveBeCanceledFromOpac {
     my ($reserve_id, $borrowernumber) = @_;
 
+    return unless $reserve_id and $borrowernumber;
     my $reserve = GetReserve($reserve_id);
 
     return 0 unless $reserve->{borrowernumber} == $borrowernumber;
index 04a9819..c32ab70 100755 (executable)
@@ -2,7 +2,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 47;
+use Test::More tests => 50;
 
 use MARC::Record;
 use DateTime::Duration;
@@ -422,6 +422,20 @@ AddReserve('CPL',  $requesters{'CPL'}, $item_bibnum,
            $title,      $checkitem, '');
 my (undef, $canres, undef) = CheckReserves($itemnumber);
 
+is( CanReserveBeCanceledFromOpac(), undef,
+    'CanReserveBeCanceledFromOpac should return undef if called without any parameter'
+);
+is(
+    CanReserveBeCanceledFromOpac( $canres->{resserve_id} ),
+    undef,
+    'CanReserveBeCanceledFromOpac should return undef if called without the reserve_id'
+);
+is(
+    CanReserveBeCanceledFromOpac( undef, $requesters{CPL} ),
+    undef,
+    'CanReserveBeCanceledFromOpac should return undef if called without borrowernumber'
+);
+
 my $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{'CPL'});
 is($cancancel, 1, 'Can user cancel its own reserve');