You are here

protected function XmlSitemapTestBase::getWatchdogMessages in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/XmlSitemapTestBase.php \Drupal\Tests\xmlsitemap\Functional\XmlSitemapTestBase::getWatchdogMessages()

Fetch all seen watchdog messages.

@todo Add unit tests for this function.

3 calls to XmlSitemapTestBase::getWatchdogMessages()
XmlSitemapTestBase::assertNoWatchdogErrors in tests/src/Functional/XmlSitemapTestBase.php
Check that there were no watchdog errors or worse.
XmlSitemapTestBase::assertNoWatchdogMessage in tests/src/Functional/XmlSitemapTestBase.php
Assert No Watchdog Message.
XmlSitemapTestBase::assertWatchdogMessage in tests/src/Functional/XmlSitemapTestBase.php
Assert Watchdog Message.

File

tests/src/Functional/XmlSitemapTestBase.php, line 397

Class

XmlSitemapTestBase
Helper test class with some added functions for testing.

Namespace

Drupal\Tests\xmlsitemap\Functional

Code

protected function getWatchdogMessages(array $conditions = [], $reset = FALSE) {
  static $seen_ids = [];
  if (!$this->moduleHandler
    ->moduleExists('dblog') || $reset) {
    $seen_ids = [];
    return [];
  }
  $query = \Drupal::database()
    ->select('watchdog');
  $query
    ->fields('watchdog', [
    '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;
}