From f7953c2054820af6afdb7bfa42e816bc0381d122 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 7 May 2024 19:40:27 +0100 Subject: [PATCH] Bug 33260: (QA follow-up) Add template relation This patch add the 'template' relation to the Koha::Notice::Message object to fetch the Koha::Notice::Template object that may have been used to generate the notice. Signed-off-by: Martin Renvoize --- Koha/Notice/Message.pm | 19 +++++++++++++++++-- t/db_dependent/Koha/Notice/Message.t | 21 ++++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Koha/Notice/Message.pm b/Koha/Notice/Message.pm index b80ef534f66..ae6efeedf42 100644 --- a/Koha/Notice/Message.pm +++ b/Koha/Notice/Message.pm @@ -158,9 +158,9 @@ sub stylesheets { =head3 patron - my $patron = $checkout->patron + my $patron = $message->patron -Return the patron by whom the checkout was done +Return the patron by whom this message is for =cut @@ -171,6 +171,21 @@ sub patron { return Koha::Patron->_new_from_dbic($patron_rs); } +=head3 template + + my $template = $message->template + +Return the template from which this message may have been generated + +=cut + +sub template { + my ($self) = @_; + my $template_rs = $self->_result->letter; + return unless $template_rs; + return Koha::Notice::Template->_new_from_dbic($template_rs); +} + =head3 type =cut diff --git a/t/db_dependent/Koha/Notice/Message.t b/t/db_dependent/Koha/Notice/Message.t index ee4f80ef30d..938d7e58a6b 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 => 4; +use Test::More tests => 5; use C4::Letters qw( GetPreparedLetter EnqueueLetter ); @@ -239,6 +239,25 @@ subtest 'patron() tests' => sub { $schema->storage->txn_rollback; }; +subtest 'template() tests' => sub { + plan tests => 2; + + $schema->storage->txn_begin; + + my $template = $builder->build_object( { class => 'Koha::Notice::Templates' } ); + my $message = $builder->build_object( + { + class => 'Koha::Notice::Messages', + value => { letter_id => $template->id } + } + ); + + is( ref( $message->template ), 'Koha::Notice::Template', 'Object type is correct' ); + is( $message->template->id, $template->id, 'Right template linked' ); + + $schema->storage->txn_rollback; +}; + subtest 'search_limited' => sub { plan tests => 2; -- 2.47.1