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