From aa83c423a7e8ddbf1a5f8f58387ed5400cce9e97 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 17 Apr 2014 14:33:16 -0400 Subject: [PATCH] Bug 8735 [QA Followup] - Add Unit Tests Content-Type: text/plain; charset=utf-8 Signed-off-by: Marcel de Rooy --- t/db_dependent/Holds.t | 39 ++++++++++++++++++++++++++++++++++++++- 1 files changed, 38 insertions(+), 1 deletions(-) diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index d51dfdb..84f246f 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -6,11 +6,12 @@ use t::lib::Mocks; use C4::Context; use C4::Branch; -use Test::More tests => 32; +use Test::More tests => 35; use MARC::Record; use C4::Biblio; use C4::Items; use C4::Members; +use C4::Calendar; BEGIN { use FindBin; @@ -324,6 +325,42 @@ ok( "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)" ); +# Test CancelExpiredReserves +C4::Context->set_preference('ExpireReservesMaxPickUpDelay', 1); +C4::Context->set_preference('ReservesMaxPickUpDelay', 1); + +my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime(time); +$year += 1900; +$mon += 1; +$reserves = $dbh->selectall_arrayref('SELECT * FROM reserves', { Slice => {} }); +$reserve = $reserves->[0]; +my $calendar = C4::Calendar->new(branchcode => $reserve->{branchcode}); +$calendar->insert_single_holiday( + day => $mday, + month => $mon, + year => $year, + title => 'Test', + description => 'Test', +); +$reserve_id = $reserve->{reserve_id}; +$dbh->do("UPDATE reserves SET waitingdate = DATE_SUB( NOW(), INTERVAL 5 DAY ), found = 'W', priority = 0 WHERE reserve_id = ?", undef, $reserve_id ); +C4::Context->set_preference('ExpireReservesOnHolidays', 0); +CancelExpiredReserves(); +my $count = $dbh->selectrow_array("SELECT COUNT(*) FROM reserves WHERE reserve_id = ?", undef, $reserve_id ); +is( $count, 1, "Waiting reserve beyond max pickup delay *not* canceled on holiday" ); +C4::Context->set_preference('ExpireReservesOnHolidays', 1); +CancelExpiredReserves(); +$count = $dbh->selectrow_array("SELECT COUNT(*) FROM reserves WHERE reserve_id = ?", undef, $reserve_id ); +is( $count, 0, "Waiting reserve beyond max pickup delay canceled on holiday" ); + +# Test expirationdate +$reserve = $reserves->[1]; +$reserve_id = $reserve->{reserve_id}; +$dbh->do("UPDATE reserves SET expirationdate = DATE_SUB( NOW(), INTERVAL 1 DAY ) WHERE reserve_id = ?", undef, $reserve_id ); +CancelExpiredReserves(); +$count = $dbh->selectrow_array("SELECT COUNT(*) FROM reserves WHERE reserve_id = ?", undef, $reserve_id ); +is( $count, 0, "Reserve with manual expiration date canceled correctly" ); + # Helper method to set up a Biblio. sub create_helper_biblio { my $itemtype = shift; -- 1.7.7.6