Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AssertMailTrait.php

function 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.

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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal