trait AssertMailTrait (View source)

Provides methods for testing emails sent during test runs.

Methods

array
getMails(array $filter = [])

Gets an array containing all emails sent during this test case.

bool
assertMail(string $name, string $value = '', string $message = '', string $group = 'Email')

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

bool
assertMailString(string $field_name, string $string, int $email_depth, string $message = '', string $group = 'Other')

Asserts that the most recently sent email message has the string in it.

bool
assertMailPattern(string $field_name, string $regex, string $message = '', string $group = 'Other')

Asserts that the most recently sent email message has the pattern in it.

verboseEmail(int $count = 1)

Outputs to verbose the most recent $count emails sent.

Details

protected array getMails(array $filter = [])

Gets an array containing all emails sent during this test case.

Parameters

array $filter

An array containing key/value pairs used to filter the emails that are returned.

Return Value

array

An array containing email messages captured during the current test.

protected bool assertMail(string $name, string $value = '', string $message = '', string $group = 'Email')

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.

protected bool assertMailString(string $field_name, string $string, int $email_depth, string $message = '', string $group = 'Other')

Asserts that the most recently sent email message has the string in it.

Parameters

string $field_name

Name of field or message property to assert: subject, body, id, ...

string $string

String to search for.

int $email_depth

Number of emails to search for string, starting with most recent.

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 'Other'; most tests do not override this default.

Return Value

bool

TRUE on pass, FALSE on fail.

protected bool assertMailPattern(string $field_name, string $regex, string $message = '', string $group = 'Other')

Asserts that the most recently sent email message has the pattern in it.

Parameters

string $field_name

Name of field or message property to assert: subject, body, id, ...

string $regex

Pattern to search for.

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 'Other'; most tests do not override this default.

Return Value

bool

TRUE on pass, FALSE on fail.

protected verboseEmail(int $count = 1)

Outputs to verbose the most recent $count emails sent.

Parameters

int $count

Optional number of emails to output.