You are here

public function FileLogTest::providerFileLog in File Log 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Unit/FileLogTest.php \Drupal\Tests\filelog\Unit\FileLogTest::providerFileLog()

Provide data for the level-checking test.

Return value

array All datasets for ::testFileLog().

File

tests/src/Unit/FileLogTest.php, line 152

Class

FileLogTest
Test the file logger.

Namespace

Drupal\Tests\filelog\Unit

Code

public function providerFileLog() : array {
  $config = [
    'enabled' => TRUE,
    'location' => 'vfs://filelog',
    'level' => 7,
    'channels_type' => 'exclude',
    'channels' => [],
    'format' => '[log:level] [log:message]',
  ];
  $levels = LogMessage::getLevels();
  $events = [];
  $messages = [];
  for ($i = 0; $i <= 7; $i++) {
    $events[] = [
      'level' => $i,
      'message' => "This is message @i.\n LD5}5>~\\8AiU * VH",
      'context' => [
        '@i' => $i,
        'timestamp' => 0,
        'channel' => "channel_{$i}",
      ],
    ];
    $messages[] = $levels[$i] . " This is message {$i}.\\n LD5}5>~\\8AiU * VH";
  }
  $data = [];
  for ($i = 0, $iMax = count($levels); $i <= $iMax; $i++) {
    $expected = implode("\n", array_slice($messages, 0, $i + 1)) . "\n";
    $data[$i] = [
      'config' => [
        'level' => $i,
      ] + $config,
      'events' => $events,
      'expected' => $expected,
    ];
  }
  $data[] = [
    'config' => [
      'enabled' => FALSE,
    ] + $config,
    'events' => $events,
    'expected' => '',
  ];
  $data[] = [
    'config' => [
      'channels_type' => 'include',
    ] + $config,
    'events' => $events,
    'expected' => '',
  ];
  $data[] = [
    'config' => [
      'channels_type' => 'include',
      'channels' => [
        'channel_3',
      ],
    ] + $config,
    'events' => $events,
    'expected' => $messages[3] . "\n",
  ];
  $data[] = [
    'config' => [
      'channels' => [
        'channel_3',
      ],
    ] + $config,
    'events' => $events,
    'expected' => implode("\n", array_slice($messages, 0, 3) + array_slice($messages, 4, 4, TRUE)) . "\n",
  ];
  return $data;
}