function FilterTest::testLimitExposedOperators

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Functional/Plugin/FilterTest.php \Drupal\Tests\views\Functional\Plugin\FilterTest::testLimitExposedOperators()
  2. 10 core/modules/views/tests/src/Functional/Plugin/FilterTest.php \Drupal\Tests\views\Functional\Plugin\FilterTest::testLimitExposedOperators()
  3. 11.x core/modules/views/tests/src/Functional/Plugin/FilterTest.php \Drupal\Tests\views\Functional\Plugin\FilterTest::testLimitExposedOperators()

Tests the limit of the expose operator functionality.

File

core/modules/views/tests/src/Functional/Plugin/FilterTest.php, line 181

Class

FilterTest
Tests general filter plugin functionality.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testLimitExposedOperators() {
    $this->drupalGet('test_filter_in_operator_ui');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->optionExists('edit-nid-op', '<');
    $this->assertSession()
        ->optionExists('edit-nid-op', '<=');
    $this->assertSession()
        ->optionExists('edit-nid-op', '=');
    $this->assertSession()
        ->optionNotExists('edit-nid-op', '>');
    $this->assertSession()
        ->optionNotExists('edit-nid-op', '>=');
    // Because there are not operators that use the min and max fields, those
    // fields should not be in the exposed form.
    $this->assertSession()
        ->fieldExists('edit-nid-value');
    $this->assertSession()
        ->fieldNotExists('edit-nid-min');
    $this->assertSession()
        ->fieldNotExists('edit-nid-max');
    $edit = [];
    $edit['options[operator]'] = '>';
    $edit['options[expose][operator_list][]'] = [
        '>',
        '>=',
        'between',
    ];
    $this->drupalGet('admin/structure/views/nojs/handler/test_filter_in_operator_ui/default/filter/nid');
    $this->submitForm($edit, 'Apply');
    $this->drupalGet('admin/structure/views/view/test_filter_in_operator_ui/edit/default');
    $this->submitForm([], 'Save');
    $this->drupalGet('test_filter_in_operator_ui');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->optionNotExists('edit-nid-op', '<');
    $this->assertSession()
        ->optionNotExists('edit-nid-op', '<=');
    $this->assertSession()
        ->optionNotExists('edit-nid-op', '=');
    $this->assertSession()
        ->optionExists('edit-nid-op', '>');
    $this->assertSession()
        ->optionExists('edit-nid-op', '>=');
    $this->assertSession()
        ->fieldExists('edit-nid-value');
    $this->assertSession()
        ->fieldExists('edit-nid-min');
    $this->assertSession()
        ->fieldExists('edit-nid-max');
    // Set the default to an excluded operator.
    $edit = [];
    $edit['options[operator]'] = '=';
    $edit['options[expose][operator_list][]'] = [
        '<',
        '>',
    ];
    $this->drupalGet('admin/structure/views/nojs/handler/test_filter_in_operator_ui/default/filter/nid');
    $this->submitForm($edit, 'Apply');
    $this->assertSession()
        ->pageTextContains('You selected the "Is equal to" operator as the default value but is not included in the list of limited operators.');
}

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