function MailTestCase::testFromHeader in Drupal 7
Checks for the site name in an auto-generated From: header.
File
- modules/
simpletest/ tests/ mail.test, line 65 - Test the Drupal mailing system.
Class
- MailTestCase
- @file Test the Drupal mailing system.
Code
function testFromHeader() {
global $language;
$default_from = variable_get('site_mail', ini_get('sendmail_from'));
$site_name = variable_get('site_name', 'Drupal');
// 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';
$message = 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']);
// Check default behavior is only email in FROM header.
self::$sent_message = NULL;
// Send an e-mail and check that the From-header contains only default mail address.
variable_del('mail_display_name_site_name');
$message = drupal_mail('simpletest', 'from_test', 'from_test@example.com', $language);
$this
->assertEqual($default_from, self::$sent_message['headers']['From']);
self::$sent_message = NULL;
// Send an e-mail and check that the From-header contains the site name.
variable_set('mail_display_name_site_name', TRUE);
$message = drupal_mail('simpletest', 'from_test', 'from_test@example.com', $language);
$this
->assertEqual($site_name . ' <' . $default_from . '>', self::$sent_message['headers']['From']);
}