function MailManagerTest::testMailInRenderContext

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Mail/MailManagerTest.php \Drupal\Tests\Core\Mail\MailManagerTest::testMailInRenderContext()
  2. 8.9.x core/tests/Drupal/Tests/Core/Mail/MailManagerTest.php \Drupal\Tests\Core\Mail\MailManagerTest::testMailInRenderContext()
  3. 11.x core/tests/Drupal/Tests/Core/Mail/MailManagerTest.php \Drupal\Tests\Core\Mail\MailManagerTest::testMailInRenderContext()

Tests that mails are sent in a separate render context.

@covers ::mail

File

core/tests/Drupal/Tests/Core/Mail/MailManagerTest.php, line 180

Class

MailManagerTest
@coversDefaultClass \Drupal\Core\Mail\MailManager[[api-linebreak]] @group Mail

Namespace

Drupal\Tests\Core\Mail

Code

public function testMailInRenderContext() : void {
  $interface = [
    'default' => 'php_mail',
    'example_test_key' => 'test_mail_collector',
  ];
  $this->setUpMailManager($interface);
  $this->renderer
    ->expects($this->exactly(1))
    ->method('executeInRenderContext')
    ->willReturnCallback(function (RenderContext $render_context, $callback) {
    $message = $callback();
    $this->assertEquals('example', $message['module']);
  });
  $this->mailManager
    ->mail('example', 'key', 'to@example.org', 'en');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.