From bd12b6050f0b1c83d7af4df71959d4c0950069e4 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 23 Mar 2021 10:56:59 -0300 Subject: [PATCH] Bug 26705: Regression tests Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart (cherry picked from commit 58a5a040661c150d455c5942bc56cecbb1a0e2d1) Signed-off-by: Fridolin Somers --- t/Koha/Email.t | 63 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/t/Koha/Email.t b/t/Koha/Email.t index 1c46fcc284..752269341f 100755 --- a/t/Koha/Email.t +++ b/t/Koha/Email.t @@ -17,7 +17,9 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; + +use Test::MockModule; use Test::Exception; use t::lib::Mocks; @@ -175,3 +177,62 @@ subtest 'create() tests' => sub { is( "$@", q{Invalid 'bcc' parameter: not_an_email}, 'Exception message correct' ); }; }; + +subtest 'send_or_die() tests' => sub { + + plan tests => 4; + + my $email; + my $args; + + my $transport = "Hi there!"; + + my $mocked_email_simple = Test::MockModule->new('Email::Sender::Simple'); + $mocked_email_simple->mock( + 'send', + sub { + my @params = @_; + $email = $params[1]; + $args = $params[2]; + return; + } + ); + + my $html_body = '

Title

Message

'; + my $THE_email = Koha::Email->create( + { + from => 'from@example.com', + to => 'to@example.com', + cc => 'cc@example.com', + reply_to => 'reply_to@example.com', + sender => 'sender@example.com', + html_body => $html_body + } + ); + + my @bcc = ( 'bcc_1@example.com', 'bcc_2@example.com' ); + + $THE_email->bcc(@bcc); + + is( + $THE_email->email->header_str('Bcc'), + join( ', ', @bcc ), + 'Bcc header set correctly' + ); + + $THE_email->send_or_die( + { transport => $transport, to => ['tomasito@mail.com'] } ); + is_deeply( $args->{to}, ['tomasito@mail.com'], + 'If explicitly passed, "to" is preserved' ); + + $THE_email->send_or_die( { transport => $transport } ); + is_deeply( + $args->{to}, + [ + 'to@example.com', 'cc@example.com', + 'bcc_1@example.com', 'bcc_2@example.com' + ], + 'If explicitly passed, "to" is preserved' + ); + is( $email->header_str('Bcc'), undef, 'The Bcc header is unset' ); +}; -- 2.39.5