function AssertMailTrait::assertMail

Same name in other branches
  1. 9 core/lib/Drupal/Core/Test/AssertMailTrait.php \Drupal\Core\Test\AssertMailTrait::assertMail()
  2. 8.9.x core/lib/Drupal/Core/Test/AssertMailTrait.php \Drupal\Core\Test\AssertMailTrait::assertMail()
  3. 11.x core/lib/Drupal/Core/Test/AssertMailTrait.php \Drupal\Core\Test\AssertMailTrait::assertMail()

Asserts that the most recently sent email message has the given value.

The field in $name must have the content described in $value.

Parameters

string $name: Name of field or message property to assert. Examples: subject, body, id, ...

string $value: Value of the field to assert.

string $message: (optional) A message to display with the assertion. Do not translate messages with t(). Use double quotes and embed variables directly in message text, or use sprintf() if necessary. Avoid the use of \Drupal\Component\Render\FormattableMarkup unless you cast the object to a string. If left blank, a default message will be displayed.

Return value

bool TRUE on pass.

4 calls to AssertMailTrait::assertMail()
AssertMailTraitTest::testAssertMailTrait in core/tests/Drupal/KernelTests/Core/Test/AssertMailTraitTest.php
Tests that the maintenance theme initializes the theme and its base themes.
MailCaptureTest::testMailSend in core/tests/Drupal/FunctionalTests/MailCaptureTest.php
Tests to see if the wrapper function is executed correctly.
UserAdminTest::testUserAdmin in core/modules/user/tests/src/Functional/UserAdminTest.php
Registers a user and deletes it.
UserPasswordResetTest::assertValidPasswordReset in core/modules/user/tests/src/Functional/UserPasswordResetTest.php
Helper function to make assertions about a valid password reset.

File

core/lib/Drupal/Core/Test/AssertMailTrait.php, line 58

Class

AssertMailTrait
Provides methods for testing emails sent during test runs.

Namespace

Drupal\Core\Test

Code

protected function assertMail($name, $value = '', $message = '') {
    $captured_emails = $this->container
        ->get('state')
        ->get('system.test_mail_collector') ?: [];
    $email = end($captured_emails);
    $this->assertIsArray($email, $message);
    $this->assertArrayHasKey($name, $email, $message);
    $this->assertEquals($value, $email[$name], $message);
    return TRUE;
}

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