Bug 20474: Mock sendmail instead of actually emailing
authorMark Tompsett <mtompset@hotmail.com>
Mon, 26 Mar 2018 15:39:28 +0000 (15:39 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 27 Mar 2018 15:19:31 +0000 (12:19 -0300)
Copy mocking sendmail code from t/db_dependent/Letters.t
into the Passwordrecovery.t test file.

prove t/db_dependent/Passwordrecovery.t

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/Passwordrecovery.t

index 47de46f..75760f4 100755 (executable)
 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;