Commit bf01b30d authored by Dave Reid's avatar Dave Reid
Browse files

by Dave Reid: Fixed remaining test failures and an error with...

by Dave Reid: Fixed remaining test failures and an error with getWatchdogMessages(). Now 100% test pass!
parent 6a1b566a
......@@ -30,7 +30,7 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
// Capture any (remaining) watchdog errors.
$this->assertNoWatchdogErrors();
// Reset the watchdog seen IDs for the next test run.
$this->getWatchdogMessages(TRUE);
$this->getWatchdogMessages(array(), TRUE);
parent::tearDown();
}
......@@ -209,53 +209,57 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
$this->assertNoText(t('One or more problems were detected with your XML sitemap configuration'));
}
private function getWatchdogMessage(array $conditions) {
$query = db_select('watchdog');
$query->fields('watchdog');
foreach ($conditions as $field => $value) {
if ($field == 'variables' && is_array($value)) {
$value = serialize($value);
}
$query->conditions($field, $value);
}
return $query->execute()->fetchAll();
}
protected function assertWatchdogMessage(array $conditions, $message = 'Watchdog message found.') {
$this->assertTrue($this->getWatchdogMessage($conditions), $message);
}
protected function assertNoWatchdogMessage(array $conditions, $message = 'Watchdog message not found.') {
$this->assertFalse($this->getWatchdogMessage($conditions), $message);
}
/**
* Fetch all seen watchdog messages.
*
* @todo Add unit tests for this function.
*/
protected function getWatchdogMessages($reset = FALSE) {
protected function getWatchdogMessages(array $conditions = array(), $reset = FALSE) {
static $seen_ids = array();
static $levels;
if (!module_exists('dblog') || $reset) {
$seen_ids = array();
return;
}
if (!isset($levels)) {
$levels = watchdog_severity_levels();
}
$query = db_select('watchdog');
$query->fields('watchdog', array('wid', 'type', 'severity', 'message', 'variables', 'timestamp'));
foreach ($conditions as $field => $value) {
if ($field == 'variables' && is_array($value)) {
$value = serialize($value);
}
$query->condition($field, $value);
}
if ($seen_ids) {
$query->condition('wid', $seen_ids);
$query->condition('wid', $seen_ids, 'NOT IN');
}
$query->orderBy('timestamp', 'ASC');
$messages = $query->execute()->fetchAllAssoc('wid');
foreach ($messages as &$message) {
$message->text = $message->timestamp . ' ' . t($message->message, unserialize($message->variables));
$message->variables = unserialize($message->variables);
if (!is_array($message->variables)) {
$message->variables = array();
}
$message->text = $message->timestamp . ' - ' . $levels[$message->severity] . ' - ' . t($message->message, $message->variables);
}
$seen_ids = array_merge($seen_ids, array_keys($messages));
return $messages;
}
protected function assertWatchdogMessage(array $conditions, $message = 'Watchdog message found.') {
$this->assertTrue($this->getWatchdogMessages($conditions), $message);
}
protected function assertNoWatchdogMessage(array $conditions, $message = 'Watchdog message not found.') {
$this->assertFalse($this->getWatchdogMessages($conditions), $message);
}
/**
* Check that there were no watchdog errors or worse.
*/
......@@ -264,12 +268,10 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
$verbose = array();
foreach ($messages as $message) {
if ($message->severity < WATCHDOG_NOTICE) {
if (in_array($message->severity, array(WATCHDOG_EMERG, WATCHDOG_ALERT, WATCHDOG_CRITICAL, WATCHDOG_ERROR, WATCHDOG_WARNING))) {
$this->fail($message->text);
}
else {
$verbose[] = $message->text;
}
$verbose[] = $message->text;
}
if ($verbose) {
......
......@@ -18,6 +18,7 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
parent::setUp('xmlsitemap_engines', 'xmlsitemap_engines_test');
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer xmlsitemap'));
$this->drupalLogin($this->admin_user);
variable_set('xmlsitemap_generated_last', REQUEST_TIME);
}
function testPing() {
......@@ -42,12 +43,11 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
xmlsitemap_engines_cron();
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Submitted the sitemap to %url and received response @code.'));
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'No sitemap parameter provided.'));
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'No valid sitemap parameter provided.'));
$this->assertWatchdogMessage(array('type' => 'page not found', 'message' => 'ping'));
$edit = array('xmlsitemap_engines_custom_urls' => url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => '[sitemap]'))));
$this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
}
}
......@@ -32,15 +32,12 @@ function xmlsitemap_engines_test_xmlsitemap_engine_info_alter(&$engines) {
}
function xmlsitemap_engines_test_pinged() {
if (empty($_GET['sitemap'])) {
return drupal_not_found();
watchdog('xmlsitemap', 'No sitemap parameter provided.', NULL, WATCHDOG_WARNING);
//drupal_set_message(t('No sitemap parameter provided.'), 'error');
echo t('No sitemap parameter provided.');
if (empty($_GET['sitemap']) || !valid_url($_GET['sitemap'])) {
watchdog('xmlsitemap', 'No valid sitemap parameter provided.', array(), WATCHDOG_WARNING);
// @todo Remove this? Causes an extra watchdog error to be handled.
return MENU_NOT_FOUND;
}
else {
watchdog('xmlsitemap', 'Recieved ping for @sitemap.', array('@sitemap' => $_GET['sitemap']));
//drupal_set_message(t('Recieved sitemap ping for @sitemap.', array('@sitemap' => $_GET['sitemap'])));
echo t('Recieved sitemap ping for @sitemap.', array('@sitemap' => $_GET['sitemap']));
}
}
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