function FilterDateTest::testExposedGroupedFilters
Same name in other branches
- 8.9.x core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php \Drupal\Tests\datetime\Functional\Views\FilterDateTest::testExposedGroupedFilters()
- 10 core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php \Drupal\Tests\datetime\Functional\Views\FilterDateTest::testExposedGroupedFilters()
- 11.x core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php \Drupal\Tests\datetime\Functional\Views\FilterDateTest::testExposedGroupedFilters()
Tests exposed grouped filters.
File
-
core/
modules/ datetime/ tests/ src/ Functional/ Views/ FilterDateTest.php, line 124
Class
- FilterDateTest
- Tests Views filters for datetime fields.
Namespace
Drupal\Tests\datetime\Functional\ViewsCode
public function testExposedGroupedFilters() {
// Expose the empty and not empty operators in a grouped filter.
$this->drupalGet('admin/structure/views/nojs/handler/test_filter_datetime/default/filter/' . $this->fieldName . '_value');
$this->submitForm([], 'Expose filter');
$this->submitForm([], 'Grouped filters');
// Test operators with different amount of expected values.
$edit = [];
// No values are required.
$edit['options[group_info][group_items][1][title]'] = 'empty';
$edit['options[group_info][group_items][1][operator]'] = 'empty';
$edit['options[group_info][group_items][2][title]'] = 'not empty';
$edit['options[group_info][group_items][2][operator]'] = 'not empty';
// One value is required.
$edit['options[group_info][group_items][3][title]'] = 'less than';
$edit['options[group_info][group_items][3][operator]'] = '<';
$edit['options[group_info][group_items][3][value][value]'] = $this->dates[0];
// Two values are required (min and max).
$this->submitForm($edit, 'Add another item');
$edit['options[group_info][group_items][4][title]'] = 'between';
$edit['options[group_info][group_items][4][operator]'] = 'between';
$edit['options[group_info][group_items][4][value][type]'] = 'offset';
$edit['options[group_info][group_items][4][value][min]'] = '-2 hours';
$edit['options[group_info][group_items][4][value][max]'] = '+2 hours';
$this->submitForm($edit, 'Apply');
// Test that the exposed filter works as expected.
$path = 'test_filter_datetime-path';
$this->drupalGet('admin/structure/views/view/test_filter_datetime/edit');
$this->submitForm([], 'Add Page');
$this->drupalGet('admin/structure/views/nojs/display/test_filter_datetime/page_1/path');
$this->submitForm([
'path' => $path,
], 'Apply');
$this->submitForm([], 'Save');
$this->drupalGet($path);
// Filter the Preview by 'empty'.
$this->getSession()
->getPage()
->findField($this->fieldName . '_value')
->selectOption(1);
$this->getSession()
->getPage()
->pressButton('Apply');
$this->assertIds([
4,
]);
// Filter the Preview by 'not empty'.
$this->getSession()
->getPage()
->findField($this->fieldName . '_value')
->selectOption(2);
$this->getSession()
->getPage()
->pressButton('Apply');
$this->assertIds([
1,
2,
3,
]);
// Filter the Preview by 'less than'.
$this->getSession()
->getPage()
->findField($this->fieldName . '_value')
->selectOption(3);
$this->getSession()
->getPage()
->pressButton('Apply');
$this->assertIds([
2,
3,
]);
// Filter the Preview by 'between'.
$this->getSession()
->getPage()
->findField($this->fieldName . '_value')
->selectOption(4);
$this->getSession()
->getPage()
->pressButton('Apply');
$this->assertIds([
2,
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.