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;
"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;