From aa485dc3897c85ad9e5001651b25cadff0a00ae5 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 1 May 2024 17:26:03 +0100 Subject: [PATCH] Bug 33260: (QA follow-up) Correct relation accessor and add unit test We were missing unit tests for the patron relation accessor added to Koha::Notice::Message and once I looked at adding the test I spotted the accessor was also using a rather outdated form. Signed-off-by: Martin Renvoize --- Koha/Notice/Message.pm | 11 +++++------ t/db_dependent/Koha/Notice/Message.t | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Koha/Notice/Message.pm b/Koha/Notice/Message.pm index 2146e1a6d31..57d99cf67c7 100644 --- a/Koha/Notice/Message.pm +++ b/Koha/Notice/Message.pm @@ -90,18 +90,17 @@ EOS =head3 patron - my $patron = $message->patron; + my $patron = $checkout->patron -Returns the Koha::Patron object for the recipient of the queued message +Return the patron by whom the checkout was done =cut sub patron { my ($self) = @_; - - $self->{_patron} ||= Koha::Patrons->find( $self->borrowernumber ); - - return $self->{_patron}; + my $patron_rs = $self->_result->borrowernumber; + return unless $patron_rs; + return Koha::Patron->_new_from_dbic($patron_rs); } =head3 type diff --git a/t/db_dependent/Koha/Notice/Message.t b/t/db_dependent/Koha/Notice/Message.t index 94c383f3b75..7c6716a69f2 100755 --- a/t/db_dependent/Koha/Notice/Message.t +++ b/t/db_dependent/Koha/Notice/Message.t @@ -218,4 +218,24 @@ WRAPPED $schema->storage->txn_rollback; }; +subtest 'patron() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $message = $builder->build_object( + { + class => 'Koha::Notice::Messages', + value => { borrowernumber => $patron->borrowernumber } + } + ); + + is( ref( $message->patron ), 'Koha::Patron', 'Object type is correct' ); + is( $message->patron->borrowernumber, $patron->borrowernumber, 'Right patron linked' ); + + $schema->storage->txn_rollback; +}; + 1; -- 2.45.0