You are here

public function MaillogTestCase::testLogging in Maillog / Mail Developer 7

Tests logging mail with maillog module.

File

tests/MaillogTestCase.test, line 66
Unit-ish tests for the Maillog module.

Class

MaillogTestCase
All unit tests for the module.

Code

public function testLogging() {

  // Login as an admin.
  $this
    ->loginAdminUser();

  // Load the admin page.
  $this
    ->drupalGet('admin/reports/maillog');
  $this
    ->assertResponse(200);

  // Confirm there are no emails present.
  $this
    ->assertText('Maillog is currently empty. Send an email!');

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

  // Some other items to test.
  $from_email = 'from_test@example.com';
  $to_email = 'to_test@example.com';
  $test_subject = 'Test email subject';
  $test_body = "Test email body.\n";

  // Send an email.
  $this
    ->sendTestEmail();

  // 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($test_subject, $logged_email['subject'], 'Email subject is correct.');
  $this
    ->assertEqual($test_body, $logged_email['body'], 'Email body is correct.');

  // Load the admin page again.
  $this
    ->drupalGet('admin/reports/maillog');
  $this
    ->assertResponse(200);

  // Confirm the message is present.
  $this
    ->assertText($test_subject);
  $this
    ->assertText($from_email);
  $this
    ->assertText($to_email);

  // Confirm the operations links are present.
  $this
    ->assertLink('view', 0, '"view" link found.');
  $this
    ->assertLink('delete', 0, '"delete" link found.');
}