You are here

function DrupalTestCase::assertErrorPattern in SimpleTest 6

Same name and namespace in other branches
  1. 5 drupal_test_case.php \DrupalTestCase::assertErrorPattern()

Confirms that an error has occurred and that the error text matches a Perl regular expression.

Parameters

string $pattern Perl regular expression to: match against. @param string $message Message to display. @return boolean True on pass @access public

File

./drupal_test_case.php, line 802

Class

DrupalTestCase
Test case for typical Drupal tests. Extends WebTestCase for comfortable browser usage but also implements all UnitTestCase methods, I wish WebTestCase would do this.

Code

function assertErrorPattern($pattern, $message = "%s") {
  $queue =& SimpleErrorQueue::instance();
  if ($queue
    ->isEmpty()) {
    $this
      ->fail(sprintf($message, "Expected error not found"));
    return;
  }
  list($severity, $content, $file, $line, $globals) = $queue
    ->extract();
  $severity = SimpleErrorQueue::getSeverityAsString($severity);
  return $this
    ->assertTrue((bool) preg_match($pattern, $content), "Expected pattern match [{$pattern}] in PHP error [{$content}] severity [{$severity}] in [{$file}] line [{$line}]");
}