Lines 399-407
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status},
Link Here
|
399 |
"CanItemBeReserved should use item home library rule when ReservesControlBranch set to 'ItemsHomeLibrary'"); |
399 |
"CanItemBeReserved should use item home library rule when ReservesControlBranch set to 'ItemsHomeLibrary'"); |
400 |
|
400 |
|
401 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem( |
401 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem( |
|
|
402 |
<<<<<<< HEAD |
402 |
{ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber); |
403 |
{ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber); |
403 |
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK', |
404 |
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK', |
404 |
"CanItemBeReserved should return 'OK'"); |
405 |
"CanItemBeReserved should return 'OK'"); |
|
|
406 |
======= |
407 |
{ homebranch => 'CPL', holdingbranch => 'CPL', itype => 'CAN' } , $bibnum); |
408 |
is(CanItemBeReserved($borrowernumbers[0], $itemnumber), 'OK', |
409 |
"CanItemBeReserved should returns 'OK'"); |
410 |
|
411 |
##Setting duration variables |
412 |
my $now = DateTime->now(); |
413 |
my $minus4days = DateTime::Duration->new(days => -4); |
414 |
my $minus1days = DateTime::Duration->new(days => -1); |
415 |
my $plus1days = DateTime::Duration->new(days => 1); |
416 |
my $plus4days = DateTime::Duration->new(days => 4); |
417 |
##Setting some test prerequisites testing environment |
418 |
C4::Context->set_preference( 'ExpireReservesMaxPickUpDelay', 1 ); |
419 |
setSimpleCircPolicy(); |
420 |
setCalendars(); |
421 |
#Running more tests |
422 |
testGetLastPickupDate(); |
423 |
testMoveWaitingdate(); |
424 |
testCancelExpiredReserves(); |
425 |
C4::Context->set_preference( 'ExpireReservesMaxPickUpDelay', 0 ); |
426 |
|
427 |
## Environment should be the following |
428 |
## Holidays: days from today; -2,-3,-4 |
429 |
sub testCancelExpiredReserves { |
430 |
$dbh->do('UPDATE issuingrules SET holdspickupwait = 1'); #Make holds problematize after 1 day |
431 |
|
432 |
$reserves = $dbh->selectall_arrayref('SELECT * FROM reserves WHERE found IS NULL', { Slice => {} }); |
433 |
$reserve = $reserves->[0]; |
434 |
#Catch this hold and make it Waiting for pickup today. |
435 |
C4::Reserves::ModReserveAffect( $reserve->{itemnumber}, $reserve->{borrowernumber} ); |
436 |
$reserve = C4::Reserves::GetReserve( $reserve->{reserve_id} ); #UPDATE DB changes to local scope. |
437 |
|
438 |
CancelExpiredReserves(); |
439 |
my $count = $dbh->selectrow_array("SELECT COUNT(*) FROM reserves WHERE reserve_id = ?", undef, $reserve->{reserve_id} ); |
440 |
is( $count, 1, "Waiting reserve with lastpickupdate for ".$reserve->{lastpickupdate}." not canceled" ); |
441 |
|
442 |
C4::Reserves::MoveWaitingdate( $reserve, DateTime::Duration->new(days => -4) ); |
443 |
CancelExpiredReserves(); |
444 |
$count = $dbh->selectrow_array("SELECT COUNT(*) FROM reserves WHERE reserve_id = ?", undef, $reserve->{reserve_id} ); |
445 |
is( $count, 0, "Waiting reserve with lastpickupdate for ".$reserve->{lastpickupdate}." totally canceled" ); |
446 |
|
447 |
# Test expirationdate |
448 |
$reserve = $reserves->[1]; |
449 |
$dbh->do("UPDATE reserves SET expirationdate = DATE_SUB( NOW(), INTERVAL 1 DAY ) WHERE reserve_id = ?", undef, $reserve->{reserve_id} ); |
450 |
CancelExpiredReserves(); |
451 |
$count = $dbh->selectrow_array("SELECT COUNT(*) FROM reserves WHERE reserve_id = ?", undef, $reserve->{reserve_id} ); |
452 |
is( $count, 0, "Reserve with manual expiration date canceled correctly" ); |
453 |
|
454 |
#This test verifies that reserves with holdspickupwait disabled are not ćanceled! |
455 |
$dbh->do('UPDATE issuingrules SET holdspickupwait = 0'); #Make holds never problematize |
456 |
$reserve = $reserves->[2]; |
457 |
#Catch this hold and make it Waiting for pickup today. |
458 |
C4::Reserves::ModReserveAffect( $reserve->{itemnumber}, $reserve->{borrowernumber} ); |
459 |
$reserve = C4::Reserves::GetReserve( $reserve->{reserve_id} ); #UPDATE DB changes to local scope. |
460 |
#Move the caught reserve 4 days to past and try to cancel it. |
461 |
C4::Reserves::MoveWaitingdate( $reserve, $minus4days ); |
462 |
CancelExpiredReserves(); |
463 |
$count = $dbh->selectrow_array("SELECT COUNT(*) FROM reserves WHERE reserve_id = ?", undef, $reserve->{reserve_id} ); |
464 |
is( $count, 1, "CancelExpiredReserves(): not canceling lastpickupdate-less hold." ); |
465 |
} |
466 |
|
467 |
## Environment should be the following |
468 |
## Holidays: days from today; -2,-3,-4 |
469 |
sub testMoveWaitingdate { |
470 |
$dbh->do('UPDATE issuingrules SET holdspickupwait = 1'); #Make holds problematize after 1 day |
471 |
|
472 |
$reserves = $dbh->selectall_arrayref('SELECT * FROM reserves WHERE found IS NULL', { Slice => {} }); #Get reserves not waiting for pickup |
473 |
$reserve = $reserves->[0]; |
474 |
|
475 |
C4::Reserves::ModReserveAffect( $reserve->{itemnumber}, $reserve->{borrowernumber} ); #Catch the reserve and put it to wait for pickup, now we get a waitingdate generated. |
476 |
|
477 |
C4::Reserves::MoveWaitingdate( $reserve, $minus1days ); |
478 |
$reserve = C4::Reserves::GetReserve( $reserve_id ); #UPDATE DB changes to local scope. Actually MoveWaitingdate already updates changes to DB, but just making sure it does. |
479 |
is( ($reserve->{waitingdate} eq $now->clone()->add_duration($minus1days)->ymd() && |
480 |
$reserve->{lastpickupdate} eq $now->ymd()), |
481 |
1, "MoveWaitingdate(): Moving to past"); |
482 |
C4::Reserves::MoveWaitingdate( $reserve, $plus1days ); |
483 |
|
484 |
C4::Reserves::MoveWaitingdate( $reserve, $plus4days ); |
485 |
$reserve = C4::Reserves::GetReserve( $reserve_id ); |
486 |
is( ($reserve->{waitingdate} eq $now->clone()->add_duration($plus4days)->ymd() && |
487 |
$reserve->{lastpickupdate} eq $now->clone()->add_duration($plus4days)->add_duration($plus1days)->ymd()), |
488 |
1, "MoveWaitingdate(): Moving to future"); |
489 |
C4::Reserves::MoveWaitingdate( $reserve, $minus4days ); |
490 |
} |
491 |
|
492 |
## Environment should be the following |
493 |
## Holidays: days from today; -2,-3,-4 |
494 |
sub testGetLastPickupDate { |
495 |
$dbh->do('UPDATE issuingrules SET holdspickupwait = 1'); #Make holds problematize after 1 day |
496 |
|
497 |
my $now = DateTime->now(); |
498 |
my $minus4days = DateTime::Duration->new(days => -4); |
499 |
my $minus1days = DateTime::Duration->new(days => -1); |
500 |
my $plus1days = DateTime::Duration->new(days => 1); |
501 |
my $plus4days = DateTime::Duration->new(days => 4); |
502 |
|
503 |
$reserves = $dbh->selectall_arrayref('SELECT * FROM reserves', { Slice => {} }); #Get reserves not waiting for pickup |
504 |
$reserve = $reserves->[0]; |
505 |
|
506 |
$reserve->{waitingdate} = $now->clone()->add_duration($minus4days)->ymd(); |
507 |
my $lastpickupdate = C4::Reserves::GetLastPickupDate( $reserve )->ymd(); |
508 |
$reserve = C4::Reserves::GetReserve( $reserve_id ); #UPDATE DB changes to local scope |
509 |
is( $lastpickupdate, $now->clone()->add_duration($minus1days)->ymd(), |
510 |
"GetLastPickupDate(): Calendar finds the next open day for lastpickupdate."); |
511 |
|
512 |
$reserve->{waitingdate} = $now->clone()->add_duration($minus1days)->ymd(); |
513 |
$lastpickupdate = C4::Reserves::GetLastPickupDate( $reserve )->ymd(); |
514 |
is( $lastpickupdate, $now->ymd(), |
515 |
"GetLastPickupDate(): Not using Calendar"); |
516 |
|
517 |
$reserve->{waitingdate} = $now->clone()->add_duration($plus4days)->ymd(); |
518 |
$lastpickupdate = C4::Reserves::GetLastPickupDate( $reserve )->ymd(); |
519 |
is( $lastpickupdate, $now->clone()->add_duration($plus4days)->add_duration($plus1days)->ymd(), |
520 |
"GetLastPickupDate(): Moving to future"); |
521 |
|
522 |
#This test catches moving lastpickupdate for each holiday, instead of just moving the last date to an open library day |
523 |
$dbh->do('UPDATE issuingrules SET holdspickupwait = 4'); #Make holds problematize after 4 days |
524 |
$reserve->{waitingdate} = $now->clone()->add_duration($minus4days)->ymd(); |
525 |
$lastpickupdate = C4::Reserves::GetLastPickupDate( $reserve )->ymd(); |
526 |
is( $lastpickupdate, $now->ymd(), |
527 |
"GetLastPickupDate(): Moving lastpickupdate over holidays, but not affected by them"); |
528 |
|
529 |
#This test verifies that this feature is disabled and an undef is returned |
530 |
$dbh->do('UPDATE issuingrules SET holdspickupwait = 0'); #Make holds never problematize |
531 |
$reserve->{waitingdate} = $now->clone()->add_duration($minus4days)->ymd(); |
532 |
$lastpickupdate = C4::Reserves::GetLastPickupDate( $reserve ); |
533 |
is( $reserve->{lastpickupdate}, undef, |
534 |
"GetLastPickupDate(): holdspickupwait disabled"); |
535 |
} |
536 |
>>>>>>> Bug 8367: How long is a hold waiting for pickup at a more granular level |
405 |
|
537 |
|
406 |
# Bug 12632 |
538 |
# Bug 12632 |
407 |
t::lib::Mocks::mock_preference( 'item-level_itypes', 1 ); |
539 |
t::lib::Mocks::mock_preference( 'item-level_itypes', 1 ); |
Lines 687-689
subtest 'CanItemBeReserved / holds_per_day tests' => sub {
Link Here
|
687 |
|
819 |
|
688 |
$schema->storage->txn_rollback; |
820 |
$schema->storage->txn_rollback; |
689 |
}; |
821 |
}; |
690 |
- |
822 |
|
|
|
823 |
# Helper method to set up a Biblio. |
824 |
sub create_helper_biblio { |
825 |
my $itemtype = $_[0] ? $_[0] : 'BK'; |
826 |
my $bib = MARC::Record->new(); |
827 |
my $title = 'Silence in the library'; |
828 |
$bib->append_fields( |
829 |
MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), |
830 |
MARC::Field->new('245', ' ', ' ', a => $title), |
831 |
MARC::Field->new('942', ' ', ' ', c => $itemtype), |
832 |
); |
833 |
return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, ''); |
834 |
} |
835 |
|
836 |
sub setSimpleCircPolicy { |
837 |
$dbh->do('DELETE FROM issuingrules'); |
838 |
$dbh->do( |
839 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, |
840 |
maxissueqty, issuelength, lengthunit, |
841 |
renewalsallowed, renewalperiod, |
842 |
norenewalbefore, auto_renew, |
843 |
fine, chargeperiod, holdspickupwait) |
844 |
VALUES (?, ?, ?, ?, |
845 |
?, ?, ?, |
846 |
?, ?, |
847 |
?, ?, |
848 |
?, ?, ? |
849 |
) |
850 |
}, |
851 |
{}, |
852 |
'*', '*', '*', 25, |
853 |
20, 14, 'days', |
854 |
1, 7, |
855 |
'', 0, |
856 |
.10, 1,1 |
857 |
); |
858 |
} |
859 |
|
860 |
###Set C4::Calendar and Koha::Calendar holidays for |
861 |
# today -2 days |
862 |
# today -3 days |
863 |
# today -4 days |
864 |
# |
865 |
## Koha::Calendar for caching purposes (supposedly) doesn't work from the DB in this script |
866 |
## So we must set the cache for Koha::calnder as well as the DB modifications for C4::Calendar. |
867 |
## When making date comparisons with Koha::Calendar, using DateTime::Set, DateTime-objects |
868 |
## need to match by the nanosecond and time_zone. |
869 |
sub setCalendars { |
870 |
|
871 |
##Set the C4::Calendar |
872 |
my $now = DateTime->now(time_zone => C4::Context->tz())->truncate(to => 'day'); |
873 |
my $c4calendar = C4::Calendar->new(branchcode => $reserve->{branchcode}); |
874 |
$now->add_duration( DateTime::Duration->new(days => -2) ); |
875 |
$c4calendar->insert_single_holiday( |
876 |
day => $now->day(), |
877 |
month => $now->month(), |
878 |
year => $now->year(), |
879 |
title => 'Test', |
880 |
description => 'Test', |
881 |
); |
882 |
$now->add_duration( DateTime::Duration->new(days => -1) ); |
883 |
$c4calendar->insert_single_holiday( |
884 |
day => $now->day(), |
885 |
month => $now->month(), |
886 |
year => $now->year(), |
887 |
title => 'Test', |
888 |
description => 'Test', |
889 |
); |
890 |
$now->add_duration( DateTime::Duration->new(days => -1) ); |
891 |
$c4calendar->insert_single_holiday( |
892 |
day => $now->day(), |
893 |
month => $now->month(), |
894 |
year => $now->year(), |
895 |
title => 'Test', |
896 |
description => 'Test', |
897 |
); |
898 |
|
899 |
#Set the Koha::Calendar |
900 |
my $kohaCalendar = Koha::Calendar->new(branchcode => $reserve->{branchcode}); |
901 |
$now = DateTime->now(time_zone => C4::Context->tz())->truncate(to => 'day'); |
902 |
$now->add_duration( DateTime::Duration->new(days => -2) ); |
903 |
$kohaCalendar->add_holiday( $now ); |
904 |
$now->add_duration( DateTime::Duration->new(days => -1) ); |
905 |
$kohaCalendar->add_holiday( $now ); |
906 |
$now->add_duration( DateTime::Duration->new(days => -1) ); |
907 |
$kohaCalendar->add_holiday( $now ); |
908 |
} |