function MailManagerTest::testMailInRenderContext

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Mail/MailManagerTest.php \Drupal\Tests\Core\Mail\MailManagerTest::testMailInRenderContext()
  2. 10 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 152

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');
}

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