function FilterBooleanOperatorTest::testFilterBooleanOperator

Same name and namespace in other branches
  1. 8.9.x core/modules/views/tests/src/Kernel/Handler/FilterBooleanOperatorTest.php \Drupal\Tests\views\Kernel\Handler\FilterBooleanOperatorTest::testFilterBooleanOperator()
  2. 10 core/modules/views/tests/src/Kernel/Handler/FilterBooleanOperatorTest.php \Drupal\Tests\views\Kernel\Handler\FilterBooleanOperatorTest::testFilterBooleanOperator()
  3. 11.x core/modules/views/tests/src/Kernel/Handler/FilterBooleanOperatorTest.php \Drupal\Tests\views\Kernel\Handler\FilterBooleanOperatorTest::testFilterBooleanOperator()

Tests the BooleanOperator filter.

File

core/modules/views/tests/src/Kernel/Handler/FilterBooleanOperatorTest.php, line 42

Class

FilterBooleanOperatorTest
Tests the core <a href="/api/drupal/core%21modules%21views%21src%21Plugin%21views%21filter%21BooleanOperator.php/class/BooleanOperator/9" title="Simple filter to handle matching of boolean values." class="local">Drupal\views\Plugin\views\filter\BooleanOperator</a> handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testFilterBooleanOperator() {
    $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);
    $view->destroy();
    $view->setDisplay();
    // Testing the same scenario but using the reverse status and operation.
    $view->displayHandlers
        ->get('default')
        ->overrideOption('filters', [
        'status' => [
            'id' => 'status',
            'field' => 'status',
            'table' => 'views_test_data',
            'value' => 0,
            'operator' => '!=',
        ],
    ]);
    $this->executeView($view);
    $expected_result = [
        [
            'id' => 1,
        ],
        [
            'id' => 3,
        ],
        [
            'id' => 5,
        ],
    ];
    $this->assertCount(3, $view->result);
    $this->assertIdenticalResultset($view, $expected_result, $this->columnMap);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.