From c65a5d73a7678cb4757566181d566e903a264aee Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 25 Dec 2013 17:07:53 +0000 Subject: [PATCH] Bug 11338: add unit tests for DelItemCheck This patch adds unit tests for two parts of DelItemCheck: checking if the item is on loan, and checking if it is waiting on the hold shelf. To test: [1] Verify that prove -v t/db_dependent/Circulation/IsItemIssued.t is successful. [2] Verify that prove -v t/db_dependent/Reserves.t is *not* successful -- as it turns out, there was a latent bug where items waiting on the hold shelf or in transit to fill a hold could still be deleted without any warning. Signed-off-by: Galen Charlton (cherry picked from commit 18888359b6744a1e65e34649c927e7c146f628f8) Signed-off-by: Fridolin SOMERS --- t/db_dependent/Circulation/IsItemIssued.t | 17 ++++++++++++++++- t/db_dependent/Reserves.t | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Circulation/IsItemIssued.t b/t/db_dependent/Circulation/IsItemIssued.t index b9f3e2bf45..18ea9843c0 100644 --- a/t/db_dependent/Circulation/IsItemIssued.t +++ b/t/db_dependent/Circulation/IsItemIssued.t @@ -1,5 +1,5 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 5; use C4::Biblio; use C4::Circulation; @@ -35,6 +35,21 @@ is ( IsItemIssued( $item->{itemnumber} ), 0, "item is not on loan at first" ); AddIssue($borrower, 'i_dont_exist'); is ( IsItemIssued( $item->{itemnumber} ), 1, "item is now on loan" ); +is( + DelItemCheck($dbh, $biblionumber, $itemnumber), + 'book_on_loan', + 'item that is on loan cannot be deleted', +); + +AddReturn('i_dont_exist', 'CPL'); +is ( IsItemIssued( $item->{itemnumber} ), 0, "item has been returned" ); + +is( + DelItemCheck($dbh, $biblionumber, $itemnumber), + 1, + 'item that is not on loan can be deleted', +); + $dbh->rollback; # C4::Context->userenv diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index ad50619d31..6906120754 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -2,7 +2,7 @@ use Modern::Perl; -use Test::More tests => 17; +use Test::More tests => 18; use MARC::Record; use DateTime::Duration; @@ -18,6 +18,11 @@ BEGIN { use_ok('C4::Reserves'); } +# a very minimal mack of userenv for use by the test of DelItemCheck +*C4::Context::userenv = sub { + return {}; +}; + my $dbh = C4::Context->dbh; # Start transaction @@ -263,6 +268,15 @@ is(exists $messages->{ResFound}?1:0, 1, 'AddReturn considers future reserve with # End of tests for bug 9761 (ConfirmFutureHolds) +# test marking a hold as captured +ModReserveAffect($itemnumber, $requesters{'CPL'}, 0); + +is( + DelItemCheck($dbh, $bibnum, $itemnumber), + 'book_reserved', + 'item that is capture to fill a hold cannot be deleted', +); + my $letter = ReserveSlip('CPL', $requesters{'CPL'}, $bibnum); ok(defined($letter), 'can successfully generate hold slip (bug 10949)'); -- 2.39.5