You are here

private function FakeLogEntries::generateLogEntries in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/dblog/tests/src/Functional/FakeLogEntries.php \Drupal\Tests\dblog\Functional\FakeLogEntries::generateLogEntries()
  2. 10 core/modules/dblog/tests/src/Functional/FakeLogEntries.php \Drupal\Tests\dblog\Functional\FakeLogEntries::generateLogEntries()

Generates a number of random database log events.

Parameters

int $count: Number of watchdog entries to generate.

array $options: These options are used to override the defaults for the test. An associative array containing any of the following keys:

  • 'channel': String identifying the log channel to be output to. If the channel is not set, the default of 'custom' will be used.
  • 'message': String containing a message to be output to the log. A simple default message is used if not provided.
  • 'variables': Array of variables that match the message string.
  • 'severity': Log severity level as defined in logging_severity_levels.
  • 'link': String linking to view the result of the event.
  • 'uid': Int identifying the user id for the user.
  • 'request_uri': String identifying the location of the request.
  • 'referer': String identifying the referring url.
  • 'ip': String The ip address of the client machine triggering the log entry.
  • 'timestamp': Int unix timestamp.
7 calls to FakeLogEntries::generateLogEntries()
DbLogTest::testDbLogCron in core/modules/dblog/tests/src/Kernel/DbLogTest.php
Tests that cron correctly applies the database log row limit.
DbLogTest::testFilter in core/modules/dblog/tests/src/Functional/DbLogTest.php
Tests the database log filter functionality at admin/reports/dblog.
DbLogTest::testLogEventPageWithMissingInfo in core/modules/dblog/tests/src/Functional/DbLogTest.php
Test individual log event page with missing log attributes.
DbLogTest::testOverviewLinks in core/modules/dblog/tests/src/Functional/DbLogTest.php
Make sure HTML tags are filtered out in the log overview links.
DbLogTest::testSameTimestampEntries in core/modules/dblog/tests/src/Functional/DbLogTest.php
Test sorting for entries with the same timestamp.

... See full list

File

core/modules/dblog/tests/src/Functional/FakeLogEntries.php, line 37

Class

FakeLogEntries
Provides methods to generate log entries.

Namespace

Drupal\Tests\dblog\Functional

Code

private function generateLogEntries($count, $options = []) {
  global $base_root;
  $user = !empty($this->adminUser) ? $this->adminUser : new AnonymousUserSession();

  // Prepare the fields to be logged.
  $log = $options + [
    'channel' => 'custom',
    'message' => 'Dblog test log message',
    'variables' => [],
    'severity' => RfcLogLevel::NOTICE,
    'link' => NULL,
    'uid' => $user
      ->id(),
    'request_uri' => $base_root . \Drupal::request()
      ->getRequestUri(),
    'referer' => \Drupal::request()->server
      ->get('HTTP_REFERER'),
    'ip' => '127.0.0.1',
    'timestamp' => REQUEST_TIME,
  ];
  $logger = $this->container
    ->get('logger.dblog');
  $message = $log['message'] . ' Entry #';
  for ($i = 0; $i < $count; $i++) {
    $log['message'] = $message . $i;
    $logger
      ->log($log['severity'], $log['message'], $log);
  }
}