From 88503d37c717463728e4cde87349cfad86b81b2b Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 21 Mar 2023 02:47:29 +0000 Subject: [PATCH] Bug 33260: Add a patron getter method to Koha::Notice::Message Signed-off-by: Laura Escamilla --- Koha/Notice/Message.pm | 16 ++++++++++++++++ t/db_dependent/Letters.t | 6 ++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Koha/Notice/Message.pm b/Koha/Notice/Message.pm index fcf7eca2a6..93dcd43ca4 100644 --- a/Koha/Notice/Message.pm +++ b/Koha/Notice/Message.pm @@ -32,6 +32,22 @@ Koha::Notice::Message - Koha notice message Object class, related to the message =cut +=head3 patron + + my $patron = $message->patron; + +Returns the Koha::Patron object for the recipient of the queued message + +=cut + +sub patron { + my ( $self ) = @_; + + $self->{_patron} ||= Koha::Patrons->find( $self->borrowernumber ); + + return $self->{_patron}; +} + =head3 type =cut diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index 33a518fc09..60f38b123d 100755 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -18,7 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 87; +use Test::More tests => 88; use Test::MockModule; use Test::Warn; use Test::Exception; @@ -150,7 +150,9 @@ is( $messages->[0]->{failure_code}, '', 'Failure code for successful message cor # Setting time_queued to something else than now my $yesterday = dt_from_string->subtract( days => 1 ); -Koha::Notice::Messages->find($messages->[0]->{message_id})->time_queued($yesterday)->store; +my $message_obj = Koha::Notice::Messages->find($messages->[0]->{message_id})->time_queued($yesterday)->store; +my $patron_obj = Koha::Patrons->find( $borrowernumber ); +is_deeply( $message_obj->patron, $patron_obj, "Koha::Notice::Message->patron sub correctly returns patron object"); # SendQueuedMessages my $messages_processed = C4::Letters::SendQueuedMessages( { type => 'email' }); -- 2.30.2