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