From 1a2bab6a2c2fe25fd826b5075ec87bb9a2ef6b10 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Mon, 26 Mar 2018 15:39:28 +0000 Subject: [PATCH] Bug 20474: Mock sendmail instead of actually emailing Copy mocking sendmail code from t/db_dependent/Letters.t into the Passwordrecovery.t test file. prove t/db_dependent/Passwordrecovery.t --- t/db_dependent/Passwordrecovery.t | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Passwordrecovery.t b/t/db_dependent/Passwordrecovery.t index 47de46f..75760f4 100755 --- a/t/db_dependent/Passwordrecovery.t +++ b/t/db_dependent/Passwordrecovery.t @@ -18,12 +18,26 @@ use Modern::Perl; use C4::Context; +use Mail::Sendmail; use C4::Letters; use Koha::Database; use Koha::Patrons; use t::lib::TestBuilder; -use Test::More tests => 20; +use Test::More tests => 22; +use Test::MockModule; +use Test::Warn; +use Carp; + +my %mail; +my $module = Test::MockModule->new('Mail::Sendmail'); +$module->mock( + 'sendmail', + sub { + carp 'Fake sendmail!'; + %mail = @_; + } +); use_ok('Koha::Patron::Password::Recovery'); @@ -180,14 +194,23 @@ ok( Koha::Patron::Password::Recovery::DeleteExpiredPasswordRecovery($borrowernum ############################################################### my $borrower = Koha::Patrons->search( { userid => $userid1 } )->next; -ok( Koha::Patron::Password::Recovery::SendPasswordRecoveryEmail($borrower, $email1, 0) == 1, "[SendPasswordRecoveryEmail] Returns 1 on success" ); +my $success; +warning_like { + $success = Koha::Patron::Password::Recovery::SendPasswordRecoveryEmail($borrower, $email1, 0); } + qr/Fake sendmail!/, + '[SendPasswordRecoveryEmail] expecting fake sendmail'; +ok( $success == 1, '[SendPasswordRecoveryEmail] Returns 1 on success'); + my $letters = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber1, limit => 99 } ); ok( scalar @$letters == 1, "[SendPasswordRecoveryEmail] There is a letter in the queue for our borrower"); my $bpr = $schema->resultset('BorrowerPasswordRecovery')->search( { borrowernumber => $borrowernumber1 } ); my $tempuuid1 = $bpr->next->uuid; -Koha::Patron::Password::Recovery::SendPasswordRecoveryEmail($borrower, $email1, 1); +warning_like { + Koha::Patron::Password::Recovery::SendPasswordRecoveryEmail($borrower, $email1, 1); } + qr/Fake sendmail!/, + '[SendPasswordRecoveryEmail] expecting fake sendmail'; $bpr = $schema->resultset('BorrowerPasswordRecovery')->search( { borrowernumber => $borrowernumber1 } ); my $tempuuid2 = $bpr->next->uuid; -- 2.1.4