Skip to content

Commit

Permalink
Add PHPMailer configuration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
titouanmathis committed Oct 20, 2023
1 parent 9eaf7c6 commit 5602f2e
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/Managers/EmailManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

use Studiometa\WPToolkit\Managers\EmailManager;

/**
* EmailManagerTest test case.
*/
class EmailManagerTest extends WP_UnitTestCase {

/**
* Test configure PHPMailer with SMTP server.
*
* @return void
*/
public function test_smtp_configuration() {
$_ENV['MAIL_MAILER'] = 'smtp';
$_ENV['MAIL_HOST'] = '127.0.0.1';
$_ENV['MAIL_PORT'] = '1025';
$_ENV['MAIL_USERNAME'] = 'test';
$_ENV['MAIL_PASSWORD'] = 'test';
$_ENV['MAIL_AUTH'] = 'true';
$_ENV['MAIL_ENCRYPTION'] = 'tls';

$manager = new EmailManager();
$manager->run();

// Trigger phpmailer configuration action.
global $phpmailer;
assert( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer );
do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );

// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$this->assertSame( $phpmailer->Mailer, 'smtp' );
$this->assertSame( $phpmailer->Host, '127.0.0.1' );
$this->assertSame( $phpmailer->Port, 1025 );
$this->assertSame( $phpmailer->Username, 'test' );
$this->assertSame( $phpmailer->Password, 'test' );
$this->assertSame( $phpmailer->SMTPAuth, true );
$this->assertSame( $phpmailer->SMTPSecure, 'tls' );
// phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
}
}

0 comments on commit 5602f2e

Please sign in to comment.