From a71c21d2ffc9ea6863bf897270fdcdc923813286 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 26 Oct 2023 09:08:04 +0100 Subject: [PATCH] Bug 31427: (follow-up) Unit tests This patch adds a unit test for error precidence where autorenewals is involved. It is not comprehensive however, and I'm a little confused by the logic around cron vs non-cron handling... Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer --- t/db_dependent/Circulation.t | 45 +++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 5095afde73..cd8192f4f6 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -431,7 +431,7 @@ subtest "GetIssuingCharges tests" => sub { my ( $reused_itemnumber_1, $reused_itemnumber_2 ); subtest "CanBookBeRenewed tests" => sub { - plan tests => 113; + plan tests => 114; C4::Context->set_preference('ItemsDeniedRenewal',''); # Generate test biblio @@ -1011,6 +1011,49 @@ subtest "CanBookBeRenewed tests" => sub { is( $renewokay, 1, 'No renewal before is 99, patron opted out of auto_renewal so can renew' ); $renewing_borrower_obj->autorenew_checkouts(1)->store; + + # Bug 31427 + # Ensure autorenewal errors always take highest precedence + subtest "auto_renewal errors first" => sub { + plan tests => 4; + + my $auto_renew_item = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + library => $branch, + } + ); + + my $ten_days_ahead = dt_from_string->add( days => 10 ); + my $issue = AddIssue( + $renewing_borrower_obj, $auto_renew_item->barcode, $ten_days_ahead, undef, undef, undef, + { auto_renew => 1 } + ); + + Koha::CirculationRules->set_rules( + { + categorycode => undef, + branchcode => undef, + itemtype => undef, + rules => { + noautorenewalbefore => 7, + renewalsallowed => 2, + } + } + ); + my ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue, undef, 'cron' ); + is( $renewokay, 0, 'Do not renew, renewal is automatic' ); + is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - returned code is auto_too_soon' ); + + $issue->renewals_count(2)->store; + ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue, undef, 'cron' ); + is( $renewokay, 0, 'Do not renew, renewal is automatic' ); + is( + $error, 'auto_too_soon', + 'Cannot auto renew, too soon - auto renewal error takes precedence over non-autorenewal error too_many' + ); + }; + subtest "too_late_renewal / no_auto_renewal_after" => sub { plan tests => 16; my $item_to_auto_renew = $builder->build_sample_item( -- 2.39.5