Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Test/AssertMailTrait.php \Drupal\Core\Test\AssertMailTrait::assertMail()
  2. 9 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: use \Drupal\Component\Render\FormattableMarkup to embed variables in the message text, not t(). 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 57

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