function OriginatorSubscriberTest::testDefaultEnvelopeSenderWithCustomFrom

Ensure that the envelope sender is set to the site mail with custom from.

File

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

Class

OriginatorSubscriberTest
Tests default originator subscriber.

Namespace

Drupal\Tests\mailer\Kernel

Code

public function testDefaultEnvelopeSenderWithCustomFrom() : void {
  $expectedAddress = Address::create('Example Site <site-mail@example.com>');
  $email = (new Email())->from('custom-from@example.com')
    ->subject('Media under opportunity similar.')
    ->text('Health catch term according me together ball never. Record rock college watch week institution collection anything.');
  $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.