|
Lines 551-557
C4::Context->dbh->do("DELETE FROM accountlines");
Link Here
|
| 551 |
); |
551 |
); |
| 552 |
|
552 |
|
| 553 |
subtest "too_late_renewal / no_auto_renewal_after" => sub { |
553 |
subtest "too_late_renewal / no_auto_renewal_after" => sub { |
| 554 |
plan tests => 8; |
554 |
plan tests => 14; |
| 555 |
my $item_to_auto_renew = $builder->build( |
555 |
my $item_to_auto_renew = $builder->build( |
| 556 |
{ source => 'Item', |
556 |
{ source => 'Item', |
| 557 |
value => { |
557 |
value => { |
|
Lines 589-598
C4::Context->dbh->do("DELETE FROM accountlines");
Link Here
|
| 589 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
589 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 590 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
590 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 591 |
is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); |
591 |
is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); |
|
|
592 |
|
| 593 |
$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 ) ); |
| 594 |
( $renewokay, $error ) = |
| 595 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 596 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 597 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
| 598 |
|
| 599 |
$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 ) ); |
| 600 |
( $renewokay, $error ) = |
| 601 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 602 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 603 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
| 604 |
|
| 605 |
$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 ) ); |
| 606 |
( $renewokay, $error ) = |
| 607 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 608 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
| 609 |
is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); |
| 592 |
}; |
610 |
}; |
| 593 |
|
611 |
|
| 594 |
subtest "GetLatestAutoRenewDate" => sub { |
612 |
subtest "GetLatestAutoRenewDate" => sub { |
| 595 |
plan tests => 3; |
613 |
plan tests => 5; |
| 596 |
my $item_to_auto_renew = $builder->build( |
614 |
my $item_to_auto_renew = $builder->build( |
| 597 |
{ source => 'Item', |
615 |
{ source => 'Item', |
| 598 |
value => { |
616 |
value => { |
|
Lines 606-628
C4::Context->dbh->do("DELETE FROM accountlines");
Link Here
|
| 606 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
624 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
| 607 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
625 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
| 608 |
AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
626 |
AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
| 609 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = ""'); |
627 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = "", no_auto_renewal_after_hard_limit = NULL'); |
| 610 |
my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
628 |
my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 611 |
is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after is not defined' ); |
629 |
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' ); |
| 612 |
my $five_days_before = dt_from_string->add( days => -5 ); |
630 |
my $five_days_before = dt_from_string->add( days => -5 ); |
| 613 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5'); |
631 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5, no_auto_renewal_after_hard_limit = NULL'); |
| 614 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
632 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 615 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
633 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
| 616 |
$five_days_before->truncate( to => 'minute' ), |
634 |
$five_days_before->truncate( to => 'minute' ), |
| 617 |
'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before' |
635 |
'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before' |
| 618 |
); |
636 |
); |
| 619 |
my $five_days_ahead = dt_from_string->add( days => 5 ); |
637 |
my $five_days_ahead = dt_from_string->add( days => 5 ); |
| 620 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15'); |
638 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = NULL'); |
| 621 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
639 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 622 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
640 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
| 623 |
$five_days_ahead->truncate( to => 'minute' ), |
641 |
$five_days_ahead->truncate( to => 'minute' ), |
| 624 |
'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before' |
642 |
'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before' |
| 625 |
); |
643 |
); |
|
|
644 |
my $two_days_ahead = dt_from_string->add( days => 2 ); |
| 645 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = "", no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 2 ) ); |
| 646 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 647 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
| 648 |
$two_days_ahead->truncate( to => 'day' ), |
| 649 |
'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is defined and not no_auto_renewal_after' |
| 650 |
); |
| 651 |
$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 ) ); |
| 652 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 653 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
| 654 |
$two_days_ahead->truncate( to => 'day' ), |
| 655 |
'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is < no_auto_renewal_after' |
| 656 |
); |
| 657 |
|
| 626 |
}; |
658 |
}; |
| 627 |
|
659 |
|
| 628 |
# Too many renewals |
660 |
# Too many renewals |
| 629 |
- |
|
|