You are here

public function ViewsIntegrationTest::testFiltering 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::testFiltering()
  2. 9 core/modules/dblog/tests/src/Kernel/Views/ViewsIntegrationTest.php \Drupal\Tests\dblog\Kernel\Views\ViewsIntegrationTest::testFiltering()

Tests views can be filtered by severity and log type.

File

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

Class

ViewsIntegrationTest
Tests the views integration of dblog module.

Namespace

Drupal\Tests\dblog\Kernel\Views

Code

public function testFiltering() {

  // Remove the watchdog entries added by the potential batch process.
  $this->container
    ->get('database')
    ->truncate('watchdog')
    ->execute();
  $this
    ->createLogEntries();
  $view = Views::getView('dblog_integration_test');
  $filters = [
    'severity' => [
      'id' => 'severity',
      'table' => 'watchdog',
      'field' => 'severity',
      'relationship' => 'none',
      'group_type' => 'group',
      'admin_label' => '',
      'operator' => 'in',
      'value' => [
        RfcLogLevel::WARNING,
      ],
      'group' => 1,
      'exposed' => FALSE,
      'plugin_id' => 'in_operator',
    ],
  ];
  $view
    ->setDisplay('page_1');
  $view->displayHandlers
    ->get('page_1')
    ->overrideOption('filters', $filters);
  $view
    ->save();
  $this
    ->executeView($view);
  $resultset = [
    [
      'message' => 'Warning message',
    ],
  ];
  $this
    ->assertIdenticalResultset($view, $resultset, $this->columnMap);
  $view = Views::getView('dblog_integration_test');
  $filters = [
    'type' => [
      'id' => 'type',
      'table' => 'watchdog',
      'field' => 'type',
      'relationship' => 'none',
      'group_type' => 'group',
      'admin_label' => '',
      'operator' => 'in',
      'value' => [
        'my-module' => 'my-module',
      ],
      'group' => '1',
      'exposed' => FALSE,
      'is_grouped' => FALSE,
      'plugin_id' => 'dblog_types',
    ],
  ];
  $view
    ->setDisplay('page_1');
  $view->displayHandlers
    ->get('page_1')
    ->overrideOption('filters', $filters);
  $view
    ->save();
  $this
    ->executeView($view);
  $resultset = [
    [
      'message' => 'My module message',
    ],
  ];
  $this
    ->assertIdenticalResultset($view, $resultset, $this->columnMap);
}