You are here

public function FilterBooleanWebTest::testFilterBooleanUI in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views_ui/tests/src/Functional/FilterBooleanWebTest.php \Drupal\Tests\views_ui\Functional\FilterBooleanWebTest::testFilterBooleanUI()
  2. 9 core/modules/views_ui/tests/src/Functional/FilterBooleanWebTest.php \Drupal\Tests\views_ui\Functional\FilterBooleanWebTest::testFilterBooleanUI()

Tests the filter boolean UI.

File

core/modules/views_ui/tests/src/Functional/FilterBooleanWebTest.php, line 28

Class

FilterBooleanWebTest
Tests the boolean filter UI.

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testFilterBooleanUI() {
  $this
    ->drupalGet('admin/structure/views/nojs/add-handler/test_view/default/filter');
  $this
    ->submitForm([
    'name[views_test_data.status]' => TRUE,
  ], 'Add and configure filter criteria');

  // Check the field widget label. 'title' should be used as a fallback.
  $result = $this
    ->cssSelect('#edit-options-value--wrapper legend span');
  $this
    ->assertEquals('Status', $result[0]
    ->getHtml());

  // Ensure that the operator and the filter value are displayed using correct
  // layout.
  $this
    ->assertSession()
    ->elementExists('css', '.views-left-30 .form-item-options-operator');
  $this
    ->assertSession()
    ->elementExists('css', '.views-right-70 .form-item-options-value');
  $this
    ->submitForm([], 'Expose filter');
  $this
    ->submitForm([], 'Grouped filters');
  $edit = [];
  $edit['options[group_info][group_items][1][title]'] = 'Published';
  $edit['options[group_info][group_items][1][operator]'] = '=';
  $edit['options[group_info][group_items][1][value]'] = 1;
  $edit['options[group_info][group_items][2][title]'] = 'Not published';
  $edit['options[group_info][group_items][2][operator]'] = '=';
  $edit['options[group_info][group_items][2][value]'] = 0;
  $edit['options[group_info][group_items][3][title]'] = 'Not published2';
  $edit['options[group_info][group_items][3][operator]'] = '!=';
  $edit['options[group_info][group_items][3][value]'] = 1;
  $this
    ->submitForm($edit, 'Apply');
  $this
    ->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/status');
  $result = $this
    ->xpath('//input[@name="options[group_info][group_items][1][value]"]');
  $this
    ->assertEquals('checked', $result[1]
    ->getAttribute('checked'));
  $result = $this
    ->xpath('//input[@name="options[group_info][group_items][2][value]"]');
  $this
    ->assertEquals('checked', $result[2]
    ->getAttribute('checked'));
  $result = $this
    ->xpath('//input[@name="options[group_info][group_items][3][value]"]');
  $this
    ->assertEquals('checked', $result[1]
    ->getAttribute('checked'));

  // Test that there is a remove link for each group.
  $this
    ->assertCount(3, $this
    ->cssSelect('a.views-remove-link'));

  // Test selecting a default and removing an item.
  $edit = [];
  $edit['options[group_info][default_group]'] = 2;
  $edit['options[group_info][group_items][3][remove]'] = 1;
  $this
    ->submitForm($edit, 'Apply');
  $this
    ->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/status');
  $this
    ->assertSession()
    ->fieldValueEquals('options[group_info][default_group]', 2);
  $this
    ->assertSession()
    ->fieldNotExists('options[group_info][group_items][3][remove]');
}