function OriginatorSubscriberTest::testCustomFromSubscriber

Ensure that the from address can be customized.

File

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

Class

OriginatorSubscriberTest
Tests default originator subscriber.

Namespace

Drupal\Tests\mailer\Kernel

Code

public function testCustomFromSubscriber() : void {
  $expectedAddress = Address::create('subscriber-from@example.com');
  $state = $this->container
    ->get('state');
  assert($state instanceof StateInterface);
  $state->set('mailer_event_subscriber_test.set_custom_from', $expectedAddress);
  $email = (new Email())->subject('Serious inside else memory if six')
    ->text('Name have page personal assume actually study else. Court response must near however.');
  $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.