function OriginatorSubscriberTest::testLocalizedDefaultFrom
Ensure that the from address is set with the correct locale.
File
-
core/
modules/ mailer/ tests/ src/ Kernel/ OriginatorSubscriberTest.php, line 79
Class
- OriginatorSubscriberTest
- Tests default originator subscriber.
Namespace
Drupal\Tests\mailer\KernelCode
public function testLocalizedDefaultFrom() : void {
ConfigurableLanguage::createFromLangcode('fr')->save();
// Update fr system.site config with custom translation.
$languageManager = $this->container
->get(LanguageManagerInterface::class);
assert($languageManager instanceof ConfigurableLanguageManagerInterface);
// Use a name that could trigger HTML entity replacements.
// cspell:ignore L'Equipe de l'Agriculture
$languageManager->getLanguageConfigOverride('fr', 'system.site')
->set('mail', 'site-mail-fr@example.com')
->set('name', "L'Equipe de l'Agriculture")
->save();
$expectedAddress = new Address('site-mail-fr@example.com', "L'Equipe de l'Agriculture");
$email = (new Email())->subject('Way house answer start behind old')
->text('We name know environmental along agree let. Traditional interest this clearly concern discover. Foot carry member your.');
$email->getHeaders()
->add(new UnstructuredHeader('Content-Language', 'fr'));
$transport = $this->container
->get(TransportInterface::class);
assert($transport instanceof TransportInterface);
$sentMessage = $transport->send($email->to('foobar@example.com'));
assert($sentMessage instanceof SentMessage);
$originalEmail = $sentMessage->getOriginalMessage();
assert($originalEmail instanceof Email);
$actualFrom = $originalEmail->getFrom();
$this->assertEquals([
$expectedAddress,
], $actualFrom);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.