You are here

public function MailManagerTest::testMailInRenderContext in Drupal 8

Same name and namespace in other branches
  1. 9 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 152
Contains \Drupal\Tests\Core\Mail\MailManagerTest.

Class

MailManagerTest
@coversDefaultClass \Drupal\Core\Mail\MailManager @group Mail

Namespace

Drupal\Tests\Core\Mail

Code

public function testMailInRenderContext() {
  $interface = [
    'default' => 'php_mail',
    'example_testkey' => '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');
}