function AssertMailTrait::assertMailPattern
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 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.
File
-
core/
lib/ Drupal/ Core/ Test/ AssertMailTrait.php, line 119
Class
- AssertMailTrait
- Provides methods for testing emails sent during test runs.
Namespace
Drupal\Core\TestCode
protected function assertMailPattern($field_name, $regex, $message = '') {
$mails = $this->getMails();
$mail = end($mails);
$regex_found = preg_match("/{$regex}/", $mail[$field_name]);
if (!$message) {
$message = new FormattableMarkup('Expected text found in @field of email message: "@expected".', [
'@field' => $field_name,
'@expected' => $regex,
]);
}
$this->assertTrue((bool) $regex_found, $message);
}