|
Lines 579-585
C4::Context->dbh->do("DELETE FROM accountlines");
Link Here
|
| 579 |
); |
579 |
); |
| 580 |
|
580 |
|
| 581 |
subtest "too_late_renewal / no_auto_renewal_after" => sub { |
581 |
subtest "too_late_renewal / no_auto_renewal_after" => sub { |
| 582 |
plan tests => 8; |
582 |
plan tests => 14; |
| 583 |
my $item_to_auto_renew = $builder->build( |
583 |
my $item_to_auto_renew = $builder->build( |
| 584 |
{ source => 'Item', |
584 |
{ source => 'Item', |
| 585 |
value => { |
585 |
value => { |
|
Lines 617-626
C4::Context->dbh->do("DELETE FROM accountlines");
Link Here
|
| 617 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
617 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 618 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
618 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 619 |
is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); |
619 |
is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); |
|
|
620 |
|
| 621 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = NULL, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => -1 ) ); |
| 622 |
( $renewokay, $error ) = |
| 623 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 624 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 625 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
| 626 |
|
| 627 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => -1 ) ); |
| 628 |
( $renewokay, $error ) = |
| 629 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 630 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 631 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
| 632 |
|
| 633 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = NULL, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 1 ) ); |
| 634 |
( $renewokay, $error ) = |
| 635 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 636 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 637 |
is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); |
| 620 |
}; |
638 |
}; |
| 621 |
|
639 |
|
| 622 |
subtest "GetLatestAutoRenewDate" => sub { |
640 |
subtest "GetLatestAutoRenewDate" => sub { |
| 623 |
plan tests => 3; |
641 |
plan tests => 5; |
| 624 |
my $item_to_auto_renew = $builder->build( |
642 |
my $item_to_auto_renew = $builder->build( |
| 625 |
{ source => 'Item', |
643 |
{ source => 'Item', |
| 626 |
value => { |
644 |
value => { |
|
Lines 634-656
C4::Context->dbh->do("DELETE FROM accountlines");
Link Here
|
| 634 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
652 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
| 635 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
653 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
| 636 |
AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
654 |
AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
| 637 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = ""'); |
655 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = "", no_auto_renewal_after_hard_limit = NULL'); |
| 638 |
my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
656 |
my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 639 |
is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after is not defined' ); |
657 |
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' ); |
| 640 |
my $five_days_before = dt_from_string->add( days => -5 ); |
658 |
my $five_days_before = dt_from_string->add( days => -5 ); |
| 641 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5'); |
659 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5, no_auto_renewal_after_hard_limit = NULL'); |
| 642 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
660 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 643 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
661 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
| 644 |
$five_days_before->truncate( to => 'minute' ), |
662 |
$five_days_before->truncate( to => 'minute' ), |
| 645 |
'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before' |
663 |
'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before' |
| 646 |
); |
664 |
); |
| 647 |
my $five_days_ahead = dt_from_string->add( days => 5 ); |
665 |
my $five_days_ahead = dt_from_string->add( days => 5 ); |
| 648 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15'); |
666 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = NULL'); |
| 649 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
667 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 650 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
668 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
| 651 |
$five_days_ahead->truncate( to => 'minute' ), |
669 |
$five_days_ahead->truncate( to => 'minute' ), |
| 652 |
'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before' |
670 |
'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before' |
| 653 |
); |
671 |
); |
|
|
672 |
my $two_days_ahead = dt_from_string->add( days => 2 ); |
| 673 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = "", no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 2 ) ); |
| 674 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 675 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
| 676 |
$two_days_ahead->truncate( to => 'day' ), |
| 677 |
'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is defined and not no_auto_renewal_after' |
| 678 |
); |
| 679 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 2 ) ); |
| 680 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 681 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
| 682 |
$two_days_ahead->truncate( to => 'day' ), |
| 683 |
'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is < no_auto_renewal_after' |
| 684 |
); |
| 685 |
|
| 654 |
}; |
686 |
}; |
| 655 |
|
687 |
|
| 656 |
# Too many renewals |
688 |
# Too many renewals |
| 657 |
- |
|
|