From 4ce29452ad4839b6672126204ee867b10c28ca61 Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Tue, 7 Jul 2015 13:02:18 -0600 Subject: [PATCH] Bug 14464: (QA followup) add unit tests This followup adds several tests to t/db_dependent/Reserves.t. Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- C4/Reserves.pm | 2 +- t/db_dependent/Reserves.t | 81 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 96570df58f..2beea87b11 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -241,7 +241,7 @@ sub AddReserve { } #} - ($const eq "o" || $const eq "e") or return; # FIXME: why not have a useful return value? + ($const eq "o" || $const eq "e") or return $reserve_id; $query = qq{ INSERT INTO reserveconstraints (borrowernumber,biblionumber,reservedate,biblioitemnumber) diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 340b7bf2ad..3ed904cd0d 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 58; +use Test::More tests => 65; use MARC::Record; use DateTime::Duration; @@ -533,6 +533,85 @@ $dbh->do( ); ok( !C4::Reserves::OnShelfHoldsAllowed($item, $borrower), "OnShelfHoldsAllowed() disallowed" ); +# Tests for bug 14464 + +$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum)); +my ( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber ); +ok( !$bz14464_fines, 'Bug 14464 - No fines at beginning' ); + +# First, test cancelling a reserve when there's no charge configured. +t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 0); + +my $bz14464_reserve = AddReserve( + 'CPL', + $borrowernumber, + $bibnum, + 'a', + undef, + '1', + undef, + undef, + '', + $title, + $itemnumber, + 'W' +); + +ok( $bz14464_reserve, 'Bug 14464 - 1st reserve correctly created' ); + +CancelReserve({ reserve_id => $bz14464_reserve, charge_cancel_fee => 1 }); + +( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber ); +ok( !$bz14464_fines, 'Bug 14464 - No fines after cancelling reserve with no charge configured' ); + +# Then, test cancelling a reserve when there's no charge desired. +t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 42); + +$bz14464_reserve = AddReserve( + 'CPL', + $borrowernumber, + $bibnum, + 'a', + undef, + '1', + undef, + undef, + '', + $title, + $itemnumber, + 'W' +); + +ok( $bz14464_reserve, 'Bug 14464 - 2nd reserve correctly created' ); + +CancelReserve({ reserve_id => $bz14464_reserve }); + +( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber ); +ok( !$bz14464_fines, 'Bug 14464 - No fines after cancelling reserve with no charge desired' ); + +# Finally, test cancelling a reserve when there's a charge desired and configured. +$bz14464_reserve = AddReserve( + 'CPL', + $borrowernumber, + $bibnum, + 'a', + undef, + '1', + undef, + undef, + '', + $title, + $itemnumber, + 'W' +); + +ok( $bz14464_reserve, 'Bug 14464 - 1st reserve correctly created' ); + +CancelReserve({ reserve_id => $bz14464_reserve, charge_cancel_fee => 1 }); + +( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber ); +is( int( $bz14464_fines ), 42, 'Bug 14464 - Fine applied after cancelling reserve with charge desired and configured' ); + $dbh->rollback; sub count_hold_print_messages { -- 2.39.5