From 9daef6fb5323c9a899da5241cfc0bf62ba4cb212 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 Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- 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 4875c9cfbc..7a075a44b9 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -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; diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 04a9819793..c32ab70e30 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -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'); -- 2.39.5