protected function DrupalWebTestCase::assertMailString in SimpleTest 7.2
Same name and namespace in other branches
- 6.2 drupal_web_test_case.php \DrupalWebTestCase::assertMailString()
Asserts that the most recently sent e-mail 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
- ./
drupal_web_test_case.php, line 3370 - Provides DrupalTestCase, DrupalUnitTestCase, and DrupalWebTestCase classes.
Class
- DrupalWebTestCase
- Test case for typical Drupal tests.
Code
protected function assertMailString($field_name, $string, $email_depth) {
$mails = $this
->drupalGetMails();
$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,
)));
}