From 7153424731c0799356b52984daec90d23384ff82 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 Signed-off-by: kelly Signed-off-by: David Nind Signed-off-by: Martin Renvoize --- Koha/Notice/Message.pm | 16 ++++++++++++++++ t/db_dependent/Letters.t | 8 +++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Koha/Notice/Message.pm b/Koha/Notice/Message.pm index 56798071063..aa166d9793e 100644 --- a/Koha/Notice/Message.pm +++ b/Koha/Notice/Message.pm @@ -124,6 +124,22 @@ sub restrict_patron_when_notice_fails { return $self; } +=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 fbe496d7ac6..2f107881e16 100755 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -19,7 +19,7 @@ use Modern::Perl; use File::Basename qw(dirname); -use Test::More tests => 103; +use Test::More tests => 104; use Test::MockModule; use Test::Warn; @@ -157,8 +157,10 @@ is( $messages->[0]->{updated_on}, $messages->[0]->{time_queued}, 'Time status ch is( $messages->[0]->{failure_code}, '', 'Failure code for successful message correctly empty'); # 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 $yesterday = dt_from_string->subtract( days => 1 ); +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" ); # EnqueueLetter - Test characters limitation for SMS -- 2.47.1