You are here

public function MailTest::testLogging in Maillog / Mail Developer 8

Tests logging mail with maillog module.

File

tests/src/Kernel/MailTest.php, line 49

Class

MailTest
Tests the maillog plugin.

Namespace

Drupal\Tests\maillog\Kernel

Code

public function testLogging() {
  $language = \Drupal::languageManager()
    ->getCurrentLanguage();

  // Send an email.
  $from_email = 'simpletest@example.com';
  $reply_email = 'someone_else@example.com';
  \Drupal::service('plugin.manager.mail')
    ->mail('simpletest', 'from_test', 'from_test@example.com', $language, [], $reply_email);

  // Compare the maillog db entry with the sent mail.
  $logged_email = $this
    ->getLatestMaillogEntry();
  $this
    ->assertTrue(is_array($logged_email), 'Email is captured.');
  $this
    ->assertEqual($from_email, $logged_email['header_from'], 'Email is sent correctly.');
  $this
    ->assertEqual($reply_email, $logged_email['header_all']['Reply-to'], 'Message is sent with correct reply address.');
}