function OriginatorSubscriberTest::testCustomEnvelopeWithCustomMessageSender

Ensure that the envelope sender can be customized using a custom envelope.

File

core/modules/mailer/tests/src/Kernel/OriginatorSubscriberTest.php, line 322

Class

OriginatorSubscriberTest
Tests default originator subscriber.

Namespace

Drupal\Tests\mailer\Kernel

Code

public function testCustomEnvelopeWithCustomMessageSender() : void {
  $expectedAddress = Address::create('custom-envelope-sender@example.com');
  $email = (new Email())->from('custom-from@example.com')
    ->sender('custom-message-sender@example.com')
    ->subject('First policy daughter need kind miss.')
    ->text('American whole magazine truth stop whose. On traditional measure example sense peace. Would mouth relate own chair.');
  $transport = $this->container
    ->get(TransportInterface::class);
  assert($transport instanceof TransportInterface);
  $customEnvelope = Envelope::create($email);
  $customEnvelope->setSender(Address::create($expectedAddress));
  $sentMessage = $transport->send($email->to('foobar@example.com'), $customEnvelope);
  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.