|
Lines 7-13
use t::lib::TestBuilder;
Link Here
|
| 7 |
|
7 |
|
| 8 |
use C4::Context; |
8 |
use C4::Context; |
| 9 |
|
9 |
|
| 10 |
use Test::More tests => 56; |
10 |
use Test::More tests => 59; |
| 11 |
use MARC::Record; |
11 |
use MARC::Record; |
| 12 |
use Koha::Patrons; |
12 |
use Koha::Patrons; |
| 13 |
use C4::Items; |
13 |
use C4::Items; |
|
Lines 382-390
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status},
Link Here
|
| 382 |
"CanItemBeReserved should return 'cannotReserveFromOtherBranches'"); |
382 |
"CanItemBeReserved should return 'cannotReserveFromOtherBranches'"); |
| 383 |
|
383 |
|
| 384 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem( |
384 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem( |
| 385 |
{ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $bibnum); |
385 |
{ homebranch => 'CPL', holdingbranch => 'CPL', itype => 'CAN' } , $bibnum); |
| 386 |
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK', |
386 |
is(CanItemBeReserved($borrowernumbers[0], $itemnumber), 'OK', |
| 387 |
"CanItemBeReserved should return 'OK'"); |
387 |
"CanItemBeReserved should returns 'OK'"); |
|
|
388 |
|
| 389 |
##Setting duration variables |
| 390 |
my $now = DateTime->now(); |
| 391 |
my $minus4days = DateTime::Duration->new(days => -4); |
| 392 |
my $minus1days = DateTime::Duration->new(days => -1); |
| 393 |
my $plus1days = DateTime::Duration->new(days => 1); |
| 394 |
my $plus4days = DateTime::Duration->new(days => 4); |
| 395 |
##Setting some test prerequisites testing environment |
| 396 |
C4::Context->set_preference( 'ExpireReservesMaxPickUpDelay', 1 ); |
| 397 |
setSimpleCircPolicy(); |
| 398 |
setCalendars(); |
| 399 |
#Running more tests |
| 400 |
testGetLastPickupDate(); |
| 401 |
testMoveWaitingdate(); |
| 402 |
testCancelExpiredReserves(); |
| 403 |
C4::Context->set_preference( 'ExpireReservesMaxPickUpDelay', 0 ); |
| 404 |
|
| 405 |
## Environment should be the following |
| 406 |
## Holidays: days from today; -2,-3,-4 |
| 407 |
sub testCancelExpiredReserves { |
| 408 |
$dbh->do('UPDATE issuingrules SET holdspickupwait = 1'); #Make holds problematize after 1 day |
| 409 |
|
| 410 |
$reserves = $dbh->selectall_arrayref('SELECT * FROM reserves WHERE found IS NULL', { Slice => {} }); |
| 411 |
$reserve = $reserves->[0]; |
| 412 |
#Catch this hold and make it Waiting for pickup today. |
| 413 |
C4::Reserves::ModReserveAffect( $reserve->{itemnumber}, $reserve->{borrowernumber} ); |
| 414 |
$reserve = C4::Reserves::GetReserve( $reserve->{reserve_id} ); #UPDATE DB changes to local scope. |
| 415 |
|
| 416 |
CancelExpiredReserves(); |
| 417 |
my $count = $dbh->selectrow_array("SELECT COUNT(*) FROM reserves WHERE reserve_id = ?", undef, $reserve->{reserve_id} ); |
| 418 |
is( $count, 1, "Waiting reserve with lastpickupdate for ".$reserve->{lastpickupdate}." not canceled" ); |
| 419 |
|
| 420 |
C4::Reserves::MoveWaitingdate( $reserve, DateTime::Duration->new(days => -4) ); |
| 421 |
CancelExpiredReserves(); |
| 422 |
$count = $dbh->selectrow_array("SELECT COUNT(*) FROM reserves WHERE reserve_id = ?", undef, $reserve->{reserve_id} ); |
| 423 |
is( $count, 0, "Waiting reserve with lastpickupdate for ".$reserve->{lastpickupdate}." totally canceled" ); |
| 424 |
|
| 425 |
# Test expirationdate |
| 426 |
$reserve = $reserves->[1]; |
| 427 |
$dbh->do("UPDATE reserves SET expirationdate = DATE_SUB( NOW(), INTERVAL 1 DAY ) WHERE reserve_id = ?", undef, $reserve->{reserve_id} ); |
| 428 |
CancelExpiredReserves(); |
| 429 |
$count = $dbh->selectrow_array("SELECT COUNT(*) FROM reserves WHERE reserve_id = ?", undef, $reserve->{reserve_id} ); |
| 430 |
is( $count, 0, "Reserve with manual expiration date canceled correctly" ); |
| 431 |
|
| 432 |
#This test verifies that reserves with holdspickupwait disabled are not ćanceled! |
| 433 |
$dbh->do('UPDATE issuingrules SET holdspickupwait = 0'); #Make holds never problematize |
| 434 |
$reserve = $reserves->[2]; |
| 435 |
#Catch this hold and make it Waiting for pickup today. |
| 436 |
C4::Reserves::ModReserveAffect( $reserve->{itemnumber}, $reserve->{borrowernumber} ); |
| 437 |
$reserve = C4::Reserves::GetReserve( $reserve->{reserve_id} ); #UPDATE DB changes to local scope. |
| 438 |
#Move the caught reserve 4 days to past and try to cancel it. |
| 439 |
C4::Reserves::MoveWaitingdate( $reserve, $minus4days ); |
| 440 |
CancelExpiredReserves(); |
| 441 |
$count = $dbh->selectrow_array("SELECT COUNT(*) FROM reserves WHERE reserve_id = ?", undef, $reserve->{reserve_id} ); |
| 442 |
is( $count, 1, "CancelExpiredReserves(): not canceling lastpickupdate-less hold." ); |
| 443 |
} |
| 444 |
|
| 445 |
## Environment should be the following |
| 446 |
## Holidays: days from today; -2,-3,-4 |
| 447 |
sub testMoveWaitingdate { |
| 448 |
$dbh->do('UPDATE issuingrules SET holdspickupwait = 1'); #Make holds problematize after 1 day |
| 449 |
|
| 450 |
$reserves = $dbh->selectall_arrayref('SELECT * FROM reserves WHERE found IS NULL', { Slice => {} }); #Get reserves not waiting for pickup |
| 451 |
$reserve = $reserves->[0]; |
| 452 |
|
| 453 |
C4::Reserves::ModReserveAffect( $reserve->{itemnumber}, $reserve->{borrowernumber} ); #Catch the reserve and put it to wait for pickup, now we get a waitingdate generated. |
| 454 |
|
| 455 |
C4::Reserves::MoveWaitingdate( $reserve, $minus1days ); |
| 456 |
$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. |
| 457 |
is( ($reserve->{waitingdate} eq $now->clone()->add_duration($minus1days)->ymd() && |
| 458 |
$reserve->{lastpickupdate} eq $now->ymd()), |
| 459 |
1, "MoveWaitingdate(): Moving to past"); |
| 460 |
C4::Reserves::MoveWaitingdate( $reserve, $plus1days ); |
| 461 |
|
| 462 |
C4::Reserves::MoveWaitingdate( $reserve, $plus4days ); |
| 463 |
$reserve = C4::Reserves::GetReserve( $reserve_id ); |
| 464 |
is( ($reserve->{waitingdate} eq $now->clone()->add_duration($plus4days)->ymd() && |
| 465 |
$reserve->{lastpickupdate} eq $now->clone()->add_duration($plus4days)->add_duration($plus1days)->ymd()), |
| 466 |
1, "MoveWaitingdate(): Moving to future"); |
| 467 |
C4::Reserves::MoveWaitingdate( $reserve, $minus4days ); |
| 468 |
} |
| 469 |
|
| 470 |
## Environment should be the following |
| 471 |
## Holidays: days from today; -2,-3,-4 |
| 472 |
sub testGetLastPickupDate { |
| 473 |
$dbh->do('UPDATE issuingrules SET holdspickupwait = 1'); #Make holds problematize after 1 day |
| 474 |
|
| 475 |
my $now = DateTime->now(); |
| 476 |
my $minus4days = DateTime::Duration->new(days => -4); |
| 477 |
my $minus1days = DateTime::Duration->new(days => -1); |
| 478 |
my $plus1days = DateTime::Duration->new(days => 1); |
| 479 |
my $plus4days = DateTime::Duration->new(days => 4); |
| 480 |
|
| 481 |
$reserves = $dbh->selectall_arrayref('SELECT * FROM reserves', { Slice => {} }); #Get reserves not waiting for pickup |
| 482 |
$reserve = $reserves->[0]; |
| 483 |
|
| 484 |
$reserve->{waitingdate} = $now->clone()->add_duration($minus4days)->ymd(); |
| 485 |
my $lastpickupdate = C4::Reserves::GetLastPickupDate( $reserve )->ymd(); |
| 486 |
$reserve = C4::Reserves::GetReserve( $reserve_id ); #UPDATE DB changes to local scope |
| 487 |
is( $lastpickupdate, $now->clone()->add_duration($minus1days)->ymd(), |
| 488 |
"GetLastPickupDate(): Calendar finds the next open day for lastpickupdate."); |
| 489 |
|
| 490 |
$reserve->{waitingdate} = $now->clone()->add_duration($minus1days)->ymd(); |
| 491 |
$lastpickupdate = C4::Reserves::GetLastPickupDate( $reserve )->ymd(); |
| 492 |
is( $lastpickupdate, $now->ymd(), |
| 493 |
"GetLastPickupDate(): Not using Calendar"); |
| 494 |
|
| 495 |
$reserve->{waitingdate} = $now->clone()->add_duration($plus4days)->ymd(); |
| 496 |
$lastpickupdate = C4::Reserves::GetLastPickupDate( $reserve )->ymd(); |
| 497 |
is( $lastpickupdate, $now->clone()->add_duration($plus4days)->add_duration($plus1days)->ymd(), |
| 498 |
"GetLastPickupDate(): Moving to future"); |
| 499 |
|
| 500 |
#This test catches moving lastpickupdate for each holiday, instead of just moving the last date to an open library day |
| 501 |
$dbh->do('UPDATE issuingrules SET holdspickupwait = 4'); #Make holds problematize after 4 days |
| 502 |
$reserve->{waitingdate} = $now->clone()->add_duration($minus4days)->ymd(); |
| 503 |
$lastpickupdate = C4::Reserves::GetLastPickupDate( $reserve )->ymd(); |
| 504 |
is( $lastpickupdate, $now->ymd(), |
| 505 |
"GetLastPickupDate(): Moving lastpickupdate over holidays, but not affected by them"); |
| 506 |
|
| 507 |
#This test verifies that this feature is disabled and an undef is returned |
| 508 |
$dbh->do('UPDATE issuingrules SET holdspickupwait = 0'); #Make holds never problematize |
| 509 |
$reserve->{waitingdate} = $now->clone()->add_duration($minus4days)->ymd(); |
| 510 |
$lastpickupdate = C4::Reserves::GetLastPickupDate( $reserve ); |
| 511 |
is( $reserve->{lastpickupdate}, undef, |
| 512 |
"GetLastPickupDate(): holdspickupwait disabled"); |
| 513 |
} |
| 388 |
|
514 |
|
| 389 |
# Bug 12632 |
515 |
# Bug 12632 |
| 390 |
t::lib::Mocks::mock_preference( 'item-level_itypes', 1 ); |
516 |
t::lib::Mocks::mock_preference( 'item-level_itypes', 1 ); |
|
Lines 513-519
subtest 'Pickup location availability tests' => sub {
Link Here
|
| 513 |
|
639 |
|
| 514 |
# Helper method to set up a Biblio. |
640 |
# Helper method to set up a Biblio. |
| 515 |
sub create_helper_biblio { |
641 |
sub create_helper_biblio { |
| 516 |
my $itemtype = shift; |
642 |
my $itemtype = $_[0] ? $_[0] : 'BK'; |
| 517 |
my $bib = MARC::Record->new(); |
643 |
my $bib = MARC::Record->new(); |
| 518 |
my $title = 'Silence in the library'; |
644 |
my $title = 'Silence in the library'; |
| 519 |
$bib->append_fields( |
645 |
$bib->append_fields( |
|
Lines 523-525
sub create_helper_biblio {
Link Here
|
| 523 |
); |
649 |
); |
| 524 |
return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, ''); |
650 |
return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, ''); |
| 525 |
} |
651 |
} |
| 526 |
- |
652 |
|
|
|
653 |
sub setSimpleCircPolicy { |
| 654 |
$dbh->do('DELETE FROM issuingrules'); |
| 655 |
$dbh->do( |
| 656 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, |
| 657 |
maxissueqty, issuelength, lengthunit, |
| 658 |
renewalsallowed, renewalperiod, |
| 659 |
norenewalbefore, auto_renew, |
| 660 |
fine, chargeperiod, holdspickupwait) |
| 661 |
VALUES (?, ?, ?, ?, |
| 662 |
?, ?, ?, |
| 663 |
?, ?, |
| 664 |
?, ?, |
| 665 |
?, ?, ? |
| 666 |
) |
| 667 |
}, |
| 668 |
{}, |
| 669 |
'*', '*', '*', 25, |
| 670 |
20, 14, 'days', |
| 671 |
1, 7, |
| 672 |
'', 0, |
| 673 |
.10, 1,1 |
| 674 |
); |
| 675 |
} |
| 676 |
|
| 677 |
###Set C4::Calendar and Koha::Calendar holidays for |
| 678 |
# today -2 days |
| 679 |
# today -3 days |
| 680 |
# today -4 days |
| 681 |
# |
| 682 |
## Koha::Calendar for caching purposes (supposedly) doesn't work from the DB in this script |
| 683 |
## So we must set the cache for Koha::calnder as well as the DB modifications for C4::Calendar. |
| 684 |
## When making date comparisons with Koha::Calendar, using DateTime::Set, DateTime-objects |
| 685 |
## need to match by the nanosecond and time_zone. |
| 686 |
sub setCalendars { |
| 687 |
|
| 688 |
##Set the C4::Calendar |
| 689 |
my $now = DateTime->now(time_zone => C4::Context->tz())->truncate(to => 'day'); |
| 690 |
my $c4calendar = C4::Calendar->new(branchcode => $reserve->{branchcode}); |
| 691 |
$now->add_duration( DateTime::Duration->new(days => -2) ); |
| 692 |
$c4calendar->insert_single_holiday( |
| 693 |
day => $now->day(), |
| 694 |
month => $now->month(), |
| 695 |
year => $now->year(), |
| 696 |
title => 'Test', |
| 697 |
description => 'Test', |
| 698 |
); |
| 699 |
$now->add_duration( DateTime::Duration->new(days => -1) ); |
| 700 |
$c4calendar->insert_single_holiday( |
| 701 |
day => $now->day(), |
| 702 |
month => $now->month(), |
| 703 |
year => $now->year(), |
| 704 |
title => 'Test', |
| 705 |
description => 'Test', |
| 706 |
); |
| 707 |
$now->add_duration( DateTime::Duration->new(days => -1) ); |
| 708 |
$c4calendar->insert_single_holiday( |
| 709 |
day => $now->day(), |
| 710 |
month => $now->month(), |
| 711 |
year => $now->year(), |
| 712 |
title => 'Test', |
| 713 |
description => 'Test', |
| 714 |
); |
| 715 |
|
| 716 |
#Set the Koha::Calendar |
| 717 |
my $kohaCalendar = Koha::Calendar->new(branchcode => $reserve->{branchcode}); |
| 718 |
$now = DateTime->now(time_zone => C4::Context->tz())->truncate(to => 'day'); |
| 719 |
$now->add_duration( DateTime::Duration->new(days => -2) ); |
| 720 |
$kohaCalendar->add_holiday( $now ); |
| 721 |
$now->add_duration( DateTime::Duration->new(days => -1) ); |
| 722 |
$kohaCalendar->add_holiday( $now ); |
| 723 |
$now->add_duration( DateTime::Duration->new(days => -1) ); |
| 724 |
$kohaCalendar->add_holiday( $now ); |
| 725 |
} |