You are here

public function SmtpUnitTest::testLogging in SMTP Authentication Support 7.2

Same name and namespace in other branches
  1. 7 tests/smtp.unit.test \SmtpUnitTest::testLogging()

Tests logging mail with maillog module.

File

tests/smtp.unit.test, line 71
Some tests for the SMTP module.

Class

SmtpUnitTest
@file Some tests for the SMTP module.

Code

public function testLogging() {
  $language = language_default();

  // This is automatically assigned by Simpletest.
  $sender = 'simpletest@example.com';

  // Send an email.
  $to_email = 'to_test@example.com';
  $reply_email = 'reply_test@example.com';
  $params = array();
  drupal_mail('smtp_tests', 'smtp_basic_test', $to_email, $language, $params);

  // The SMTP module controls the 'from' address but defaults to using the
  // site's system email address.
  $from_email = variable_get('site_mail', '');

  // Compare the maillog db entry with the sent mail.
  $logged_email = $this
    ->getLatestMaillogEntry();
  $this
    ->assertTrue(!empty($logged_email), 'The test email was captured.');
  $this
    ->assertEqual($to_email, $logged_email['header_to']);

  //, 'Email "to" address is correct.');
  $this
    ->assertEqual($from_email, $logged_email['header_from']);

  //, 'Email "from" address is correct.');
  $this
    ->assertEqual($from_email, $logged_email['header_all']['From']);

  //, 'Email "from" header is correct.');
  $this
    ->assertEqual($sender, $logged_email['header_all']['Sender']);

  //, 'Email "sender" header is correct.');
  $this
    ->assertEqual($sender, $logged_email['header_all']['Return-Path']);

  //, 'Email "return-path" header is correct.');
  $this
    ->assertEqual('Drupal', $logged_email['header_all']['X-Mailer']);

  //, 'Email "x-mailer" header is correct.');
  $this
    ->assertEqual(t('Test email subject'), $logged_email['subject']);

  //, 'Email subject is correct.');
  $this
    ->assertEqual(t('Test email body.') . "\n", $logged_email['body']);

  //, 'Email body is correct.');
}