From 44050929032d3a0465bfc8d3a2a6c305043b99ce 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. --- Koha/Notice/Message.pm | 11 +++++------ t/db_dependent/Koha/Notice/Message.t | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Koha/Notice/Message.pm b/Koha/Notice/Message.pm index 65c6df18df2..c7b03d299db 100644 --- a/Koha/Notice/Message.pm +++ b/Koha/Notice/Message.pm @@ -67,18 +67,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 72192655f9c..28394bb0ba2 100755 --- a/t/db_dependent/Koha/Notice/Message.t +++ b/t/db_dependent/Koha/Notice/Message.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; use C4::Letters qw( GetPreparedLetter EnqueueLetter ); @@ -119,4 +119,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.44.0