1 backdrop_web_test_case.php | protected BackdropWebTestCase::assertMailString($field_name, $string, $email_depth) |
Asserts that the most recently sent email message has the string in it.
Parameters
$field_name: Name of field or message property to assert: subject, body, id, ...
$string: String to search for.
$email_depth: Number of emails to search for string, starting with most recent.
Return value
TRUE on pass, FALSE on fail.:
File
- core/
modules/ simpletest/ backdrop_web_test_case.php, line 3950
Class
- BackdropWebTestCase
- Test case for typical Backdrop tests.
Code
protected function assertMailString($field_name, $string, $email_depth) {
$mails = $this->backdropGetMails();
$string_found = FALSE;
for ($i = sizeof($mails) -1; $i >= sizeof($mails) - $email_depth && $i >= 0; $i--) {
$mail = $mails[$i];
// Normalize whitespace, as we don't know what the mail system might have
// done. Any run of whitespace becomes a single space.
$normalized_mail = preg_replace('/\s+/', ' ', $mail[$field_name]);
$normalized_string = preg_replace('/\s+/', ' ', $string);
$string_found = (FALSE !== strpos($normalized_mail, $normalized_string));
if ($string_found) {
break;
}
}
return $this->assertTrue($string_found, t('Expected text found in @field of email message: "@expected".', array('@field' => $field_name, '@expected' => $string)));
}