From b4632daa7cb6fdb25c82a6ab30220feffc562222 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Wed, 28 Feb 2024 16:59:29 +0100 Subject: [PATCH] Bug 32476: Fix Circulation tests and exclude cache param from cache key --- Koha/Object.pm | 10 ++++++---- t/db_dependent/Circulation.t | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Koha/Object.pm b/Koha/Object.pm index 4086caf3169..5c54ae020bc 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -177,16 +177,18 @@ my $value = Koha::Object->_method_cache($method_name, @args); sub _method_cache { my ($self, $method_name, @args) = @_; + # Don't include in cache key. Must also be unset in + # possible uncached call to $method_name below + if (@args) { + delete $args[0]->{cache}; + } + my $cache_key = $self->_method_cache_key($method_name, @args); my $value = $self->_instance_cache_get($cache_key); return $value if defined $value; - if (@args) { - delete $args[0]->{cache}; - } $value = $self->$method_name(@args); - $self->_instance_cache_set($cache_key, $value); return $value; diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 5095afde735..2429bd86c91 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -734,6 +734,9 @@ subtest "CanBookBeRenewed tests" => sub { is( $renewokay, 1, '(Bug 8236), Can renew, this item is overdue but not pref does not block'); t::lib::Mocks::mock_preference('OverduesBlockRenewing','block'); + # Clear cache after changing preference affecting has_overdues evaluation + $renewing_borrower_obj->_method_cache_clear('has_overdues'); + ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_6); is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is not overdue but patron has overdues'); is( $error, 'overdue', "Correct error returned"); @@ -742,6 +745,9 @@ subtest "CanBookBeRenewed tests" => sub { is( $error, 'overdue', "Correct error returned"); t::lib::Mocks::mock_preference('OverduesBlockRenewing','blockitem'); + # Clear cache after changing preference affecting has_overdues evaluation + $renewing_borrower_obj->_method_cache_clear('has_overdues'); + ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_6); is( $renewokay, 1, '(Bug 8236), Can renew, this item is not overdue'); ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_7); -- 2.43.0