function MailTest::testFromHeader

Checks for the site name in an auto-generated From: header.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Mail/MailTest.php, line 83
Definition of Drupal\system\Tests\Mail\MailTest.

Class

MailTest
Defines a mail class used for testing.

Namespace

Drupal\system\Tests\Mail

Code

function testFromHeader() {
  global $language;

  // Reset the class variable holding a copy of the last sent message.
  self::$sent_message = NULL;

  // Send an e-mail with a sender address specified.
  $from_email = 'someone_else@example.com';
  drupal_mail('simpletest', 'from_test', 'from_test@example.com', $language, array(), $from_email);

  // Test that the from e-mail is just the e-mail and not the site name and
  // default sender e-mail.
  $this
    ->assertEqual($from_email, self::$sent_message['headers']['From']);
  self::$sent_message = NULL;

  // Send an e-mail and check that the From-header contains the site name.
  drupal_mail('simpletest', 'from_test', 'from_test@example.com', $language);
  $this
    ->assertEqual('Drupal <simpletest@example.com>', self::$sent_message['headers']['From']);
}