|
Lines 310-316
subtest "CanBookBeRenewed AllowRenewalIfOtherItemsAvailable multiple borrowers a
Link Here
|
| 310 |
); |
310 |
); |
| 311 |
|
311 |
|
| 312 |
# Patrons from three different branches |
312 |
# Patrons from three different branches |
| 313 |
my $patron_borrower = $builder->build_object({ class => 'Koha::Patrons' }); |
313 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
| 314 |
my $patron_hold_1 = $builder->build_object({ class => 'Koha::Patrons' }); |
314 |
my $patron_hold_1 = $builder->build_object({ class => 'Koha::Patrons' }); |
| 315 |
my $patron_hold_2 = $builder->build_object({ class => 'Koha::Patrons' }); |
315 |
my $patron_hold_2 = $builder->build_object({ class => 'Koha::Patrons' }); |
| 316 |
my $biblio = $builder->build_sample_biblio(); |
316 |
my $biblio = $builder->build_sample_biblio(); |
|
Lines 318-324
subtest "CanBookBeRenewed AllowRenewalIfOtherItemsAvailable multiple borrowers a
Link Here
|
| 318 |
# Item at each patron branch |
318 |
# Item at each patron branch |
| 319 |
my $item_1 = $builder->build_sample_item({ |
319 |
my $item_1 = $builder->build_sample_item({ |
| 320 |
biblionumber => $biblio->biblionumber, |
320 |
biblionumber => $biblio->biblionumber, |
| 321 |
homebranch => $patron_borrower->branchcode |
321 |
homebranch => $patron->branchcode |
| 322 |
}); |
322 |
}); |
| 323 |
my $item_2 = $builder->build_sample_item({ |
323 |
my $item_2 = $builder->build_sample_item({ |
| 324 |
biblionumber => $biblio->biblionumber, |
324 |
biblionumber => $biblio->biblionumber, |
|
Lines 329-335
subtest "CanBookBeRenewed AllowRenewalIfOtherItemsAvailable multiple borrowers a
Link Here
|
| 329 |
homebranch => $patron_hold_1->branchcode |
329 |
homebranch => $patron_hold_1->branchcode |
| 330 |
}); |
330 |
}); |
| 331 |
|
331 |
|
| 332 |
my $issue = AddIssue( $patron_borrower->unblessed, $item_1->barcode); |
332 |
my $issue = AddIssue( $patron->unblessed, $item_1->barcode); |
| 333 |
my $datedue = dt_from_string( $issue->date_due() ); |
333 |
my $datedue = dt_from_string( $issue->date_due() ); |
| 334 |
is (defined $issue->date_due(), 1, "Item 1 checked out, due date: " . $issue->date_due() ); |
334 |
is (defined $issue->date_due(), 1, "Item 1 checked out, due date: " . $issue->date_due() ); |
| 335 |
|
335 |
|
|
Lines 360-372
subtest "CanBookBeRenewed AllowRenewalIfOtherItemsAvailable multiple borrowers a
Link Here
|
| 360 |
); |
360 |
); |
| 361 |
t::lib::Mocks::mock_preference('AllowRenewalIfOtherItemsAvailable', 0 ); |
361 |
t::lib::Mocks::mock_preference('AllowRenewalIfOtherItemsAvailable', 0 ); |
| 362 |
|
362 |
|
| 363 |
my ( $renewokay, $error ) = CanBookBeRenewed($patron_borrower->borrowernumber, $item_1->itemnumber); |
363 |
my ( $renewokay, $error ) = CanBookBeRenewed($patron, $issue); |
| 364 |
is( $renewokay, 0, 'Cannot renew, reserved'); |
364 |
is( $renewokay, 0, 'Cannot renew, reserved'); |
| 365 |
is( $error, 'on_reserve', 'Cannot renew, reserved (returned error is on_reserve)'); |
365 |
is( $error, 'on_reserve', 'Cannot renew, reserved (returned error is on_reserve)'); |
| 366 |
|
366 |
|
| 367 |
t::lib::Mocks::mock_preference('AllowRenewalIfOtherItemsAvailable', 1 ); |
367 |
t::lib::Mocks::mock_preference('AllowRenewalIfOtherItemsAvailable', 1 ); |
| 368 |
|
368 |
|
| 369 |
( $renewokay, $error ) = CanBookBeRenewed($patron_borrower->borrowernumber, $item_1->itemnumber); |
369 |
( $renewokay, $error ) = CanBookBeRenewed($patron, $issue); |
| 370 |
is( $renewokay, 1, 'Can renew, two items available for two holds'); |
370 |
is( $renewokay, 1, 'Can renew, two items available for two holds'); |
| 371 |
is( $error, undef, 'Can renew, each reserve has an item'); |
371 |
is( $error, undef, 'Can renew, each reserve has an item'); |
| 372 |
|
372 |
|
|
Lines 374-383
subtest "CanBookBeRenewed AllowRenewalIfOtherItemsAvailable multiple borrowers a
Link Here
|
| 374 |
my $hold = Koha::Holds->find( $reserve_1 ); |
374 |
my $hold = Koha::Holds->find( $reserve_1 ); |
| 375 |
$hold->itemnumber( $item_1->itemnumber )->store; |
375 |
$hold->itemnumber( $item_1->itemnumber )->store; |
| 376 |
|
376 |
|
| 377 |
( $renewokay, $error ) = CanBookBeRenewed($patron_borrower->borrowernumber, $item_1->itemnumber); |
377 |
( $renewokay, $error ) = CanBookBeRenewed($patron, $issue); |
| 378 |
is( $renewokay, 0, 'Cannot renew when there is an item specific hold'); |
378 |
is( $renewokay, 0, 'Cannot renew when there is an item specific hold'); |
| 379 |
is( $error, 'on_reserve', 'Cannot renew, only this item can fill the reserve'); |
379 |
is( $error, 'on_reserve', 'Cannot renew, only this item can fill the reserve'); |
| 380 |
|
|
|
| 381 |
}; |
380 |
}; |
| 382 |
|
381 |
|
| 383 |
subtest "GetIssuingCharges tests" => sub { |
382 |
subtest "GetIssuingCharges tests" => sub { |
|
Lines 470-475
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 470 |
surname => 'Renewal', |
469 |
surname => 'Renewal', |
| 471 |
categorycode => $patron_category->{categorycode}, |
470 |
categorycode => $patron_category->{categorycode}, |
| 472 |
branchcode => $branch, |
471 |
branchcode => $branch, |
|
|
472 |
autorenew_checkouts => 1, |
| 473 |
); |
473 |
); |
| 474 |
|
474 |
|
| 475 |
my %reserving_borrower_data = ( |
475 |
my %reserving_borrower_data = ( |
|
Lines 500-517
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 500 |
categorycode => $patron_category->{categorycode}, |
500 |
categorycode => $patron_category->{categorycode}, |
| 501 |
branchcode => $branch, |
501 |
branchcode => $branch, |
| 502 |
dateexpiry => dt_from_string->subtract( months => 1 ), |
502 |
dateexpiry => dt_from_string->subtract( months => 1 ), |
|
|
503 |
autorenew_checkouts => 1, |
| 503 |
); |
504 |
); |
| 504 |
|
505 |
|
| 505 |
my $renewing_borrowernumber = Koha::Patron->new(\%renewing_borrower_data)->store->borrowernumber; |
506 |
my $renewing_borrower_obj = Koha::Patron->new(\%renewing_borrower_data)->store; |
|
|
507 |
my $renewing_borrowernumber = $renewing_borrower_obj->borrowernumber; |
| 506 |
my $reserving_borrowernumber = Koha::Patron->new(\%reserving_borrower_data)->store->borrowernumber; |
508 |
my $reserving_borrowernumber = Koha::Patron->new(\%reserving_borrower_data)->store->borrowernumber; |
| 507 |
my $hold_waiting_borrowernumber = Koha::Patron->new(\%hold_waiting_borrower_data)->store->borrowernumber; |
509 |
my $hold_waiting_borrowernumber = Koha::Patron->new(\%hold_waiting_borrower_data)->store->borrowernumber; |
| 508 |
my $restricted_borrowernumber = Koha::Patron->new(\%restricted_borrower_data)->store->borrowernumber; |
510 |
my $restricted_borrower_obj = Koha::Patron->new(\%restricted_borrower_data)->store; |
| 509 |
my $expired_borrowernumber = Koha::Patron->new(\%expired_borrower_data)->store->borrowernumber; |
|
|
| 510 |
|
511 |
|
| 511 |
my $renewing_borrower_obj = Koha::Patrons->find( $renewing_borrowernumber ); |
512 |
my $expired_borrower_obj = Koha::Patron->new(\%expired_borrower_data)->store; |
| 512 |
my $renewing_borrower = $renewing_borrower_obj->unblessed; |
|
|
| 513 |
my $restricted_borrower = Koha::Patrons->find( $restricted_borrowernumber )->unblessed; |
| 514 |
my $expired_borrower = Koha::Patrons->find( $expired_borrowernumber )->unblessed; |
| 515 |
|
513 |
|
| 516 |
my $bibitems = ''; |
514 |
my $bibitems = ''; |
| 517 |
my $priority = '1'; |
515 |
my $priority = '1'; |
|
Lines 521-539
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 521 |
my $checkitem = undef; |
519 |
my $checkitem = undef; |
| 522 |
my $found = undef; |
520 |
my $found = undef; |
| 523 |
|
521 |
|
| 524 |
my $issue = AddIssue( $renewing_borrower, $item_1->barcode); |
522 |
my $issue_1 = AddIssue( $renewing_borrower_obj->unblessed, $item_1->barcode); |
| 525 |
my $datedue = dt_from_string( $issue->date_due() ); |
523 |
my $datedue = dt_from_string( $issue_1->date_due() ); |
| 526 |
is (defined $issue->date_due(), 1, "Item 1 checked out, due date: " . $issue->date_due() ); |
524 |
is (defined $issue_1->date_due(), 1, "Item 1 checked out, due date: " . $issue_1->date_due() ); |
| 527 |
|
|
|
| 528 |
my $issue2 = AddIssue( $renewing_borrower, $item_2->barcode); |
| 529 |
$datedue = dt_from_string( $issue->date_due() ); |
| 530 |
is (defined $issue2, 1, "Item 2 checked out, due date: " . $issue2->date_due()); |
| 531 |
|
525 |
|
|
|
526 |
my $issue_2 = AddIssue( $renewing_borrower_obj->unblessed, $item_2->barcode); |
| 527 |
is (defined $issue_2, 1, "Item 2 checked out, due date: " . $issue_2->date_due()); |
| 532 |
|
528 |
|
| 533 |
my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $item_1->itemnumber } )->borrowernumber; |
529 |
my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $item_1->itemnumber } )->borrowernumber; |
| 534 |
is ($borrowing_borrowernumber, $renewing_borrowernumber, "Item checked out to $renewing_borrower->{firstname} $renewing_borrower->{surname}"); |
530 |
is ($borrowing_borrowernumber, $renewing_borrowernumber, "Item checked out to ".$renewing_borrower_obj->firstname." ".$renewing_borrower_obj->surname); |
| 535 |
|
531 |
|
| 536 |
my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1); |
532 |
my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1, 1); |
| 537 |
is( $renewokay, 1, 'Can renew, no holds for this title or item'); |
533 |
is( $renewokay, 1, 'Can renew, no holds for this title or item'); |
| 538 |
|
534 |
|
| 539 |
|
535 |
|
|
Lines 572-580
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 572 |
} |
568 |
} |
| 573 |
); |
569 |
); |
| 574 |
t::lib::Mocks::mock_preference('AllowRenewalIfOtherItemsAvailable', 1 ); |
570 |
t::lib::Mocks::mock_preference('AllowRenewalIfOtherItemsAvailable', 1 ); |
| 575 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
571 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1); |
| 576 |
is( $renewokay, 1, 'Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds'); |
572 |
is( $renewokay, 1, 'Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds'); |
| 577 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_2->itemnumber); |
573 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_2); |
| 578 |
is( $renewokay, 1, 'Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds'); |
574 |
is( $renewokay, 1, 'Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds'); |
| 579 |
|
575 |
|
| 580 |
|
576 |
|
|
Lines 592-598
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 592 |
found => $found, |
588 |
found => $found, |
| 593 |
} |
589 |
} |
| 594 |
); |
590 |
); |
| 595 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
591 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1); |
| 596 |
is( $renewokay, 0, 'Renewal not possible when single patron\'s holds exceed the number of available items'); |
592 |
is( $renewokay, 0, 'Renewal not possible when single patron\'s holds exceed the number of available items'); |
| 597 |
Koha::Holds->find($reserve_id)->delete; |
593 |
Koha::Holds->find($reserve_id)->delete; |
| 598 |
|
594 |
|
|
Lines 607-613
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 607 |
reservedate => '1999-01-01', |
603 |
reservedate => '1999-01-01', |
| 608 |
} |
604 |
} |
| 609 |
); |
605 |
); |
| 610 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
606 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1); |
| 611 |
is( $renewokay, 0, 'Bug 13919 - Renewal possible with item level hold on item'); |
607 |
is( $renewokay, 0, 'Bug 13919 - Renewal possible with item level hold on item'); |
| 612 |
$hold->delete(); |
608 |
$hold->delete(); |
| 613 |
|
609 |
|
|
Lines 623-639
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 623 |
found => 'W' |
619 |
found => 'W' |
| 624 |
} |
620 |
} |
| 625 |
); |
621 |
); |
| 626 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
622 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1); |
| 627 |
is( $renewokay, 0, 'Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds'); |
623 |
is( $renewokay, 0, 'Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds'); |
| 628 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_2->itemnumber); |
624 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_2); |
| 629 |
is( $renewokay, 0, 'Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds'); |
625 |
is( $renewokay, 0, 'Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds'); |
| 630 |
t::lib::Mocks::mock_preference('AllowRenewalIfOtherItemsAvailable', 0 ); |
626 |
t::lib::Mocks::mock_preference('AllowRenewalIfOtherItemsAvailable', 0 ); |
| 631 |
|
627 |
|
| 632 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
628 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1); |
| 633 |
is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved'); |
629 |
is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved'); |
| 634 |
is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)'); |
630 |
is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)'); |
| 635 |
|
631 |
|
| 636 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_2->itemnumber); |
632 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_2); |
| 637 |
is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved'); |
633 |
is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved'); |
| 638 |
is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)'); |
634 |
is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)'); |
| 639 |
|
635 |
|
|
Lines 662-677
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 662 |
} |
658 |
} |
| 663 |
); |
659 |
); |
| 664 |
|
660 |
|
| 665 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1); |
661 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1, 1); |
| 666 |
is( $renewokay, 0, '(Bug 10663) Cannot renew, item reserved'); |
662 |
is( $renewokay, 0, '(Bug 10663) Cannot renew, item reserved'); |
| 667 |
is( $error, 'on_reserve', '(Bug 10663) Cannot renew, item reserved (returned error is on_reserve)'); |
663 |
is( $error, 'on_reserve', '(Bug 10663) Cannot renew, item reserved (returned error is on_reserve)'); |
| 668 |
|
664 |
|
| 669 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_2->itemnumber, 1); |
665 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_2, 1); |
| 670 |
is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1'); |
666 |
is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1'); |
| 671 |
|
667 |
|
| 672 |
# Items can't fill hold for reasons |
668 |
# Items can't fill hold for reasons |
| 673 |
$item_1->notforloan(1)->store; |
669 |
$issue_1->item->notforloan(1)->store; |
| 674 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1); |
670 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1, 1); |
| 675 |
is( $renewokay, 0, 'Cannot renew, item is marked not for loan, but an item specific hold always blocks'); |
671 |
is( $renewokay, 0, 'Cannot renew, item is marked not for loan, but an item specific hold always blocks'); |
| 676 |
$item_1->set({notforloan => 0, itype => $itemtype })->store; |
672 |
$item_1->set({notforloan => 0, itype => $itemtype })->store; |
| 677 |
|
673 |
|
|
Lines 686-698
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 686 |
itype => $itemtype, |
682 |
itype => $itemtype, |
| 687 |
} |
683 |
} |
| 688 |
); |
684 |
); |
| 689 |
my $datedue5 = AddIssue($restricted_borrower, $item_5->barcode); |
685 |
my $issue_5 = AddIssue($restricted_borrower_obj->unblessed, $item_5->barcode); |
| 690 |
is (defined $datedue5, 1, "Item with date due checked out, due date: $datedue5"); |
686 |
is (defined $issue_5, 1, "Item with date due checked out, due date: ". $issue_5->date_due); |
| 691 |
|
687 |
|
| 692 |
t::lib::Mocks::mock_preference('RestrictionBlockRenewing','1'); |
688 |
t::lib::Mocks::mock_preference('RestrictionBlockRenewing','1'); |
| 693 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_2->itemnumber); |
689 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_2); |
| 694 |
is( $renewokay, 1, '(Bug 8236), Can renew, user is not restricted'); |
690 |
is( $renewokay, 1, '(Bug 8236), Can renew, user is not restricted'); |
| 695 |
( $renewokay, $error ) = CanBookBeRenewed($restricted_borrowernumber, $item_5->itemnumber); |
691 |
( $renewokay, $error ) = CanBookBeRenewed($restricted_borrower_obj, $issue_5); |
| 696 |
is( $renewokay, 0, '(Bug 8236), Cannot renew, user is restricted'); |
692 |
is( $renewokay, 0, '(Bug 8236), Cannot renew, user is restricted'); |
| 697 |
is( $error, 'restriction', "Correct error returned"); |
693 |
is( $error, 'restriction', "Correct error returned"); |
| 698 |
|
694 |
|
|
Lines 715-758
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 715 |
} |
711 |
} |
| 716 |
); |
712 |
); |
| 717 |
|
713 |
|
| 718 |
my $datedue6 = AddIssue( $renewing_borrower, $item_6->barcode); |
714 |
my $issue_6 = AddIssue( $renewing_borrower_obj->unblessed, $item_6->barcode); |
| 719 |
is (defined $datedue6, 1, "Item 2 checked out, due date: ".$datedue6->date_due); |
715 |
is (defined $issue_6, 1, "Item 2 checked out, due date: ".$issue_6->date_due); |
| 720 |
|
716 |
|
| 721 |
my $now = dt_from_string(); |
717 |
my $now = dt_from_string(); |
| 722 |
my $five_weeks = DateTime::Duration->new(weeks => 5); |
718 |
my $five_weeks = DateTime::Duration->new(weeks => 5); |
| 723 |
my $five_weeks_ago = $now - $five_weeks; |
719 |
my $five_weeks_ago = $now - $five_weeks; |
| 724 |
t::lib::Mocks::mock_preference('finesMode', 'production'); |
720 |
t::lib::Mocks::mock_preference('finesMode', 'production'); |
| 725 |
|
721 |
|
| 726 |
my $passeddatedue1 = AddIssue($renewing_borrower, $item_7->barcode, $five_weeks_ago); |
722 |
my $issue_7 = AddIssue($renewing_borrower_obj->unblessed, $item_7->barcode, $five_weeks_ago); |
| 727 |
is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due); |
723 |
is (defined $issue_7, 1, "Item with passed date due checked out, due date: " . $issue_7->date_due); |
| 728 |
|
724 |
|
| 729 |
t::lib::Mocks::mock_preference('OverduesBlockRenewing','allow'); |
725 |
t::lib::Mocks::mock_preference('OverduesBlockRenewing','allow'); |
| 730 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_6->itemnumber); |
726 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_6); |
| 731 |
is( $renewokay, 1, '(Bug 8236), Can renew, this item is not overdue'); |
727 |
is( $renewokay, 1, '(Bug 8236), Can renew, this item is not overdue'); |
| 732 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_7->itemnumber); |
728 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_7); |
| 733 |
is( $renewokay, 1, '(Bug 8236), Can renew, this item is overdue but not pref does not block'); |
729 |
is( $renewokay, 1, '(Bug 8236), Can renew, this item is overdue but not pref does not block'); |
| 734 |
|
730 |
|
| 735 |
t::lib::Mocks::mock_preference('OverduesBlockRenewing','block'); |
731 |
t::lib::Mocks::mock_preference('OverduesBlockRenewing','block'); |
| 736 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_6->itemnumber); |
732 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_6); |
| 737 |
is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is not overdue but patron has overdues'); |
733 |
is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is not overdue but patron has overdues'); |
| 738 |
is( $error, 'overdue', "Correct error returned"); |
734 |
is( $error, 'overdue', "Correct error returned"); |
| 739 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_7->itemnumber); |
735 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_7); |
| 740 |
is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is overdue so patron has overdues'); |
736 |
is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is overdue so patron has overdues'); |
| 741 |
is( $error, 'overdue', "Correct error returned"); |
737 |
is( $error, 'overdue', "Correct error returned"); |
| 742 |
|
738 |
|
| 743 |
t::lib::Mocks::mock_preference('OverduesBlockRenewing','blockitem'); |
739 |
t::lib::Mocks::mock_preference('OverduesBlockRenewing','blockitem'); |
| 744 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_6->itemnumber); |
740 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_6); |
| 745 |
is( $renewokay, 1, '(Bug 8236), Can renew, this item is not overdue'); |
741 |
is( $renewokay, 1, '(Bug 8236), Can renew, this item is not overdue'); |
| 746 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_7->itemnumber); |
742 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_7); |
| 747 |
is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is overdue'); |
743 |
is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is overdue'); |
| 748 |
is( $error, 'overdue', "Correct error returned"); |
744 |
is( $error, 'overdue', "Correct error returned"); |
| 749 |
|
745 |
|
| 750 |
my ( $fine ) = CalcFine( $item_7->unblessed, $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now ); |
746 |
my ( $fine ) = CalcFine( $item_7->unblessed, $renewing_borrower_obj->categorycode, $branch, $five_weeks_ago, $now ); |
| 751 |
C4::Overdues::UpdateFine( |
747 |
C4::Overdues::UpdateFine( |
| 752 |
{ |
748 |
{ |
| 753 |
issue_id => $passeddatedue1->id(), |
749 |
issue_id => $issue_7->id(), |
| 754 |
itemnumber => $item_7->itemnumber, |
750 |
itemnumber => $item_7->itemnumber, |
| 755 |
borrowernumber => $renewing_borrower->{borrowernumber}, |
751 |
borrowernumber => $renewing_borrower_obj->borrowernumber, |
| 756 |
amount => $fine, |
752 |
amount => $fine, |
| 757 |
due => Koha::DateUtils::output_pref($five_weeks_ago) |
753 |
due => Koha::DateUtils::output_pref($five_weeks_ago) |
| 758 |
} |
754 |
} |
|
Lines 783-789
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 783 |
my $old_log_size = Koha::ActionLogs->count( \%params_renewal ); |
779 |
my $old_log_size = Koha::ActionLogs->count( \%params_renewal ); |
| 784 |
my $dt = dt_from_string(); |
780 |
my $dt = dt_from_string(); |
| 785 |
Time::Fake->offset( $dt->epoch ); |
781 |
Time::Fake->offset( $dt->epoch ); |
| 786 |
my $datedue1 = AddRenewal( $renewing_borrower->{borrowernumber}, $item_7->itemnumber, $branch ); |
782 |
my $datedue1 = AddRenewal( $renewing_borrower_obj->borrowernumber, $item_7->itemnumber, $branch ); |
| 787 |
my $new_log_size = Koha::ActionLogs->count( \%params_renewal ); |
783 |
my $new_log_size = Koha::ActionLogs->count( \%params_renewal ); |
| 788 |
is ($new_log_size, $old_log_size, 'renew log not added because of the syspref RenewalLog'); |
784 |
is ($new_log_size, $old_log_size, 'renew log not added because of the syspref RenewalLog'); |
| 789 |
isnt (DateTime->compare($datedue1, $dt), 0, "AddRenewal returned a good duedate"); |
785 |
isnt (DateTime->compare($datedue1, $dt), 0, "AddRenewal returned a good duedate"); |
|
Lines 792-809
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 792 |
t::lib::Mocks::mock_preference('RenewalLog', 1); |
788 |
t::lib::Mocks::mock_preference('RenewalLog', 1); |
| 793 |
$date = output_pref( { dt => dt_from_string(), dateonly => 1, dateformat => 'iso' } ); |
789 |
$date = output_pref( { dt => dt_from_string(), dateonly => 1, dateformat => 'iso' } ); |
| 794 |
$old_log_size = Koha::ActionLogs->count( \%params_renewal ); |
790 |
$old_log_size = Koha::ActionLogs->count( \%params_renewal ); |
| 795 |
AddRenewal( $renewing_borrower->{borrowernumber}, $item_7->itemnumber, $branch ); |
791 |
AddRenewal( $renewing_borrower_obj->borrowernumber, $item_7->itemnumber, $branch ); |
| 796 |
$new_log_size = Koha::ActionLogs->count( \%params_renewal ); |
792 |
$new_log_size = Koha::ActionLogs->count( \%params_renewal ); |
| 797 |
is ($new_log_size, $old_log_size + 1, 'renew log successfully added'); |
793 |
is ($new_log_size, $old_log_size + 1, 'renew log successfully added'); |
| 798 |
|
794 |
|
| 799 |
my $fines = Koha::Account::Lines->search( { borrowernumber => $renewing_borrower->{borrowernumber}, itemnumber => $item_7->itemnumber } ); |
795 |
my $fines = Koha::Account::Lines->search( { borrowernumber => $renewing_borrower_obj->borrowernumber, itemnumber => $item_7->itemnumber } ); |
| 800 |
is( $fines->count, 1, 'AddRenewal left fine' ); |
796 |
is( $fines->count, 1, 'AddRenewal left fine' ); |
| 801 |
is( $fines->next->status, 'RENEWED', 'Fine on renewed item is closed out properly' ); |
797 |
is( $fines->next->status, 'RENEWED', 'Fine on renewed item is closed out properly' ); |
| 802 |
$fines->delete(); |
798 |
$fines->delete(); |
| 803 |
|
799 |
|
| 804 |
my $old_issue_log_size = Koha::ActionLogs->count( \%params_issue ); |
800 |
my $old_issue_log_size = Koha::ActionLogs->count( \%params_issue ); |
| 805 |
my $old_renew_log_size = Koha::ActionLogs->count( \%params_renewal ); |
801 |
my $old_renew_log_size = Koha::ActionLogs->count( \%params_renewal ); |
| 806 |
AddIssue( $renewing_borrower,$item_7->barcode,Koha::DateUtils::output_pref({str=>$datedue6->date_due, dateformat =>'iso'}),0,$date, 0, undef ); |
802 |
AddIssue( |
|
|
803 |
$renewing_borrower_obj->unblessed, |
| 804 |
$item_7->barcode, |
| 805 |
Koha::DateUtils::output_pref({str=>$issue_6->date_due, dateformat =>'iso'}), |
| 806 |
0, |
| 807 |
$date, |
| 808 |
0, |
| 809 |
undef |
| 810 |
); # TODO: Already issued??? |
| 807 |
$new_log_size = Koha::ActionLogs->count( \%params_renewal ); |
811 |
$new_log_size = Koha::ActionLogs->count( \%params_renewal ); |
| 808 |
is ($new_log_size, $old_renew_log_size + 1, 'renew log successfully added when renewed via issuing'); |
812 |
is ($new_log_size, $old_renew_log_size + 1, 'renew log successfully added when renewed via issuing'); |
| 809 |
$new_log_size = Koha::ActionLogs->count( \%params_issue ); |
813 |
$new_log_size = Koha::ActionLogs->count( \%params_issue ); |
|
Lines 824-837
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 824 |
} |
828 |
} |
| 825 |
); |
829 |
); |
| 826 |
|
830 |
|
| 827 |
$issue = AddIssue( $renewing_borrower, $item_4->barcode, undef, undef, undef, undef, { auto_renew => 1 } ); |
831 |
my $issue_4 = AddIssue( $renewing_borrower_obj->unblessed, $item_4->barcode, undef, undef, undef, undef, { auto_renew => 1 } ); |
| 828 |
my $info; |
832 |
my $info; |
| 829 |
( $renewokay, $error, $info ) = |
833 |
( $renewokay, $error, $info ) = |
| 830 |
CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber ); |
834 |
CanBookBeRenewed( $renewing_borrower_obj, $issue_4 ); |
| 831 |
is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' ); |
835 |
is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' ); |
| 832 |
is( $error, 'auto_too_soon', |
836 |
is( $error, 'auto_too_soon', |
| 833 |
'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' ); |
837 |
'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' ); |
| 834 |
is( $info->{soonest_renew_date} , dt_from_string($issue->date_due), "Due date is returned as earliest renewal date when error is 'auto_too_soon'" ); |
838 |
is( $info->{soonest_renew_date} , dt_from_string($issue_4->date_due), "Due date is returned as earliest renewal date when error is 'auto_too_soon'" ); |
| 835 |
AddReserve( |
839 |
AddReserve( |
| 836 |
{ |
840 |
{ |
| 837 |
branchcode => $branch, |
841 |
branchcode => $branch, |
|
Lines 847-876
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 847 |
found => $found |
851 |
found => $found |
| 848 |
} |
852 |
} |
| 849 |
); |
853 |
); |
| 850 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber ); |
854 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4 ); |
| 851 |
is( $renewokay, 0, 'Still should not be able to renew' ); |
855 |
is( $renewokay, 0, 'Still should not be able to renew' ); |
| 852 |
is( $error, 'on_reserve', 'returned code is on_reserve, reserve checked when not checking for cron' ); |
856 |
is( $error, 'on_reserve', 'returned code is on_reserve, reserve checked when not checking for cron' ); |
| 853 |
( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, undef, 1 ); |
857 |
( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4, undef, 1 ); |
| 854 |
is( $renewokay, 0, 'Still should not be able to renew' ); |
858 |
is( $renewokay, 0, 'Still should not be able to renew' ); |
| 855 |
is( $error, 'auto_too_soon', 'returned code is auto_too_soon, reserve not checked when checking for cron' ); |
859 |
is( $error, 'auto_too_soon', 'returned code is auto_too_soon, reserve not checked when checking for cron' ); |
| 856 |
is( $info->{soonest_renew_date}, dt_from_string($issue->date_due), "Due date is returned as earliest renewal date when error is 'auto_too_soon'" ); |
860 |
is( $info->{soonest_renew_date}, dt_from_string($issue_4->date_due), "Due date is returned as earliest renewal date when error is 'auto_too_soon'" ); |
| 857 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 ); |
861 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4, 1 ); |
| 858 |
is( $renewokay, 0, 'Still should not be able to renew' ); |
862 |
is( $renewokay, 0, 'Still should not be able to renew' ); |
| 859 |
is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' ); |
863 |
is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' ); |
| 860 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1, 1 ); |
864 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4, 1, 1 ); |
| 861 |
is( $renewokay, 0, 'Still should not be able to renew' ); |
865 |
is( $renewokay, 0, 'Still should not be able to renew' ); |
| 862 |
is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' ); |
866 |
is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' ); |
| 863 |
$dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"'); |
867 |
$dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"'); |
| 864 |
Koha::Cache::Memory::Lite->flush(); |
868 |
Koha::Cache::Memory::Lite->flush(); |
| 865 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 ); |
869 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4, 1 ); |
| 866 |
is( $renewokay, 0, 'Still should not be able to renew' ); |
870 |
is( $renewokay, 0, 'Still should not be able to renew' ); |
| 867 |
is( $error, 'on_reserve', 'returned code is on_reserve, auto_renew only happens if not on reserve' ); |
871 |
is( $error, 'on_reserve', 'returned code is on_reserve, auto_renew only happens if not on reserve' ); |
| 868 |
ModReserveCancelAll($item_4->itemnumber, $reserving_borrowernumber); |
872 |
ModReserveCancelAll($item_4->itemnumber, $reserving_borrowernumber); |
| 869 |
|
873 |
|
| 870 |
|
874 |
$renewing_borrower_obj = Koha::Patrons->find($renewing_borrower_obj->borrowernumber); |
| 871 |
|
|
|
| 872 |
$renewing_borrower_obj->autorenew_checkouts(0)->store; |
875 |
$renewing_borrower_obj->autorenew_checkouts(0)->store; |
| 873 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber ); |
876 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4 ); |
| 874 |
is( $renewokay, 1, 'No renewal before is undef, but patron opted out of auto_renewal' ); |
877 |
is( $renewokay, 1, 'No renewal before is undef, but patron opted out of auto_renewal' ); |
| 875 |
$renewing_borrower_obj->autorenew_checkouts(1)->store; |
878 |
$renewing_borrower_obj->autorenew_checkouts(1)->store; |
| 876 |
|
879 |
|
|
Lines 887-912
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 887 |
} |
890 |
} |
| 888 |
); |
891 |
); |
| 889 |
|
892 |
|
| 890 |
( $renewokay, $error, $info ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
893 |
( $renewokay, $error, $info ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1); |
| 891 |
is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature'); |
894 |
is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature'); |
| 892 |
is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)'); |
895 |
is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)'); |
| 893 |
is( $info->{soonest_renew_date}, dt_from_string($issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'"); |
896 |
is( $info->{soonest_renew_date}, dt_from_string($issue_1->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'"); |
| 894 |
|
897 |
|
| 895 |
# Bug 14101 |
898 |
# Bug 14101 |
| 896 |
# Test premature automatic renewal |
899 |
# Test premature automatic renewal |
| 897 |
( $renewokay, $error, $info ) = |
900 |
( $renewokay, $error, $info ) = |
| 898 |
CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber ); |
901 |
CanBookBeRenewed( $renewing_borrower_obj, $issue_4 ); |
| 899 |
is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' ); |
902 |
is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' ); |
| 900 |
is( $error, 'auto_too_soon', |
903 |
is( $error, 'auto_too_soon', |
| 901 |
'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)' |
904 |
'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)' |
| 902 |
); |
905 |
); |
| 903 |
is( $info->{soonest_renew_date}, dt_from_string($issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'auto_too_soon'"); |
906 |
is( $info->{soonest_renew_date}, dt_from_string($issue_4->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'auto_too_soon'"); |
| 904 |
|
907 |
|
| 905 |
$renewing_borrower_obj->autorenew_checkouts(0)->store; |
908 |
$renewing_borrower_obj->autorenew_checkouts(0)->store; |
| 906 |
( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber ); |
909 |
( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4 ); |
| 907 |
is( $renewokay, 0, 'No renewal before is 7, patron opted out of auto_renewal still cannot renew early' ); |
910 |
is( $renewokay, 0, 'No renewal before is 7, patron opted out of auto_renewal still cannot renew early' ); |
| 908 |
is( $error, 'too_soon', 'Error is too_soon, no auto' ); |
911 |
is( $error, 'too_soon', 'Error is too_soon, no auto' ); |
| 909 |
is( $info->{soonest_renew_date}, dt_from_string($issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'"); |
912 |
is( $info->{soonest_renew_date}, dt_from_string($issue_4->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'"); |
| 910 |
$renewing_borrower_obj->autorenew_checkouts(1)->store; |
913 |
$renewing_borrower_obj->autorenew_checkouts(1)->store; |
| 911 |
|
914 |
|
| 912 |
# Change policy so that loans can only be renewed exactly on due date (0 days prior to due date) |
915 |
# Change policy so that loans can only be renewed exactly on due date (0 days prior to due date) |
|
Lines 914-931
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 914 |
$dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'norenewalbefore'}); |
917 |
$dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'norenewalbefore'}); |
| 915 |
Koha::Cache::Memory::Lite->flush(); |
918 |
Koha::Cache::Memory::Lite->flush(); |
| 916 |
( $renewokay, $error, $info ) = |
919 |
( $renewokay, $error, $info ) = |
| 917 |
CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber ); |
920 |
CanBookBeRenewed( $renewing_borrower_obj, $issue_4 ); |
| 918 |
is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' ); |
921 |
is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' ); |
| 919 |
is( $error, 'auto_too_soon', |
922 |
is( $error, 'auto_too_soon', |
| 920 |
'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)' |
923 |
'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)' |
| 921 |
); |
924 |
); |
| 922 |
is( $info->{soonest_renew_date}, dt_from_string($issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'"); |
925 |
is( $info->{soonest_renew_date}, dt_from_string($issue_4->date_due), "Soonest renew date returned when error is 'auto_too_soon'"); |
| 923 |
|
926 |
|
| 924 |
$renewing_borrower_obj->autorenew_checkouts(0)->store; |
927 |
$renewing_borrower_obj->autorenew_checkouts(0)->store; |
| 925 |
( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber ); |
928 |
( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4 ); |
| 926 |
is( $renewokay, 0, 'No renewal before is 0, patron opted out of auto_renewal still cannot renew early' ); |
929 |
is( $renewokay, 0, 'No renewal before is 0, patron opted out of auto_renewal still cannot renew early' ); |
| 927 |
is( $error, 'too_soon', 'Error is too_soon, no auto' ); |
930 |
is( $error, 'too_soon', 'Error is too_soon, no auto' ); |
| 928 |
is( $info->{soonest_renew_date}, dt_from_string($issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'"); |
931 |
is( $info->{soonest_renew_date}, dt_from_string($issue_4->date_due), "Soonest renew date returned when error is 'auto_too_soon'"); |
| 929 |
$renewing_borrower_obj->autorenew_checkouts(1)->store; |
932 |
$renewing_borrower_obj->autorenew_checkouts(1)->store; |
| 930 |
|
933 |
|
| 931 |
# Change policy so that loans can be renewed 99 days prior to the due date |
934 |
# Change policy so that loans can be renewed 99 days prior to the due date |
|
Lines 933-946
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 933 |
$dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'norenewalbefore'}); |
936 |
$dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'norenewalbefore'}); |
| 934 |
Koha::Cache::Memory::Lite->flush(); |
937 |
Koha::Cache::Memory::Lite->flush(); |
| 935 |
( $renewokay, $error ) = |
938 |
( $renewokay, $error ) = |
| 936 |
CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber ); |
939 |
CanBookBeRenewed( $renewing_borrower_obj, $issue_4 ); |
| 937 |
is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' ); |
940 |
is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' ); |
| 938 |
is( $error, 'auto_renew', |
941 |
is( $error, 'auto_renew', |
| 939 |
'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)' |
942 |
'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)' |
| 940 |
); |
943 |
); |
| 941 |
|
944 |
|
| 942 |
$renewing_borrower_obj->autorenew_checkouts(0)->store; |
945 |
$renewing_borrower_obj->autorenew_checkouts(0)->store; |
| 943 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber ); |
946 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4 ); |
| 944 |
is( $renewokay, 1, 'No renewal before is 99, patron opted out of auto_renewal so can renew' ); |
947 |
is( $renewokay, 1, 'No renewal before is 99, patron opted out of auto_renewal so can renew' ); |
| 945 |
$renewing_borrower_obj->autorenew_checkouts(1)->store; |
948 |
$renewing_borrower_obj->autorenew_checkouts(1)->store; |
| 946 |
|
949 |
|
|
Lines 955-961
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 955 |
|
958 |
|
| 956 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
959 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
| 957 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
960 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
| 958 |
AddIssue( $renewing_borrower, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
961 |
my $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
| 959 |
|
962 |
|
| 960 |
Koha::CirculationRules->set_rules( |
963 |
Koha::CirculationRules->set_rules( |
| 961 |
{ |
964 |
{ |
|
Lines 969-975
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 969 |
} |
972 |
} |
| 970 |
); |
973 |
); |
| 971 |
( $renewokay, $error ) = |
974 |
( $renewokay, $error ) = |
| 972 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
975 |
CanBookBeRenewed( $renewing_borrower_obj, $issue ); |
| 973 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
976 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 974 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
977 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
| 975 |
|
978 |
|
|
Lines 985-991
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 985 |
} |
988 |
} |
| 986 |
); |
989 |
); |
| 987 |
( $renewokay, $error ) = |
990 |
( $renewokay, $error ) = |
| 988 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
991 |
CanBookBeRenewed( $renewing_borrower_obj, $issue ); |
| 989 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
992 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 990 |
is( $error, 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' ); |
993 |
is( $error, 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' ); |
| 991 |
|
994 |
|
|
Lines 1001-1007
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1001 |
} |
1004 |
} |
| 1002 |
); |
1005 |
); |
| 1003 |
( $renewokay, $error ) = |
1006 |
( $renewokay, $error ) = |
| 1004 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
1007 |
CanBookBeRenewed( $renewing_borrower_obj, $issue ); |
| 1005 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
1008 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 1006 |
is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' ); |
1009 |
is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' ); |
| 1007 |
|
1010 |
|
|
Lines 1017-1023
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1017 |
} |
1020 |
} |
| 1018 |
); |
1021 |
); |
| 1019 |
( $renewokay, $error ) = |
1022 |
( $renewokay, $error ) = |
| 1020 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
1023 |
CanBookBeRenewed( $renewing_borrower_obj, $issue ); |
| 1021 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
1024 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 1022 |
is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); |
1025 |
is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); |
| 1023 |
|
1026 |
|
|
Lines 1034-1040
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1034 |
} |
1037 |
} |
| 1035 |
); |
1038 |
); |
| 1036 |
( $renewokay, $error ) = |
1039 |
( $renewokay, $error ) = |
| 1037 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
1040 |
CanBookBeRenewed( $renewing_borrower_obj, $issue ); |
| 1038 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
1041 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 1039 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
1042 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
| 1040 |
|
1043 |
|
|
Lines 1051-1057
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1051 |
} |
1054 |
} |
| 1052 |
); |
1055 |
); |
| 1053 |
( $renewokay, $error ) = |
1056 |
( $renewokay, $error ) = |
| 1054 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
1057 |
CanBookBeRenewed( $renewing_borrower_obj, $issue ); |
| 1055 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
1058 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 1056 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
1059 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
| 1057 |
|
1060 |
|
|
Lines 1068-1074
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1068 |
} |
1071 |
} |
| 1069 |
); |
1072 |
); |
| 1070 |
( $renewokay, $error ) = |
1073 |
( $renewokay, $error ) = |
| 1071 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
1074 |
CanBookBeRenewed( $renewing_borrower_obj, $issue ); |
| 1072 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
1075 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 1073 |
is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); |
1076 |
is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); |
| 1074 |
}; |
1077 |
}; |
|
Lines 1084-1090
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1084 |
|
1087 |
|
| 1085 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
1088 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
| 1086 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
1089 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
| 1087 |
AddIssue( $renewing_borrower, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
1090 |
my $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
| 1088 |
|
1091 |
|
| 1089 |
Koha::CirculationRules->set_rules( |
1092 |
Koha::CirculationRules->set_rules( |
| 1090 |
{ |
1093 |
{ |
|
Lines 1112-1118
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1112 |
} |
1115 |
} |
| 1113 |
)->status('RETURNED')->store; |
1116 |
)->status('RETURNED')->store; |
| 1114 |
( $renewokay, $error ) = |
1117 |
( $renewokay, $error ) = |
| 1115 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
1118 |
CanBookBeRenewed( $renewing_borrower_obj, $issue ); |
| 1116 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
1119 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 1117 |
is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 5' ); |
1120 |
is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 5' ); |
| 1118 |
|
1121 |
|
|
Lines 1126-1132
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1126 |
} |
1129 |
} |
| 1127 |
)->status('RETURNED')->store; |
1130 |
)->status('RETURNED')->store; |
| 1128 |
( $renewokay, $error ) = |
1131 |
( $renewokay, $error ) = |
| 1129 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
1132 |
CanBookBeRenewed( $renewing_borrower_obj, $issue ); |
| 1130 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
1133 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 1131 |
is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 10' ); |
1134 |
is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 10' ); |
| 1132 |
|
1135 |
|
|
Lines 1140-1146
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1140 |
} |
1143 |
} |
| 1141 |
)->status('RETURNED')->store; |
1144 |
)->status('RETURNED')->store; |
| 1142 |
( $renewokay, $error ) = |
1145 |
( $renewokay, $error ) = |
| 1143 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
1146 |
CanBookBeRenewed( $renewing_borrower_obj, $issue ); |
| 1144 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
1147 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 1145 |
is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, patron has 15' ); |
1148 |
is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, patron has 15' ); |
| 1146 |
|
1149 |
|
|
Lines 1153-1165
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1153 |
} |
1156 |
} |
| 1154 |
)->store; |
1157 |
)->store; |
| 1155 |
( $renewokay, $error ) = |
1158 |
( $renewokay, $error ) = |
| 1156 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
1159 |
CanBookBeRenewed( $renewing_borrower_obj, $issue ); |
| 1157 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
1160 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 1158 |
is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit' ); |
1161 |
is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit' ); |
| 1159 |
|
1162 |
|
| 1160 |
C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','0'); |
1163 |
C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','0'); |
| 1161 |
( $renewokay, $error ) = |
1164 |
( $renewokay, $error ) = |
| 1162 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
1165 |
CanBookBeRenewed( $renewing_borrower_obj, $issue ); |
| 1163 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
1166 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 1164 |
is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit' ); |
1167 |
is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit' ); |
| 1165 |
|
1168 |
|
|
Lines 1194-1230
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1194 |
# Patron is expired and BlockExpiredPatronOpacActions=0 |
1197 |
# Patron is expired and BlockExpiredPatronOpacActions=0 |
| 1195 |
# => auto renew is allowed |
1198 |
# => auto renew is allowed |
| 1196 |
t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 0); |
1199 |
t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 0); |
| 1197 |
my $patron = $expired_borrower; |
1200 |
my $issue = AddIssue( $expired_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
| 1198 |
my $checkout = AddIssue( $patron, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
|
|
| 1199 |
( $renewokay, $error ) = |
1201 |
( $renewokay, $error ) = |
| 1200 |
CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->itemnumber ); |
1202 |
CanBookBeRenewed( $expired_borrower_obj, $issue ); |
| 1201 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
1203 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 1202 |
is( $error, 'auto_renew', 'Can auto renew, patron is expired but BlockExpiredPatronOpacActions=0' ); |
1204 |
is( $error, 'auto_renew', 'Can auto renew, patron is expired but BlockExpiredPatronOpacActions=0' ); |
| 1203 |
Koha::Checkouts->find( $checkout->issue_id )->delete; |
1205 |
Koha::Checkouts->find( $issue->issue_id )->delete; |
| 1204 |
|
1206 |
|
| 1205 |
|
1207 |
|
| 1206 |
# Patron is expired and BlockExpiredPatronOpacActions=1 |
1208 |
# Patron is expired and BlockExpiredPatronOpacActions=1 |
| 1207 |
# => auto renew is not allowed |
1209 |
# => auto renew is not allowed |
| 1208 |
t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1); |
1210 |
t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1); |
| 1209 |
$patron = $expired_borrower; |
1211 |
$issue = AddIssue( $expired_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
| 1210 |
$checkout = AddIssue( $patron, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
|
|
| 1211 |
( $renewokay, $error ) = |
1212 |
( $renewokay, $error ) = |
| 1212 |
CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->itemnumber ); |
1213 |
CanBookBeRenewed( $expired_borrower_obj, $issue ); |
| 1213 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
1214 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 1214 |
is( $error, 'auto_account_expired', 'Can not auto renew, lockExpiredPatronOpacActions=1 and patron is expired' ); |
1215 |
is( $error, 'auto_account_expired', 'Can not auto renew, lockExpiredPatronOpacActions=1 and patron is expired' ); |
| 1215 |
Koha::Checkouts->find( $checkout->issue_id )->delete; |
1216 |
$issue->delete; |
| 1216 |
|
|
|
| 1217 |
|
1217 |
|
| 1218 |
# Patron is not expired and BlockExpiredPatronOpacActions=1 |
1218 |
# Patron is not expired and BlockExpiredPatronOpacActions=1 |
| 1219 |
# => auto renew is allowed |
1219 |
# => auto renew is allowed |
| 1220 |
t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1); |
1220 |
t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1); |
| 1221 |
$patron = $renewing_borrower; |
1221 |
$issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
| 1222 |
$checkout = AddIssue( $patron, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
|
|
| 1223 |
( $renewokay, $error ) = |
1222 |
( $renewokay, $error ) = |
| 1224 |
CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->itemnumber ); |
1223 |
CanBookBeRenewed( $renewing_borrower_obj, $issue ); |
| 1225 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
1224 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 1226 |
is( $error, 'auto_renew', 'Can auto renew, BlockExpiredPatronOpacActions=1 but patron is not expired' ); |
1225 |
is( $error, 'auto_renew', 'Can auto renew, BlockExpiredPatronOpacActions=1 but patron is not expired' ); |
| 1227 |
Koha::Checkouts->find( $checkout->issue_id )->delete; |
1226 |
$issue->delete; |
| 1228 |
}; |
1227 |
}; |
| 1229 |
|
1228 |
|
| 1230 |
subtest "GetLatestAutoRenewDate" => sub { |
1229 |
subtest "GetLatestAutoRenewDate" => sub { |
|
Lines 1238-1244
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1238 |
|
1237 |
|
| 1239 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
1238 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
| 1240 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
1239 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
| 1241 |
AddIssue( $renewing_borrower, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
1240 |
my $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
| 1242 |
Koha::CirculationRules->set_rules( |
1241 |
Koha::CirculationRules->set_rules( |
| 1243 |
{ |
1242 |
{ |
| 1244 |
categorycode => undef, |
1243 |
categorycode => undef, |
|
Lines 1251-1257
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1251 |
} |
1250 |
} |
| 1252 |
} |
1251 |
} |
| 1253 |
); |
1252 |
); |
| 1254 |
my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
1253 |
my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrower_obj, $issue ); |
| 1255 |
is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after or no_auto_renewal_after_hard_limit are not defined' ); |
1254 |
is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after or no_auto_renewal_after_hard_limit are not defined' ); |
| 1256 |
my $five_days_before = dt_from_string->add( days => -5 ); |
1255 |
my $five_days_before = dt_from_string->add( days => -5 ); |
| 1257 |
Koha::CirculationRules->set_rules( |
1256 |
Koha::CirculationRules->set_rules( |
|
Lines 1266-1272
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1266 |
} |
1265 |
} |
| 1267 |
} |
1266 |
} |
| 1268 |
); |
1267 |
); |
| 1269 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
1268 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrower_obj,, $issue ); |
| 1270 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
1269 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
| 1271 |
$five_days_before->truncate( to => 'minute' ), |
1270 |
$five_days_before->truncate( to => 'minute' ), |
| 1272 |
'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before' |
1271 |
'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before' |
|
Lines 1288-1294
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1288 |
} |
1287 |
} |
| 1289 |
} |
1288 |
} |
| 1290 |
); |
1289 |
); |
| 1291 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
1290 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrower_obj, $issue ); |
| 1292 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
1291 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
| 1293 |
$five_days_ahead->truncate( to => 'minute' ), |
1292 |
$five_days_ahead->truncate( to => 'minute' ), |
| 1294 |
'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before' |
1293 |
'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before' |
|
Lines 1306-1312
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1306 |
} |
1305 |
} |
| 1307 |
} |
1306 |
} |
| 1308 |
); |
1307 |
); |
| 1309 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
1308 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrower_obj, $issue ); |
| 1310 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
1309 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
| 1311 |
$two_days_ahead->truncate( to => 'day' ), |
1310 |
$two_days_ahead->truncate( to => 'day' ), |
| 1312 |
'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is defined and not no_auto_renewal_after' |
1311 |
'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is defined and not no_auto_renewal_after' |
|
Lines 1323-1329
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1323 |
} |
1322 |
} |
| 1324 |
} |
1323 |
} |
| 1325 |
); |
1324 |
); |
| 1326 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->itemnumber ); |
1325 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrower_obj, $issue ); |
| 1327 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
1326 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
| 1328 |
$two_days_ahead->truncate( to => 'day' ), |
1327 |
$two_days_ahead->truncate( to => 'day' ), |
| 1329 |
'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is < no_auto_renewal_after' |
1328 |
'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is < no_auto_renewal_after' |
|
Lines 1345-1351
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1345 |
} |
1344 |
} |
| 1346 |
); |
1345 |
); |
| 1347 |
|
1346 |
|
| 1348 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
1347 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1); |
| 1349 |
is( $renewokay, 0, 'Cannot renew, 0 renewals allowed'); |
1348 |
is( $renewokay, 0, 'Cannot renew, 0 renewals allowed'); |
| 1350 |
is( $error, 'too_many', 'Cannot renew, 0 renewals allowed (returned code is too_many)'); |
1349 |
is( $error, 'too_many', 'Cannot renew, 0 renewals allowed (returned code is too_many)'); |
| 1351 |
|
1350 |
|
|
Lines 1362-1369
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1362 |
} |
1361 |
} |
| 1363 |
); |
1362 |
); |
| 1364 |
t::lib::Mocks::mock_preference('UnseenRenewals', 1); |
1363 |
t::lib::Mocks::mock_preference('UnseenRenewals', 1); |
| 1365 |
$dbh->do('UPDATE issues SET unseen_renewals = 2 where borrowernumber = ? AND itemnumber = ?', undef, ($renewing_borrowernumber, $item_1->itemnumber)); |
1364 |
$issue_1->unseen_renewals(2)->store; |
| 1366 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
1365 |
|
|
|
1366 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1); |
| 1367 |
is( $renewokay, 0, 'Cannot renew, 0 unseen renewals allowed'); |
1367 |
is( $renewokay, 0, 'Cannot renew, 0 unseen renewals allowed'); |
| 1368 |
is( $error, 'too_unseen', 'Cannot renew, returned code is too_unseen'); |
1368 |
is( $error, 'too_unseen', 'Cannot renew, returned code is too_unseen'); |
| 1369 |
Koha::CirculationRules->set_rules( |
1369 |
Koha::CirculationRules->set_rules( |
|
Lines 1385-1405
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1385 |
|
1385 |
|
| 1386 |
C4::Overdues::UpdateFine( |
1386 |
C4::Overdues::UpdateFine( |
| 1387 |
{ |
1387 |
{ |
| 1388 |
issue_id => $issue->id(), |
1388 |
issue_id => $issue_1->id(), |
| 1389 |
itemnumber => $item_1->itemnumber, |
1389 |
itemnumber => $item_1->itemnumber, |
| 1390 |
borrowernumber => $renewing_borrower->{borrowernumber}, |
1390 |
borrowernumber => $renewing_borrower_obj->borrowernumber, |
| 1391 |
amount => 15.00, |
1391 |
amount => 15.00, |
| 1392 |
type => q{}, |
1392 |
type => q{}, |
| 1393 |
due => Koha::DateUtils::output_pref($datedue) |
1393 |
due => Koha::DateUtils::output_pref($datedue) |
| 1394 |
} |
1394 |
} |
| 1395 |
); |
1395 |
); |
| 1396 |
|
1396 |
|
| 1397 |
my $line = Koha::Account::Lines->search({ borrowernumber => $renewing_borrower->{borrowernumber} })->next(); |
1397 |
my $line = Koha::Account::Lines->search({ borrowernumber => $renewing_borrower_obj->borrowernumber })->next(); |
| 1398 |
is( $line->debit_type_code, 'OVERDUE', 'Account line type is OVERDUE' ); |
1398 |
is( $line->debit_type_code, 'OVERDUE', 'Account line type is OVERDUE' ); |
| 1399 |
is( $line->status, 'UNRETURNED', 'Account line status is UNRETURNED' ); |
1399 |
is( $line->status, 'UNRETURNED', 'Account line status is UNRETURNED' ); |
| 1400 |
is( $line->amountoutstanding+0, 15, 'Account line amount outstanding is 15.00' ); |
1400 |
is( $line->amountoutstanding+0, 15, 'Account line amount outstanding is 15.00' ); |
| 1401 |
is( $line->amount+0, 15, 'Account line amount is 15.00' ); |
1401 |
is( $line->amount+0, 15, 'Account line amount is 15.00' ); |
| 1402 |
is( $line->issue_id, $issue->id, 'Account line issue id matches' ); |
1402 |
is( $line->issue_id, $issue_1->id, 'Account line issue id matches' ); |
| 1403 |
|
1403 |
|
| 1404 |
my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next(); |
1404 |
my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next(); |
| 1405 |
is( $offset->type, 'CREATE', 'Account offset type is CREATE' ); |
1405 |
is( $offset->type, 'CREATE', 'Account offset type is CREATE' ); |
|
Lines 1421-1427
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1421 |
|
1421 |
|
| 1422 |
my $total_due = $dbh->selectrow_array( |
1422 |
my $total_due = $dbh->selectrow_array( |
| 1423 |
'SELECT SUM( amountoutstanding ) FROM accountlines WHERE borrowernumber = ?', |
1423 |
'SELECT SUM( amountoutstanding ) FROM accountlines WHERE borrowernumber = ?', |
| 1424 |
undef, $renewing_borrower->{borrowernumber} |
1424 |
undef, $renewing_borrower_obj->borrowernumber |
| 1425 |
); |
1425 |
); |
| 1426 |
|
1426 |
|
| 1427 |
is( $total_due+0, 15, 'Borrower only charged replacement fee with both WhenLostForgiveFine and WhenLostChargeReplacementFee enabled' ); |
1427 |
is( $total_due+0, 15, 'Borrower only charged replacement fee with both WhenLostForgiveFine and WhenLostChargeReplacementFee enabled' ); |
|
Lines 1430-1438
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1430 |
|
1430 |
|
| 1431 |
C4::Overdues::UpdateFine( |
1431 |
C4::Overdues::UpdateFine( |
| 1432 |
{ |
1432 |
{ |
| 1433 |
issue_id => $issue2->id(), |
1433 |
issue_id => $issue_2->id(), |
| 1434 |
itemnumber => $item_2->itemnumber, |
1434 |
itemnumber => $item_2->itemnumber, |
| 1435 |
borrowernumber => $renewing_borrower->{borrowernumber}, |
1435 |
borrowernumber => $renewing_borrower_obj->borrowernumber, |
| 1436 |
amount => 15.00, |
1436 |
amount => 15.00, |
| 1437 |
type => q{}, |
1437 |
type => q{}, |
| 1438 |
due => Koha::DateUtils::output_pref($datedue) |
1438 |
due => Koha::DateUtils::output_pref($datedue) |
|
Lines 1447-1453
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1447 |
|
1447 |
|
| 1448 |
$total_due = $dbh->selectrow_array( |
1448 |
$total_due = $dbh->selectrow_array( |
| 1449 |
'SELECT SUM( amountoutstanding ) FROM accountlines WHERE borrowernumber = ?', |
1449 |
'SELECT SUM( amountoutstanding ) FROM accountlines WHERE borrowernumber = ?', |
| 1450 |
undef, $renewing_borrower->{borrowernumber} |
1450 |
undef, $renewing_borrower_obj->borrowernumber |
| 1451 |
); |
1451 |
); |
| 1452 |
|
1452 |
|
| 1453 |
ok( $total_due == 15, 'Borrower only charged fine with both WhenLostForgiveFine and WhenLostChargeReplacementFee disabled' ); |
1453 |
ok( $total_due == 15, 'Borrower only charged fine with both WhenLostForgiveFine and WhenLostChargeReplacementFee disabled' ); |
|
Lines 1485-1495
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1485 |
}, |
1485 |
}, |
| 1486 |
}); |
1486 |
}); |
| 1487 |
my $recall_borrower = $builder->build_object({ class => 'Koha::Patrons' }); |
1487 |
my $recall_borrower = $builder->build_object({ class => 'Koha::Patrons' }); |
| 1488 |
my $recall_biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
1488 |
my $recall_biblio = $builder->build_sample_biblio(); |
| 1489 |
my $recall_item1 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1489 |
my $recall_item1 = $builder->build_sample_item({ biblionumber => $recall_biblio->biblionumber }); |
| 1490 |
my $recall_item2 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1490 |
my $recall_item2 = $builder->build_sample_item({ biblionumber => $recall_biblio->biblionumber }); |
| 1491 |
|
1491 |
|
| 1492 |
AddIssue( $renewing_borrower, $recall_item1->barcode ); |
1492 |
my $recall_issue = AddIssue( $renewing_borrower_obj->unblessed, $recall_item1->barcode ); |
| 1493 |
|
1493 |
|
| 1494 |
# item-level and this item: renewal not allowed |
1494 |
# item-level and this item: renewal not allowed |
| 1495 |
my $recall = Koha::Recall->new({ |
1495 |
my $recall = Koha::Recall->new({ |
|
Lines 1499-1505
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1499 |
pickup_library_id => $recall_borrower->branchcode, |
1499 |
pickup_library_id => $recall_borrower->branchcode, |
| 1500 |
item_level => 1, |
1500 |
item_level => 1, |
| 1501 |
})->store; |
1501 |
})->store; |
| 1502 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1502 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $recall_issue ); |
| 1503 |
is( $error, 'recalled', 'Cannot renew item that has been recalled' ); |
1503 |
is( $error, 'recalled', 'Cannot renew item that has been recalled' ); |
| 1504 |
$recall->set_cancelled; |
1504 |
$recall->set_cancelled; |
| 1505 |
|
1505 |
|
|
Lines 1511-1517
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1511 |
pickup_library_id => $recall_borrower->branchcode, |
1511 |
pickup_library_id => $recall_borrower->branchcode, |
| 1512 |
item_level => 0, |
1512 |
item_level => 0, |
| 1513 |
})->store; |
1513 |
})->store; |
| 1514 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1514 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $recall_issue ); |
| 1515 |
is( $error, 'recalled', 'Cannot renew item if biblio is recalled and has no item allocated' ); |
1515 |
is( $error, 'recalled', 'Cannot renew item if biblio is recalled and has no item allocated' ); |
| 1516 |
$recall->set_cancelled; |
1516 |
$recall->set_cancelled; |
| 1517 |
|
1517 |
|
|
Lines 1523-1529
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1523 |
pickup_library_id => $recall_borrower->branchcode, |
1523 |
pickup_library_id => $recall_borrower->branchcode, |
| 1524 |
item_level => 1, |
1524 |
item_level => 1, |
| 1525 |
})->store; |
1525 |
})->store; |
| 1526 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1526 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $recall_issue ); |
| 1527 |
is( $renewokay, 1, 'Can renew item if item-level recall on biblio is not on this item' ); |
1527 |
is( $renewokay, 1, 'Can renew item if item-level recall on biblio is not on this item' ); |
| 1528 |
$recall->set_cancelled; |
1528 |
$recall->set_cancelled; |
| 1529 |
|
1529 |
|
|
Lines 1536-1542
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1536 |
item_level => 0, |
1536 |
item_level => 0, |
| 1537 |
})->store; |
1537 |
})->store; |
| 1538 |
$recall->set_waiting({ item => $recall_item1 }); |
1538 |
$recall->set_waiting({ item => $recall_item1 }); |
| 1539 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1539 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $recall_issue ); |
| 1540 |
is( $renewokay, 1, 'Can renew item if biblio-level recall has already been allocated an item' ); |
1540 |
is( $renewokay, 1, 'Can renew item if biblio-level recall has already been allocated an item' ); |
| 1541 |
$recall->set_cancelled; |
1541 |
$recall->set_cancelled; |
| 1542 |
}; |
1542 |
}; |
|
Lines 1578-1584
subtest "GetUpcomingDueIssues" => sub {
Link Here
|
| 1578 |
|
1578 |
|
| 1579 |
my $issue = AddIssue( $a_borrower, $item_1->barcode, $yesterday ); |
1579 |
my $issue = AddIssue( $a_borrower, $item_1->barcode, $yesterday ); |
| 1580 |
my $datedue = dt_from_string( $issue->date_due() ); |
1580 |
my $datedue = dt_from_string( $issue->date_due() ); |
| 1581 |
my $issue2 = AddIssue( $a_borrower, $item_2->barcode, $two_days_ahead ); |
1581 |
my $issue_2 = AddIssue( $a_borrower, $item_2->barcode, $two_days_ahead ); |
| 1582 |
my $datedue2 = dt_from_string( $issue->date_due() ); |
1582 |
my $datedue2 = dt_from_string( $issue->date_due() ); |
| 1583 |
|
1583 |
|
| 1584 |
my $upcoming_dues; |
1584 |
my $upcoming_dues; |
|
Lines 1704-1715
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Link Here
|
| 1704 |
); |
1704 |
); |
| 1705 |
|
1705 |
|
| 1706 |
|
1706 |
|
| 1707 |
my $borrowernumber1 = Koha::Patron->new({ |
1707 |
my $borrower1 = Koha::Patron->new({ |
| 1708 |
firstname => 'Kyle', |
1708 |
firstname => 'Kyle', |
| 1709 |
surname => 'Hall', |
1709 |
surname => 'Hall', |
| 1710 |
categorycode => $patron_category->{categorycode}, |
1710 |
categorycode => $patron_category->{categorycode}, |
| 1711 |
branchcode => $library2->{branchcode}, |
1711 |
branchcode => $library2->{branchcode}, |
| 1712 |
})->store->borrowernumber; |
1712 |
})->store; |
| 1713 |
my $borrowernumber2 = Koha::Patron->new({ |
1713 |
my $borrowernumber2 = Koha::Patron->new({ |
| 1714 |
firstname => 'Chelsea', |
1714 |
firstname => 'Chelsea', |
| 1715 |
surname => 'Hall', |
1715 |
surname => 'Hall', |
|
Lines 1733-1744
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Link Here
|
| 1733 |
branchcode => $library2->{branchcode}, |
1733 |
branchcode => $library2->{branchcode}, |
| 1734 |
})->store->borrowernumber; |
1734 |
})->store->borrowernumber; |
| 1735 |
|
1735 |
|
| 1736 |
my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed; |
1736 |
my $issue = AddIssue( $borrower1->unblessed, $item_1->barcode ); |
| 1737 |
my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed; |
|
|
| 1738 |
|
1737 |
|
| 1739 |
my $issue = AddIssue( $borrower1, $item_1->barcode ); |
1738 |
my ( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue ); |
| 1740 |
|
|
|
| 1741 |
my ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
| 1742 |
is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' ); |
1739 |
is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' ); |
| 1743 |
|
1740 |
|
| 1744 |
AddReserve( |
1741 |
AddReserve( |
|
Lines 1761-1771
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Link Here
|
| 1761 |
} |
1758 |
} |
| 1762 |
); |
1759 |
); |
| 1763 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 0 ); |
1760 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 0 ); |
| 1764 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1761 |
( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue ); |
| 1765 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfholds are disabled' ); |
1762 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfholds are disabled' ); |
| 1766 |
|
1763 |
|
| 1767 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); |
1764 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); |
| 1768 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1765 |
( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue ); |
| 1769 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled and onshelfholds is disabled' ); |
1766 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled and onshelfholds is disabled' ); |
| 1770 |
|
1767 |
|
| 1771 |
Koha::CirculationRules->set_rules( |
1768 |
Koha::CirculationRules->set_rules( |
|
Lines 1779-1789
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Link Here
|
| 1779 |
} |
1776 |
} |
| 1780 |
); |
1777 |
); |
| 1781 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 0 ); |
1778 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 0 ); |
| 1782 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1779 |
( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue ); |
| 1783 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is disabled and onshelfhold is enabled' ); |
1780 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is disabled and onshelfhold is enabled' ); |
| 1784 |
|
1781 |
|
| 1785 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); |
1782 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); |
| 1786 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1783 |
( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue ); |
| 1787 |
is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' ); |
1784 |
is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' ); |
| 1788 |
|
1785 |
|
| 1789 |
AddReserve( |
1786 |
AddReserve( |
|
Lines 1795-1801
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Link Here
|
| 1795 |
} |
1792 |
} |
| 1796 |
); |
1793 |
); |
| 1797 |
|
1794 |
|
| 1798 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1795 |
( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue ); |
| 1799 |
is( $renewokay, 0, 'Verify the borrower cannot renew with 2 holds on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled and one other item on record' ); |
1796 |
is( $renewokay, 0, 'Verify the borrower cannot renew with 2 holds on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled and one other item on record' ); |
| 1800 |
|
1797 |
|
| 1801 |
my $item_3= $builder->build_sample_item( |
1798 |
my $item_3= $builder->build_sample_item( |
|
Lines 1806-1812
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Link Here
|
| 1806 |
} |
1803 |
} |
| 1807 |
); |
1804 |
); |
| 1808 |
|
1805 |
|
| 1809 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1806 |
( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue ); |
| 1810 |
is( $renewokay, 1, 'Verify the borrower cannot renew with 2 holds on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled and two other items on record' ); |
1807 |
is( $renewokay, 1, 'Verify the borrower cannot renew with 2 holds on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled and two other items on record' ); |
| 1811 |
|
1808 |
|
| 1812 |
Koha::CirculationRules->set_rules( |
1809 |
Koha::CirculationRules->set_rules( |
|
Lines 1820-1826
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Link Here
|
| 1820 |
} |
1817 |
} |
| 1821 |
); |
1818 |
); |
| 1822 |
|
1819 |
|
| 1823 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1820 |
( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue ); |
| 1824 |
is( $renewokay, 0, 'Verify the borrower cannot renew with 2 holds on the record, but only one of those holds can be filled when AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled and two other items on record' ); |
1821 |
is( $renewokay, 0, 'Verify the borrower cannot renew with 2 holds on the record, but only one of those holds can be filled when AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled and two other items on record' ); |
| 1825 |
|
1822 |
|
| 1826 |
Koha::CirculationRules->set_rules( |
1823 |
Koha::CirculationRules->set_rules( |
|
Lines 1837-1843
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Link Here
|
| 1837 |
# Setting item not checked out to be not for loan but holdable |
1834 |
# Setting item not checked out to be not for loan but holdable |
| 1838 |
$item_2->notforloan(-1)->store; |
1835 |
$item_2->notforloan(-1)->store; |
| 1839 |
|
1836 |
|
| 1840 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1837 |
( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue ); |
| 1841 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower can not renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled but the only available item is notforloan' ); |
1838 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower can not renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled but the only available item is notforloan' ); |
| 1842 |
|
1839 |
|
| 1843 |
my $mock_circ = Test::MockModule->new("C4::Circulation"); |
1840 |
my $mock_circ = Test::MockModule->new("C4::Circulation"); |
|
Lines 1851-1857
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Link Here
|
| 1851 |
# Two items total, one item available, one issued, two holds on record |
1848 |
# Two items total, one item available, one issued, two holds on record |
| 1852 |
|
1849 |
|
| 1853 |
warnings_are{ |
1850 |
warnings_are{ |
| 1854 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1851 |
( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue ); |
| 1855 |
} [], "CanItemBeReserved not called when there are more possible holds than available items"; |
1852 |
} [], "CanItemBeReserved not called when there are more possible holds than available items"; |
| 1856 |
is( $renewokay, 0, 'Borrower cannot renew when there are more holds than available items' ); |
1853 |
is( $renewokay, 0, 'Borrower cannot renew when there are more holds than available items' ); |
| 1857 |
|
1854 |
|
|
Lines 1875-1881
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Link Here
|
| 1875 |
); |
1872 |
); |
| 1876 |
|
1873 |
|
| 1877 |
warnings_are{ |
1874 |
warnings_are{ |
| 1878 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1875 |
( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue ); |
| 1879 |
} ["Checked","Checked"], "CanItemBeReserved only called once per available item if it returns a negative result for all items for a borrower"; |
1876 |
} ["Checked","Checked"], "CanItemBeReserved only called once per available item if it returns a negative result for all items for a borrower"; |
| 1880 |
is( $renewokay, 0, 'Borrower cannot renew when there are more holds than available items' ); |
1877 |
is( $renewokay, 0, 'Borrower cannot renew when there are more holds than available items' ); |
| 1881 |
|
1878 |
|
|
Lines 1896-1912
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Link Here
|
| 1896 |
} |
1893 |
} |
| 1897 |
); |
1894 |
); |
| 1898 |
|
1895 |
|
| 1899 |
my $borrowernumber = Koha::Patron->new({ |
1896 |
my $borrower = Koha::Patron->new({ |
| 1900 |
firstname => 'fn', |
1897 |
firstname => 'fn', |
| 1901 |
surname => 'dn', |
1898 |
surname => 'dn', |
| 1902 |
categorycode => $patron_category->{categorycode}, |
1899 |
categorycode => $patron_category->{categorycode}, |
| 1903 |
branchcode => $branch, |
1900 |
branchcode => $branch, |
| 1904 |
})->store->borrowernumber; |
1901 |
})->store; |
| 1905 |
|
|
|
| 1906 |
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; |
| 1907 |
|
1902 |
|
| 1908 |
my $issue = AddIssue( $borrower, $item->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } ); |
1903 |
my $issue = AddIssue( $borrower->unblessed, $item->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } ); |
| 1909 |
my ( $renewed, $error ) = CanBookBeRenewed( $borrowernumber, $item->itemnumber ); |
1904 |
my ( $renewed, $error ) = CanBookBeRenewed( $borrower, $issue ); |
| 1910 |
is( $renewed, 0, 'CanBookBeRenewed should not allow to renew on-site checkout' ); |
1905 |
is( $renewed, 0, 'CanBookBeRenewed should not allow to renew on-site checkout' ); |
| 1911 |
is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' ); |
1906 |
is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' ); |
| 1912 |
} |
1907 |
} |
|
Lines 1923-1946
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Link Here
|
| 1923 |
itype => $itemtype, |
1918 |
itype => $itemtype, |
| 1924 |
} |
1919 |
} |
| 1925 |
); |
1920 |
); |
|
|
1921 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } ); |
| 1926 |
|
1922 |
|
| 1927 |
my $patron = $builder->build({ source => 'Borrower', value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } ); |
1923 |
my $issue = AddIssue( $patron->unblessed, $item->barcode ); |
| 1928 |
|
|
|
| 1929 |
my $issue = AddIssue( $patron, $item->barcode ); |
| 1930 |
UpdateFine( |
1924 |
UpdateFine( |
| 1931 |
{ |
1925 |
{ |
| 1932 |
issue_id => $issue->id(), |
1926 |
issue_id => $issue->id, |
| 1933 |
itemnumber => $item->itemnumber, |
1927 |
itemnumber => $item->itemnumber, |
| 1934 |
borrowernumber => $patron->{borrowernumber}, |
1928 |
borrowernumber => $patron->borrowernumber, |
| 1935 |
amount => 1, |
1929 |
amount => 1, |
| 1936 |
type => q{} |
1930 |
type => q{} |
| 1937 |
} |
1931 |
} |
| 1938 |
); |
1932 |
); |
| 1939 |
UpdateFine( |
1933 |
UpdateFine( |
| 1940 |
{ |
1934 |
{ |
| 1941 |
issue_id => $issue->id(), |
1935 |
issue_id => $issue->id, |
| 1942 |
itemnumber => $item->itemnumber, |
1936 |
itemnumber => $item->itemnumber, |
| 1943 |
borrowernumber => $patron->{borrowernumber}, |
1937 |
borrowernumber => $patron->borrowernumber, |
| 1944 |
amount => 2, |
1938 |
amount => 2, |
| 1945 |
type => q{} |
1939 |
type => q{} |
| 1946 |
} |
1940 |
} |
|
Lines 2365-2373
subtest 'MultipleReserves' => sub {
Link Here
|
| 2365 |
categorycode => $patron_category->{categorycode}, |
2359 |
categorycode => $patron_category->{categorycode}, |
| 2366 |
branchcode => $branch, |
2360 |
branchcode => $branch, |
| 2367 |
); |
2361 |
); |
| 2368 |
my $renewing_borrowernumber = Koha::Patron->new(\%renewing_borrower_data)->store->borrowernumber; |
2362 |
my $patron = Koha::Patron->new(\%renewing_borrower_data)->store; |
| 2369 |
my $renewing_borrower = Koha::Patrons->find( $renewing_borrowernumber )->unblessed; |
2363 |
my $issue = AddIssue( $patron->unblessed, $item_1->barcode); |
| 2370 |
my $issue = AddIssue( $renewing_borrower, $item_1->barcode); |
|
|
| 2371 |
my $datedue = dt_from_string( $issue->date_due() ); |
2364 |
my $datedue = dt_from_string( $issue->date_due() ); |
| 2372 |
is (defined $issue->date_due(), 1, "item 1 checked out"); |
2365 |
is (defined $issue->date_due(), 1, "item 1 checked out"); |
| 2373 |
my $borrowing_borrowernumber = Koha::Checkouts->find({ itemnumber => $item_1->itemnumber })->borrowernumber; |
2366 |
my $borrowing_borrowernumber = Koha::Checkouts->find({ itemnumber => $item_1->itemnumber })->borrowernumber; |
|
Lines 2415-2421
subtest 'MultipleReserves' => sub {
Link Here
|
| 2415 |
); |
2408 |
); |
| 2416 |
|
2409 |
|
| 2417 |
{ |
2410 |
{ |
| 2418 |
my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1); |
2411 |
my ( $renewokay, $error ) = CanBookBeRenewed($patron, $issue, 1); |
| 2419 |
is($renewokay, 0, 'Bug 17941 - should cover the case where 2 books are both reserved, so failing'); |
2412 |
is($renewokay, 0, 'Bug 17941 - should cover the case where 2 books are both reserved, so failing'); |
| 2420 |
} |
2413 |
} |
| 2421 |
|
2414 |
|
|
Lines 2429-2435
subtest 'MultipleReserves' => sub {
Link Here
|
| 2429 |
); |
2422 |
); |
| 2430 |
|
2423 |
|
| 2431 |
{ |
2424 |
{ |
| 2432 |
my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1); |
2425 |
my ( $renewokay, $error ) = CanBookBeRenewed($patron, $issue, 1); |
| 2433 |
is($renewokay, 1, 'Bug 17941 - should cover the case where 2 books are reserved, but a third one is available'); |
2426 |
is($renewokay, 1, 'Bug 17941 - should cover the case where 2 books are reserved, but a third one is available'); |
| 2434 |
} |
2427 |
} |
| 2435 |
}; |
2428 |
}; |
|
Lines 4031-4037
subtest 'Set waiting flag' => sub {
Link Here
|
| 4031 |
my $hold = Koha::Holds->find( $reserve_id ); |
4024 |
my $hold = Koha::Holds->find( $reserve_id ); |
| 4032 |
is( $hold->found, 'T', 'Hold is in transit' ); |
4025 |
is( $hold->found, 'T', 'Hold is in transit' ); |
| 4033 |
|
4026 |
|
| 4034 |
my ( $status ) = CheckReserves($item->itemnumber); |
4027 |
my ( $status ) = CheckReserves($item); |
| 4035 |
is( $status, 'Transferred', 'Hold is not waiting yet'); |
4028 |
is( $status, 'Transferred', 'Hold is not waiting yet'); |
| 4036 |
|
4029 |
|
| 4037 |
set_userenv( $library_2 ); |
4030 |
set_userenv( $library_2 ); |
|
Lines 4040-4046
subtest 'Set waiting flag' => sub {
Link Here
|
| 4040 |
ModReserveAffect( $item->itemnumber, undef, $do_transfer, $reserve_id ); |
4033 |
ModReserveAffect( $item->itemnumber, undef, $do_transfer, $reserve_id ); |
| 4041 |
$hold = Koha::Holds->find( $reserve_id ); |
4034 |
$hold = Koha::Holds->find( $reserve_id ); |
| 4042 |
is( $hold->found, 'W', 'Hold is waiting' ); |
4035 |
is( $hold->found, 'W', 'Hold is waiting' ); |
| 4043 |
( $status ) = CheckReserves($item->itemnumber); |
4036 |
( $status ) = CheckReserves($item); |
| 4044 |
is( $status, 'Waiting', 'Now the hold is waiting'); |
4037 |
is( $status, 'Waiting', 'Now the hold is waiting'); |
| 4045 |
|
4038 |
|
| 4046 |
#Bug 21944 - Waiting transfer checked in at branch other than pickup location |
4039 |
#Bug 21944 - Waiting transfer checked in at branch other than pickup location |
|
Lines 4225-4238
subtest 'ItemsDeniedRenewal rules are checked' => sub {
Link Here
|
| 4225 |
my $mock_item_class = Test::MockModule->new("Koha::Item"); |
4218 |
my $mock_item_class = Test::MockModule->new("Koha::Item"); |
| 4226 |
$mock_item_class->mock( 'is_denied_renewal', sub { return 1; } ); |
4219 |
$mock_item_class->mock( 'is_denied_renewal', sub { return 1; } ); |
| 4227 |
|
4220 |
|
| 4228 |
my ( $mayrenew, $error ) = CanBookBeRenewed( $idr_borrower->borrowernumber, $issue->itemnumber ); |
4221 |
my ( $mayrenew, $error ) = CanBookBeRenewed( $idr_borrower, $issue ); |
| 4229 |
is( $mayrenew, 0, 'Renewal blocked when $item->is_denied_renewal returns true' ); |
4222 |
is( $mayrenew, 0, 'Renewal blocked when $item->is_denied_renewal returns true' ); |
| 4230 |
is( $error, 'item_denied_renewal', 'Renewal blocked when $item->is_denied_renewal returns true' ); |
4223 |
is( $error, 'item_denied_renewal', 'Renewal blocked when $item->is_denied_renewal returns true' ); |
| 4231 |
|
4224 |
|
| 4232 |
$mock_item_class->unmock( 'is_denied_renewal' ); |
4225 |
$mock_item_class->unmock( 'is_denied_renewal' ); |
| 4233 |
$mock_item_class->mock( 'is_denied_renewal', sub { return 0; } ); |
4226 |
$mock_item_class->mock( 'is_denied_renewal', sub { return 0; } ); |
| 4234 |
|
4227 |
|
| 4235 |
( $mayrenew, $error ) = CanBookBeRenewed( $idr_borrower->borrowernumber, $issue->itemnumber ); |
4228 |
( $mayrenew, $error ) = CanBookBeRenewed( $idr_borrower, $issue ); |
| 4236 |
is( $mayrenew, 1, 'Renewal allowed when $item->is_denied_renewal returns false' ); |
4229 |
is( $mayrenew, 1, 'Renewal allowed when $item->is_denied_renewal returns false' ); |
| 4237 |
is( $error, undef, 'Renewal allowed when $item->is_denied_renewal returns false' ); |
4230 |
is( $error, undef, 'Renewal allowed when $item->is_denied_renewal returns false' ); |
| 4238 |
|
4231 |
|
|
Lines 5720-5726
subtest "GetSoonestRenewDate tests" => sub {
Link Here
|
| 5720 |
# Test 'exact time' setting for syspref NoRenewalBeforePrecision |
5713 |
# Test 'exact time' setting for syspref NoRenewalBeforePrecision |
| 5721 |
t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact_time' ); |
5714 |
t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact_time' ); |
| 5722 |
is( |
5715 |
is( |
| 5723 |
GetSoonestRenewDate( $issue ), |
5716 |
GetSoonestRenewDate( $patron, $issue ), |
| 5724 |
$datedue->clone->add( days => -7 ), |
5717 |
$datedue->clone->add( days => -7 ), |
| 5725 |
'Bug 14395: Renewals permitted 7 days before due date, as expected' |
5718 |
'Bug 14395: Renewals permitted 7 days before due date, as expected' |
| 5726 |
); |
5719 |
); |
|
Lines 5729-5735
subtest "GetSoonestRenewDate tests" => sub {
Link Here
|
| 5729 |
# Test 'date' setting for syspref NoRenewalBeforePrecision |
5722 |
# Test 'date' setting for syspref NoRenewalBeforePrecision |
| 5730 |
t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' ); |
5723 |
t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' ); |
| 5731 |
is( |
5724 |
is( |
| 5732 |
GetSoonestRenewDate( $issue ), |
5725 |
GetSoonestRenewDate( $patron, $issue ), |
| 5733 |
$datedue->clone->add( days => -7 )->truncate( to => 'day' ), |
5726 |
$datedue->clone->add( days => -7 )->truncate( to => 'day' ), |
| 5734 |
'Bug 14395: Renewals permitted 7 days before due date, as expected' |
5727 |
'Bug 14395: Renewals permitted 7 days before due date, as expected' |
| 5735 |
); |
5728 |
); |
|
Lines 5746-5752
subtest "GetSoonestRenewDate tests" => sub {
Link Here
|
| 5746 |
); |
5739 |
); |
| 5747 |
|
5740 |
|
| 5748 |
is( |
5741 |
is( |
| 5749 |
GetSoonestRenewDate( $issue ), |
5742 |
GetSoonestRenewDate( $patron, $issue ), |
| 5750 |
dt_from_string, |
5743 |
dt_from_string, |
| 5751 |
'Checkouts without auto-renewal can be renewed immediately if no norenewalbefore' |
5744 |
'Checkouts without auto-renewal can be renewed immediately if no norenewalbefore' |
| 5752 |
); |
5745 |
); |
|
Lines 5754-5766
subtest "GetSoonestRenewDate tests" => sub {
Link Here
|
| 5754 |
t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' ); |
5747 |
t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' ); |
| 5755 |
$issue->auto_renew(1)->store; |
5748 |
$issue->auto_renew(1)->store; |
| 5756 |
is( |
5749 |
is( |
| 5757 |
GetSoonestRenewDate( $issue ), |
5750 |
GetSoonestRenewDate( $patron, $issue ), |
| 5758 |
$datedue->clone->truncate( to => 'day' ), |
5751 |
$datedue->clone->truncate( to => 'day' ), |
| 5759 |
'Checkouts with auto-renewal can be renewed earliest on due date if no renewalbefore' |
5752 |
'Checkouts with auto-renewal can be renewed earliest on due date if no renewalbefore' |
| 5760 |
); |
5753 |
); |
| 5761 |
t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact' ); |
5754 |
t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact' ); |
| 5762 |
is( |
5755 |
is( |
| 5763 |
GetSoonestRenewDate( $issue ), |
5756 |
GetSoonestRenewDate( $patron, $issue ), |
| 5764 |
$datedue, |
5757 |
$datedue, |
| 5765 |
'Checkouts with auto-renewal can be renewed earliest on due date if no renewalbefore' |
5758 |
'Checkouts with auto-renewal can be renewed earliest on due date if no renewalbefore' |
| 5766 |
); |
5759 |
); |
|
Lines 5773-5779
subtest "CanBookBeIssued + needsconfirmation message" => sub {
Link Here
|
| 5773 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
5766 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 5774 |
my $biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
5767 |
my $biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
| 5775 |
my $biblioitem = $builder->build_object({ class => 'Koha::Biblioitems', value => { biblionumber => $biblio->biblionumber }}); |
5768 |
my $biblioitem = $builder->build_object({ class => 'Koha::Biblioitems', value => { biblionumber => $biblio->biblionumber }}); |
| 5776 |
my $item = $builder->build_object({ class => 'Koha::Items' , value => { biblionumber => $biblio->biblionumber }}); |
5769 |
my $item = $builder->build_object({ class => 'Koha::Items' , value => { itype => $itemtype, biblionumber => $biblio->biblionumber }}); |
| 5777 |
|
5770 |
|
| 5778 |
my $hold = $builder->build_object({ class => 'Koha::Holds', value => { |
5771 |
my $hold = $builder->build_object({ class => 'Koha::Holds', value => { |
| 5779 |
biblionumber => $item->biblionumber, |
5772 |
biblionumber => $item->biblionumber, |