public function WebformMailTest::testFromAndReplyToHeader in Webform 6.x
Same name and namespace in other branches
- 8.5 tests/src/Functional/WebformMailTest.php \Drupal\Tests\webform\Functional\WebformMailTest::testFromAndReplyToHeader()
Checks the From: and Reply-to: headers.
File
- tests/
src/ Functional/ WebformMailTest.php, line 22
Class
- WebformMailTest
- Performs tests on the pluggable mailing framework.
Namespace
Drupal\Tests\webform\FunctionalCode
public function testFromAndReplyToHeader() {
$language = \Drupal::languageManager()
->getCurrentLanguage();
// Use the state system collector mail backend.
$this
->config('system.mail')
->set('interface.default', 'test_mail_collector')
->save();
// Reset the state variable that holds sent messages.
\Drupal::state()
->set('system.test_mail_collector', []);
// Send an email with a reply-to address specified.
$from_email = 'simpletest@example.com';
$reply_email = 'webform@example.com';
// Send an email and check that the From-header contains the from_name.
\Drupal::service('plugin.manager.mail')
->mail('webform', '', 'from_test@example.com', $language, [
'subject' => '',
'body' => '',
'from_mail' => $from_email,
'from_name' => 'Drépal',
], $reply_email);
$captured_emails = \Drupal::state()
->get('system.test_mail_collector');
$sent_message = end($captured_emails);
$this
->assertEquals($sent_message['headers']['From'], '=?UTF-8?B?RHLDg8KpcGFs?= <simpletest@example.com>', 'From header is correctly encoded.');
}