From abe7cf2c32ab289a97aa9c7cc8e93dd97e2d408f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 5 Sep 2014 17:40:05 +0200 Subject: [PATCH] Bug 12876: Improve unit tests for CanReserveBeCanceledFromOpac This patch fix the subroutine name and add a restriction on the arguments: both argument are mandatory! Signed-off-by: Jonathan Druart --- C4/Reserves.pm | 1 + t/db_dependent/Reserves.t | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 54b674d..c6bc35f 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -571,6 +571,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; diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index ed7e31e..707d57b 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -2,7 +2,7 @@ use Modern::Perl; -use Test::More tests => 39; +use Test::More tests => 42; use MARC::Record; use DateTime::Duration; @@ -402,6 +402,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'); -- 2.1.0