function AssertMailTrait::assertMail

Same name in other branches
  1. 9 core/lib/Drupal/Core/Test/AssertMailTrait.php \Drupal\Core\Test\AssertMailTrait::assertMail()
  2. 10 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: use \Drupal\Component\Render\FormattableMarkup to embed variables in the message text, not t(). If left blank, a default message will be displayed.

string $group: (optional) The group this message is in, which is displayed in a column in test output. Use 'Debug' to indicate this is debugging output. Do not translate this string. Defaults to 'Email'; most tests do not override this default.

Return value

bool TRUE on pass, FALSE on fail.

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
Test 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 62

Class

AssertMailTrait
Provides methods for testing emails sent during test runs.

Namespace

Drupal\Core\Test

Code

protected function assertMail($name, $value = '', $message = '', $group = 'Email') {
    $captured_emails = $this->container
        ->get('state')
        ->get('system.test_mail_collector') ?: [];
    $email = end($captured_emails);
    return $this->assertTrue($email && isset($email[$name]) && $email[$name] == $value, $message, $group);
}

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