function FilterInOperatorTest::testFilterInOperatorSimple

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

File

core/modules/views/tests/src/Kernel/Handler/FilterInOperatorTest.php, line 47

Class

FilterInOperatorTest
Tests the core <a href="/api/drupal/core%21modules%21views%21src%21Plugin%21views%21filter%21InOperator.php/class/InOperator/11.x" title="Simple filter to handle matching of multiple options selectable via checkboxes." class="local">Drupal\views\Plugin\views\filter\InOperator</a> handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testFilterInOperatorSimple() : void {
    $view = Views::getView('test_view');
    $view->setDisplay();
    // Add an in_operator ordering.
    $view->displayHandlers
        ->get('default')
        ->overrideOption('filters', [
        'age' => [
            'id' => 'age',
            'field' => 'age',
            'table' => 'views_test_data',
            'value' => [
                26,
                30,
            ],
            'operator' => 'in',
        ],
    ]);
    $this->executeView($view);
    $expected_result = [
        [
            'name' => 'Paul',
            'age' => 26,
        ],
        [
            'name' => 'Meredith',
            'age' => 30,
        ],
    ];
    $this->assertCount(2, $view->result);
    $this->assertIdenticalResultset($view, $expected_result, $this->columnMap);
    $view->destroy();
    $view->setDisplay();
    // Add an in_operator ordering.
    $view->displayHandlers
        ->get('default')
        ->overrideOption('filters', [
        'age' => [
            'id' => 'age',
            'field' => 'age',
            'table' => 'views_test_data',
            'value' => [
                26,
                30,
            ],
            'operator' => 'not in',
        ],
    ]);
    $this->executeView($view);
    $expected_result = [
        [
            'name' => 'John',
            'age' => 25,
        ],
        [
            'name' => 'George',
            'age' => 27,
        ],
        [
            'name' => 'Ringo',
            'age' => 28,
        ],
    ];
    $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.