function OriginatorSubscriberTest::testCustomEnvelopeSubscriberWithCustomMessageSender
Ensure that the envelope sender can be customized using an event subscriber.
File
-
core/
modules/ mailer/ tests/ src/ Kernel/ OriginatorSubscriberTest.php, line 372
Class
- OriginatorSubscriberTest
- Tests default originator subscriber.
Namespace
Drupal\Tests\mailer\KernelCode
public function testCustomEnvelopeSubscriberWithCustomMessageSender() : void {
$expectedAddress = Address::create('subscriber-envelope-sender@example.com');
$state = $this->container
->get('state');
assert($state instanceof StateInterface);
$state->set('mailer_event_subscriber_test.set_custom_envelope_sender', $expectedAddress);
$email = (new Email())->from('custom-from@example.com')
->sender('custom-message-sender@example.com')
->subject('Record rock college')
->text('Magazine service red minute. Top here box election yard as per. Blue around doctor beat tough might.');
$transport = $this->container
->get(TransportInterface::class);
assert($transport instanceof TransportInterface);
$sentMessage = $transport->send($email->to('foobar@example.com'));
assert($sentMessage instanceof SentMessage);
$envelope = $sentMessage->getEnvelope();
$actualAddress = $envelope->getSender();
$this->assertEquals($expectedAddress, $actualAddress);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.