From fc4d7c3d4deeec4f9bfae2dd31e83be7527e2887 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 28 Mar 2023 12:35:05 +0100 Subject: [PATCH] Bug 18398: (follow-up) Update POD & Unit tests Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 488e67656ffa3016a32f39eb68c5a3aa7fb8a68e) Signed-off-by: Jacob O'Mara --- C4/Message.pm | 8 ++++---- t/db_dependent/Message.t | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/C4/Message.pm b/C4/Message.pm index 8bf1a05b0a..68205083d5 100644 --- a/C4/Message.pm +++ b/C4/Message.pm @@ -37,8 +37,8 @@ How to add a new message to the queue: use C4::Message; use C4::Items; - my $borrower = { borrowernumber => 1 }; - my $item = Koha::Items->find($itemnumber)->unblessed; + my $patron = Koha::Patron->find({ borrowernumber => 1 }); + my $item = Koha::Items->find($itemnumber)->unblessed; my $letter = C4::Letters::GetPreparedLetter ( module => 'circulation', letter_code => 'CHECKOUT', @@ -48,7 +48,7 @@ How to add a new message to the queue: 'biblioitems', $item->{biblionumber}, }, ); - C4::Message->enqueue($letter, $borrower->{borrowernumber}, 'email'); + C4::Message->enqueue($letter, $patron, 'email'); How to update a borrower's last checkout message: @@ -148,7 +148,7 @@ sub find_last_message { } -=head3 C4::Message->enqueue($letter, $borrower, $transport) +=head3 C4::Message->enqueue($letter, $patron, $transport) This is a front-end for C that adds metadata to the message. diff --git a/t/db_dependent/Message.t b/t/db_dependent/Message.t index ab65e0ba1b..b223c56505 100755 --- a/t/db_dependent/Message.t +++ b/t/db_dependent/Message.t @@ -16,11 +16,12 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 5; use utf8; use t::lib::TestBuilder; +use t::lib::Mocks; use C4::Letters qw( GetPreparedLetter ); use Koha::Database; @@ -37,7 +38,7 @@ $dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('test ")}); my $biblio_1 = $builder->build_sample_biblio({ title => "heÄllo" }); my $biblio_2 = $builder->build_sample_biblio({ title => "hell❤️" }); -my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { email => 'test@example.org'} }); +my $patron = $builder->build_object({ class => 'Koha::Patrons' }); my $letter = C4::Letters::GetPreparedLetter( ( module => 'test', @@ -48,9 +49,12 @@ my $letter = C4::Letters::GetPreparedLetter( ) ); -C4::Message->enqueue($letter, $patron->unblessed, 'email'); + +t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' ); +C4::Message->enqueue($letter, $patron, 'email'); my $message = C4::Message->find_last_message($patron->unblessed, 'TEST_MESSAGE', 'email'); like( $message->{metadata}, qr{heÄllo} ); +is ($message->{to_address}, $patron->email, "To address set correctly for AutoEmailPrimaryAddress 'off'"); $letter = C4::Letters::GetPreparedLetter( ( @@ -64,3 +68,8 @@ $letter = C4::Letters::GetPreparedLetter( $message->append($letter); like( $message->{metadata}, qr{heÄllo} ); like( $message->{metadata}, qr{hell❤️} ); + +t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'emailpro' ); +C4::Message->enqueue($letter, $patron, 'email'); +$message = C4::Message->find_last_message($patron->unblessed, 'TEST_MESSAGE', 'email'); +is ($patron->notice_email_address, $patron->emailpro, "To address set correctly for AutoEmailPrimaryAddress 'emailpro'"); -- 2.39.5