You are here

protected function XMLSitemapTestHelper::getWatchdogMessages in XML sitemap 7.2

Same name and namespace in other branches
  1. 6.2 xmlsitemap.test \XMLSitemapTestHelper::getWatchdogMessages()

Fetch all seen watchdog messages.

@todo Add unit tests for this function.

3 calls to XMLSitemapTestHelper::getWatchdogMessages()
XMLSitemapTestHelper::assertNoWatchdogErrors in ./xmlsitemap.test
Check that there were no watchdog errors or worse.
XMLSitemapTestHelper::assertNoWatchdogMessage in ./xmlsitemap.test
Assert No Watchdog Message.
XMLSitemapTestHelper::assertWatchdogMessage in ./xmlsitemap.test
Assert Watchdog Message.

File

./xmlsitemap.test, line 307
Unit tests for the xmlsitemap.

Class

XMLSitemapTestHelper
Helper test class with some added functions for testing.

Code

protected function getWatchdogMessages(array $conditions = array(), $reset = FALSE) {
  static $seen_ids = array();
  if (!module_exists('dblog') || $reset) {
    $seen_ids = array();
    return array();
  }
  $query = db_select('watchdog');
  $query
    ->fields('watchdog', array(
    'wid',
    'type',
    'severity',
    'message',
    'variables',
    'timestamp',
  ));
  foreach ($conditions as $field => $value) {
    if ($field == 'variables' && !is_string($value)) {
      $value = serialize($value);
    }
    $query
      ->condition($field, $value);
  }
  if ($seen_ids) {
    $query
      ->condition('wid', $seen_ids, 'NOT IN');
  }
  $query
    ->orderBy('timestamp');
  $messages = $query
    ->execute()
    ->fetchAllAssoc('wid');
  $seen_ids = array_merge($seen_ids, array_keys($messages));
  return $messages;
}