You are here

public function FilterBooleanOperatorStringTest::testFilterBooleanOperatorString in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Handler/FilterBooleanOperatorStringTest.php \Drupal\Tests\views\Kernel\Handler\FilterBooleanOperatorStringTest::testFilterBooleanOperatorString()
  2. 10 core/modules/views/tests/src/Kernel/Handler/FilterBooleanOperatorStringTest.php \Drupal\Tests\views\Kernel\Handler\FilterBooleanOperatorStringTest::testFilterBooleanOperatorString()

Tests the BooleanOperatorString filter.

File

core/modules/views/tests/src/Kernel/Handler/FilterBooleanOperatorStringTest.php, line 89

Class

FilterBooleanOperatorStringTest
Tests the core Drupal\views\Plugin\views\filter\BooleanOperatorString handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testFilterBooleanOperatorString() {
  $view = Views::getView('test_view');
  $view
    ->setDisplay();

  // Add a the status boolean filter.
  $view->displayHandlers
    ->get('default')
    ->overrideOption('filters', [
    'status' => [
      'id' => 'status',
      'field' => 'status',
      'table' => 'views_test_data',
      'value' => 0,
    ],
  ]);
  $this
    ->executeView($view);
  $expected_result = [
    [
      'id' => 2,
    ],
    [
      'id' => 4,
    ],
  ];
  $this
    ->assertCount(2, $view->result);
  $this
    ->assertIdenticalResultset($view, $expected_result, $this->columnMap);
  $view
    ->destroy();
  $view
    ->setDisplay();

  // Add the status boolean filter.
  $view->displayHandlers
    ->get('default')
    ->overrideOption('filters', [
    'status' => [
      'id' => 'status',
      'field' => 'status',
      'table' => 'views_test_data',
      'value' => 1,
    ],
  ]);
  $this
    ->executeView($view);
  $expected_result = [
    [
      'id' => 1,
    ],
    [
      'id' => 3,
    ],
    [
      'id' => 5,
    ],
  ];
  $this
    ->assertCount(3, $view->result);
  $this
    ->assertIdenticalResultset($view, $expected_result, $this->columnMap);
}