Commit f9b54585 authored by Dave Reid's avatar Dave Reid

by Dave Reid: Adding a copy of DrupalWebTestCase->verbose() to allow a...

by Dave Reid: Adding a copy of DrupalWebTestCase->verbose() to allow a customizable summary message.
parent 97e1b322
......@@ -260,18 +260,11 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
* Check that there were no watchdog errors or worse.
*/
protected function assertNoWatchdogErrors() {
module_load_include('admin.inc', 'dblog');
static $levels;
if (!isset($levels)) {
$levels = watchdog_severity_levels();
}
$messages = $this->getWatchdogMessages();
$verbose = array();
foreach ($messages as $message) {
$message->text = $message->timestamp . ' - ' . $levels[$message->severity] . ' - ' . $message->type . ' - ' . theme_dblog_message(array('event' => $message));
$message->text = $this->formatWatchdogMessage($message);
if (in_array($message->severity, array(WATCHDOG_EMERGENCY, WATCHDOG_ALERT, WATCHDOG_CRITICAL, WATCHDOG_ERROR, WATCHDOG_WARNING))) {
$this->fail($message->text);
}
......@@ -280,12 +273,58 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
if ($verbose) {
array_unshift($verbose, '<h2>Watchdog messages</h2>');
$this->verbose(implode("<br />", $verbose));
$this->verbose(implode("<br />", $verbose), 'Watchdog messages from test run');
}
// Clear the seen watchdog messages since we've failed on any errors.
$this->getWatchdogMessages(array(), TRUE);
}
/**
* Format a watchdog message in a one-line summary.
*
* @param $message
* A watchdog messsage object.
* @return
* A string containing the watchdog message's timestamp, severity, type,
* and actual message.
*/
private function formatWatchdogMessage(stdClass $message) {
static $levels;
if (!isset($levels)) {
module_load_include('admin.inc', 'dblog');
$levels = watchdog_severity_levels();
}
return t('@timestamp - @severity - @type - !message', array(
'@timestamp' => $message->timestamp,
'@severity' => $levels[$message->severity],
'@type' => $message->type,
'!message' => theme_dblog_message(array('event' => $message, 'link' => FALSE)),
));
}
/**
* Log verbose message in a text file.
*
* This is a copy of DrupalWebTestCase->verbose() but allows a customizable
* summary message rather than hard-coding 'Verbose message'.
*
* @param $verbose_message
* The verbose message to be stored.
* @param $message
* Message to display.
* @see simpletest_verbose()
*
* @todo Remove when http://drupal.org/node/800426 is fixed.
*/
protected function verbose($verbose_message, $message = 'Verbose message') {
if ($id = simpletest_verbose($verbose_message)) {
$url = file_create_url($this->originalFileDirectory . '/simpletest/verbose/' . get_class($this) . '-' . $id . '.html');
$this->error(l($message, $url, array('attributes' => array('target' => '_blank'))), 'User notice');
}
}
}
class XMLSitemapUnitTest extends XMLSitemapTestHelper {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment