You are here

protected function ViewsIntegrationTest::createLogEntries in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/dblog/tests/src/Kernel/Views/ViewsIntegrationTest.php \Drupal\Tests\dblog\Kernel\Views\ViewsIntegrationTest::createLogEntries()
  2. 9 core/modules/dblog/tests/src/Kernel/Views/ViewsIntegrationTest.php \Drupal\Tests\dblog\Kernel\Views\ViewsIntegrationTest::createLogEntries()

Create a set of log entries.

Return value

array An array of data used to create the log entries.

2 calls to ViewsIntegrationTest::createLogEntries()
ViewsIntegrationTest::testFiltering in core/modules/dblog/tests/src/Kernel/Views/ViewsIntegrationTest.php
Tests views can be filtered by severity and log type.
ViewsIntegrationTest::testMessages in core/modules/dblog/tests/src/Kernel/Views/ViewsIntegrationTest.php
Tests the messages escaping functionality.

File

core/modules/dblog/tests/src/Kernel/Views/ViewsIntegrationTest.php, line 178

Class

ViewsIntegrationTest
Tests the views integration of dblog module.

Namespace

Drupal\Tests\dblog\Kernel\Views

Code

protected function createLogEntries() {
  $entries = [];

  // Setup a watchdog entry without tokens.
  $entries[] = [
    'message' => $this
      ->randomMachineName(),
    'variables' => [
      'link' => Link::fromTextAndUrl('Link', Url::fromRoute('<front>'))
        ->toString(),
    ],
  ];

  // Setup a watchdog entry with one token.
  $entries[] = [
    'message' => '@token1',
    'variables' => [
      '@token1' => $this
        ->randomMachineName(),
      'link' => Link::fromTextAndUrl('Link', Url::fromRoute('<front>'))
        ->toString(),
    ],
  ];

  // Setup a watchdog entry with two tokens.
  $entries[] = [
    'message' => '@token1 @token2',
    // Setup a link with a tag which is filtered by
    // \Drupal\Component\Utility\Xss::filterAdmin() in order to make sure
    // that strings which are not marked as safe get filtered.
    'variables' => [
      '@token1' => $this
        ->randomMachineName(),
      '@token2' => $this
        ->randomMachineName(),
      'link' => '<a href="' . Url::fromRoute('<front>')
        ->toString() . '"><object>Link</object></a>',
    ],
  ];

  // Setup a watchdog entry with severity WARNING.
  $entries[] = [
    'message' => 'Warning message',
    'severity' => RfcLogLevel::WARNING,
  ];

  // Setup a watchdog entry with a different module.
  $entries[] = [
    'message' => 'My module message',
    'severity' => RfcLogLevel::INFO,
    'type' => 'my-module',
  ];
  $logger_factory = $this->container
    ->get('logger.factory');
  foreach ($entries as $entry) {
    $entry += [
      'type' => 'test-views',
      'severity' => RfcLogLevel::NOTICE,
      'variables' => [],
    ];
    $logger_factory
      ->get($entry['type'])
      ->log($entry['severity'], $entry['message'], $entry['variables']);
  }
  return $entries;
}