Asserts that the most recently sent e-mail message has the string in it.
$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.
$message: (optional) A message to display with the assertion. Do not translate messages: use format_string() to embed variables in the message text, not t(). If left blank, a default message will be displayed.
$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.
TRUE on pass, FALSE on fail.
protected function assertMailString($field_name, $string, $email_depth, $message = '', $group = 'Other') {
$mails = $this
->drupalGetMails();
$string_found = FALSE;
for ($i = count($mails) - 1; $i >= count($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;
}
}
if (!$message) {
$message = format_string('Expected text found in @field of email message: "@expected".', array(
'@field' => $field_name,
'@expected' => $string,
));
}
return $this
->assertTrue($string_found, $message, $group);
}