function ExposedFormUITest::testExposedGroupedFilter
Same name in other branches
- 8.9.x core/modules/views_ui/tests/src/Functional/ExposedFormUITest.php \Drupal\Tests\views_ui\Functional\ExposedFormUITest::testExposedGroupedFilter()
- 10 core/modules/views_ui/tests/src/Functional/ExposedFormUITest.php \Drupal\Tests\views_ui\Functional\ExposedFormUITest::testExposedGroupedFilter()
- 11.x 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 314
Class
- ExposedFormUITest
- Tests exposed forms UI functionality.
Namespace
Drupal\Tests\views_ui\FunctionalCode
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',
'options[group_info][default_group]' => '3',
];
// Apply the filter settings.
$this->submitForm($edit, 'Apply');
// Check that the view is saved without errors.
$this->submitForm([], 'Save');
$this->assertSession()
->statusCodeEquals(200);
// Check the default filter value.
$this->drupalGet('test_exposed_admin_ui');
$this->assertSession()
->fieldValueEquals('type', '3');
// Enable "Allow multiple selections" option and set a default group.
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type');
$edit['options[group_info][multiple]'] = 1;
$edit['options[group_info][default_group_multiple][1]'] = 1;
$this->submitForm($edit, 'Apply');
$this->submitForm([], 'Save');
// Check the default filter values again.
$this->drupalGet('test_exposed_admin_ui');
$this->assertSession()
->checkboxChecked('type[1]');
$this->assertSession()
->checkboxNotChecked('type[2]');
$this->assertSession()
->checkboxNotChecked('type[3]');
// 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,
'options[group_info][default_group]' => 2,
];
// 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');
// Check the default filter value.
$this->drupalGet('test_exposed_admin_ui');
$this->assertSession()
->fieldValueEquals('status', '2');
// Enable "Allow multiple selections" option and set a default group.
$this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/status');
$edit['options[group_info][multiple]'] = 1;
$edit['options[group_info][default_group_multiple][3]'] = 1;
$this->submitForm($edit, 'Apply');
$this->submitForm([], 'Save');
// Check the default filter value again.
$this->drupalGet('test_exposed_admin_ui');
$this->assertSession()
->checkboxNotChecked('status[1]');
$this->assertSession()
->checkboxNotChecked('status[2]');
$this->assertSession()
->checkboxChecked('status[3]');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.