Lines 533-539
C4::Context->dbh->do("DELETE FROM accountlines");
Link Here
|
533 |
); |
533 |
); |
534 |
|
534 |
|
535 |
subtest "too_late_renewal / no_auto_renewal_after" => sub { |
535 |
subtest "too_late_renewal / no_auto_renewal_after" => sub { |
536 |
plan tests => 8; |
536 |
plan tests => 14; |
537 |
my $item_to_auto_renew = $builder->build( |
537 |
my $item_to_auto_renew = $builder->build( |
538 |
{ source => 'Item', |
538 |
{ source => 'Item', |
539 |
value => { |
539 |
value => { |
Lines 571-580
C4::Context->dbh->do("DELETE FROM accountlines");
Link Here
|
571 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
571 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
572 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
572 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
573 |
is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); |
573 |
is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); |
|
|
574 |
|
575 |
$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 ) ); |
576 |
( $renewokay, $error ) = |
577 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
578 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
579 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
580 |
|
581 |
$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 ) ); |
582 |
( $renewokay, $error ) = |
583 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
584 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
585 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
586 |
|
587 |
$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 ) ); |
588 |
( $renewokay, $error ) = |
589 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
590 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
591 |
is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); |
574 |
}; |
592 |
}; |
575 |
|
593 |
|
576 |
subtest "GetLatestAutoRenewDate" => sub { |
594 |
subtest "GetLatestAutoRenewDate" => sub { |
577 |
plan tests => 3; |
595 |
plan tests => 5; |
578 |
my $item_to_auto_renew = $builder->build( |
596 |
my $item_to_auto_renew = $builder->build( |
579 |
{ source => 'Item', |
597 |
{ source => 'Item', |
580 |
value => { |
598 |
value => { |
Lines 588-610
C4::Context->dbh->do("DELETE FROM accountlines");
Link Here
|
588 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
606 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
589 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
607 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
590 |
AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
608 |
AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
591 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = ""'); |
609 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = "", no_auto_renewal_after_hard_limit = NULL'); |
592 |
my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
610 |
my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
593 |
is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after is not defined' ); |
611 |
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' ); |
594 |
my $five_days_before = dt_from_string->add( days => -5 ); |
612 |
my $five_days_before = dt_from_string->add( days => -5 ); |
595 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5'); |
613 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5, no_auto_renewal_after_hard_limit = NULL'); |
596 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
614 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
597 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
615 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
598 |
$five_days_before->truncate( to => 'minute' ), |
616 |
$five_days_before->truncate( to => 'minute' ), |
599 |
'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before' |
617 |
'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before' |
600 |
); |
618 |
); |
601 |
my $five_days_ahead = dt_from_string->add( days => 5 ); |
619 |
my $five_days_ahead = dt_from_string->add( days => 5 ); |
602 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15'); |
620 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = NULL'); |
603 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
621 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
604 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
622 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
605 |
$five_days_ahead->truncate( to => 'minute' ), |
623 |
$five_days_ahead->truncate( to => 'minute' ), |
606 |
'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before' |
624 |
'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before' |
607 |
); |
625 |
); |
|
|
626 |
my $two_days_ahead = dt_from_string->add( days => 2 ); |
627 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = "", no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 2 ) ); |
628 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
629 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
630 |
$two_days_ahead->truncate( to => 'day' ), |
631 |
'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is defined and not no_auto_renewal_after' |
632 |
); |
633 |
$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 ) ); |
634 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
635 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
636 |
$two_days_ahead->truncate( to => 'day' ), |
637 |
'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is < no_auto_renewal_after' |
638 |
); |
639 |
|
608 |
}; |
640 |
}; |
609 |
|
641 |
|
610 |
# Too many renewals |
642 |
# Too many renewals |
611 |
- |
|
|