function AssertMailTrait::assertMailPattern
Same name in other branches
- 9 core/lib/Drupal/Core/Test/AssertMailTrait.php \Drupal\Core\Test\AssertMailTrait::assertMailPattern()
- 10 core/lib/Drupal/Core/Test/AssertMailTrait.php \Drupal\Core\Test\AssertMailTrait::assertMailPattern()
- 11.x core/lib/Drupal/Core/Test/AssertMailTrait.php \Drupal\Core\Test\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: 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.
File
-
core/
lib/ Drupal/ Core/ Test/ AssertMailTrait.php, line 134
Class
- AssertMailTrait
- Provides methods for testing emails sent during test runs.
Namespace
Drupal\Core\TestCode
protected function assertMailPattern($field_name, $regex, $message = '', $group = 'Other') {
$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,
]);
}
return $this->assertTrue($regex_found, $message, $group);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.