You are here

public function ExposedFormUITest::testExposedGroupedFilter in Drupal 9

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

Tests the configuration of grouped exposed filters.

File

core/modules/views_ui/tests/src/Functional/ExposedFormUITest.php, line 315

Class

ExposedFormUITest
Tests exposed forms UI functionality.

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testExposedGroupedFilter() {

  // Click the Expose filter button.
  $this
    ->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type');
  $this
    ->submitForm([], 'Expose filter');

  // Select 'Grouped filters' radio button.
  $this
    ->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type');
  $this
    ->submitForm([], 'Grouped filters');

  // Add 3 groupings.
  $edit = [
    'options[group_button][radios][radios]' => 1,
    'options[group_info][group_items][1][title]' => '1st',
    'options[group_info][group_items][1][value][all]' => 'all',
    'options[group_info][group_items][2][title]' => '2nd',
    'options[group_info][group_items][2][value][article]' => 'article',
    'options[group_info][group_items][3][title]' => '3rd',
    'options[group_info][group_items][3][value][page]' => 'page',
  ];

  // Apply the filter settings.
  $this
    ->submitForm($edit, 'Apply');

  // Check that the view is saved without errors.
  $this
    ->submitForm([], 'Save');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Click the Expose filter button.
  $this
    ->drupalGet('admin/structure/views/nojs/add-handler/test_exposed_admin_ui/default/filter');
  $this
    ->submitForm([
    'name[node_field_data.status]' => 1,
  ], 'Add and configure filter criteria');
  $this
    ->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/status');
  $this
    ->submitForm([], 'Expose filter');

  // Select 'Grouped filters' radio button.
  $this
    ->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/status');
  $this
    ->submitForm([], 'Grouped filters');

  // Add 3 groupings.
  $edit = [
    'options[group_button][radios][radios]' => 1,
    'options[group_info][group_items][1][title]' => 'Any',
    'options[group_info][group_items][1][value]' => 'All',
    'options[group_info][group_items][2][title]' => 'Published',
    'options[group_info][group_items][2][value]' => 1,
    'options[group_info][group_items][3][title]' => 'Unpublished',
    'options[group_info][group_items][3][value]' => 0,
  ];

  // Apply the filter settings.
  $this
    ->submitForm($edit, 'Apply');

  // Check that the view is saved without errors.
  $this
    ->submitForm([], 'Save');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/status');

  // Assert the same settings defined before still are there.
  $this
    ->assertSession()
    ->checkboxChecked('edit-options-group-info-group-items-1-value-all');
  $this
    ->assertSession()
    ->checkboxChecked('edit-options-group-info-group-items-2-value-1');
  $this
    ->assertSession()
    ->checkboxChecked('edit-options-group-info-group-items-3-value-0');
}