diff --git a/core/modules/options/tests/src/Kernel/Views/OptionsListFilterTest.php b/core/modules/options/tests/src/Kernel/Views/OptionsListFilterTest.php index c62b27549e..bc377b094a 100644 --- a/core/modules/options/tests/src/Kernel/Views/OptionsListFilterTest.php +++ b/core/modules/options/tests/src/Kernel/Views/OptionsListFilterTest.php @@ -35,4 +35,78 @@ public function testViewsTestOptionsListFilter() { $this->assertIdenticalResultset($view, $resultset, $column_map); } + /** + * Tests options list field filter when grouped. + */ + public function testViewsTestOptionsListGroupedFilter() { + $view = Views::getView('test_options_list_filter'); + + $filters = [ + 'field_test_list_string_value' => [ + 'id' => 'field_test_list_string_value', + 'table' => 'field_data_field_test_list_string', + 'field' => 'field_test_list_string_value', + 'relationship' => 'none', + 'group_type' => 'group', + 'admin_label' => '', + 'operator' => 'or', + 'value' => [ + 'man' => 'man', + 'woman' => 'woman', + ], + 'group' => '1', + 'exposed' => TRUE, + 'expose' => [ + 'operator_id' => 'field_test_list_string_value_op', + 'label' => 'list-text', + 'description' => '', + 'identifier' => 'field_test_list_string_value', + ], + 'is_grouped' => TRUE, + 'group_info' => [ + 'label' => 'list-text (field_list_text)', + 'description' => '', + 'identifier' => 'field_test_list_string_value', + 'optional' => TRUE, + 'widget' => 'radios', + 'multiple' => TRUE, + 'remember' => FALSE, + 'default_group' => '1', + 'group_items' => [ + 1 => [ + 'title' => 'First', + 'operator' => 'or', + 'value' => [ + $this->fieldValues[0] => $this->fieldValues[0], + ] + ], + 2 => [ + 'title' => 'Second', + 'operator' => 'or', + 'value' => [ + $this->fieldValues[1] => $this->fieldValues[1], + ] + ], + ], + ], + 'reduce_duplicates' => '', + 'plugin_id' => 'list_field', + ] + ]; + $view->setDisplay(); + $view->displayHandlers->get('default')->overrideOption('filters', $filters); + + $view->storage->save(); + + $this->executeView($view); + + $resultset = [ + ['nid' => $this->nodes[0]->nid->value], + ['nid' => $this->nodes[1]->nid->value], + ]; + + $column_map = ['nid' => 'nid']; + $this->assertIdenticalResultset($view, $resultset, $column_map); + } + } --- a/core/modules/views/src/Tests/Handler/FilterDateTest.php +++ b/core/modules/views/src/Tests/Handler/FilterDateTest.php @@ -152,4 +182,114 @@ protected function _testUiValidation() { $this->assertText(t('Invalid date format.'), 'Make sure that validation is run and the invalidate date format is identified.'); } + /** + * Test date filter UI. + */ + protected function _testFilterDateUI() { + $this->drupalLogin($this->drupalCreateUser(['administer views'])); + $this->drupalGet('admin/structure/views/nojs/handler/test_filter_date_between/default/filter/created'); + $this->drupalPostForm(NULL, [], t('Expose filter')); + $this->drupalPostForm(NULL, [], t('Grouped filters')); + + $edit = []; + $edit['options[group_info][group_items][1][title]'] = 'simple-offset'; + $edit['options[group_info][group_items][1][operator]'] = '>'; + $edit['options[group_info][group_items][1][value][type]'] = 'offset'; + $edit['options[group_info][group_items][1][value][value]'] = '+1 hour'; + $edit['options[group_info][group_items][2][title]'] = 'between-offset'; + $edit['options[group_info][group_items][2][operator]'] = 'between'; + $edit['options[group_info][group_items][2][value][type]'] = 'offset'; + $edit['options[group_info][group_items][2][value][min]'] = '+1 hour'; + $edit['options[group_info][group_items][2][value][max]'] = '+2 days'; + $edit['options[group_info][group_items][3][title]'] = 'between-date'; + $edit['options[group_info][group_items][3][operator]'] = 'between'; + $edit['options[group_info][group_items][3][value][min]'] = format_date(150000, 'custom', 'Y-m-d H:i:s'); + $edit['options[group_info][group_items][3][value][max]'] = format_date(250000, 'custom', 'Y-m-d H:i:s'); + + $this->drupalPostForm(NULL, $edit, t('Apply')); + + $this->drupalGet('admin/structure/views/nojs/handler/test_filter_date_between/default/filter/created'); + foreach ($edit as $name => $value) { + $this->assertFieldByName($name, $value); + if (strpos($name, '[value][type]')) { + $radio = $this->cssSelect('input[name="' . $name . '"][checked="checked"][type="radio"]'); + $this->assertEqual((string) $radio[0]['value'], $value); + } + } + + $this->drupalPostForm('admin/structure/views/view/test_filter_date_between', [], t('Save')); + $this->assertConfigSchemaByName('views.view.test_filter_date_between'); + + // Test that the exposed filter works as expected. + $this->drupalGet('admin/structure/views/view/test_filter_date_between/edit'); + $this->drupalPostForm(NULL, [], t('Update preview')); + $results = $this->cssSelect('.view-content .field-content'); + $this->assertEqual(count($results), 4); + $this->drupalPostForm(NULL, ['created' => '1'], t('Update preview')); + $results = $this->cssSelect('.view-content .field-content'); + $this->assertEqual(count($results), 1); + $this->assertEqual((string) $results[0], $this->nodes[3]->id()); + $this->drupalPostForm(NULL, ['created' => '2'], t('Update preview')); + $results = $this->cssSelect('.view-content .field-content'); + $this->assertEqual(count($results), 1); + $this->assertEqual((string) $results[0], $this->nodes[3]->id()); + $this->drupalPostForm(NULL, ['created' => '3'], t('Update preview')); + $results = $this->cssSelect('.view-content .field-content'); + $this->assertEqual(count($results), 1); + $this->assertEqual((string) $results[0], $this->nodes[1]->id()); + + // Change the filter to a single filter to test the schema when the operator + // is not exposed. + $this->drupalPostForm('admin/structure/views/nojs/handler/test_filter_date_between/default/filter/created', [], t('Single filter')); + $edit = []; + $edit['options[operator]'] = '>'; + $edit['options[value][type]'] = 'date'; + $edit['options[value][value]'] = format_date(350000, 'custom', 'Y-m-d H:i:s'); + $this->drupalPostForm(NULL, $edit, t('Apply')); + $this->drupalPostForm('admin/structure/views/view/test_filter_date_between', [], t('Save')); + $this->assertConfigSchemaByName('views.view.test_filter_date_between'); + + // Test that the filter works as expected. + $this->drupalPostForm(NULL, [], t('Update preview')); + $results = $this->cssSelect('.view-content .field-content'); + $this->assertEqual(count($results), 1); + $this->assertEqual((string) $results[0], $this->nodes[3]->id()); + $this->drupalPostForm(NULL, ['created' => format_date(250000, 'custom', 'Y-m-d H:i:s')], t('Update preview')); + $results = $this->cssSelect('.view-content .field-content'); + $this->assertEqual(count($results), 2); + $this->assertEqual((string) $results[0], $this->nodes[2]->id()); + $this->assertEqual((string) $results[1], $this->nodes[3]->id()); + } + + /** + * Test datetime grouped filter UI. + */ + protected function _testFilterDatetimeUI() { + $this->drupalLogin($this->drupalCreateUser(['administer views'])); + $this->drupalPostForm('admin/structure/views/nojs/add-handler/test_filter_date_between/default/filter', ['name[node__field_date.field_date_value]' => 'node__field_date.field_date_value'], t('Add and configure filter criteria')); + + $this->drupalPostForm(NULL, [], t('Expose filter')); + $this->drupalPostForm(NULL, [], t('Grouped filters')); + + $edit = []; + $edit['options[group_info][group_items][1][title]'] = 'simple-offset'; + $edit['options[group_info][group_items][1][operator]'] = '>'; + $edit['options[group_info][group_items][1][value][type]'] = 'offset'; + $edit['options[group_info][group_items][1][value][value]'] = '+1 hour'; + $edit['options[group_info][group_items][2][title]'] = 'between-offset'; + $edit['options[group_info][group_items][2][operator]'] = 'between'; + $edit['options[group_info][group_items][2][value][type]'] = 'offset'; + $edit['options[group_info][group_items][2][value][min]'] = '+1 hour'; + $edit['options[group_info][group_items][2][value][max]'] = '+2 days'; + $edit['options[group_info][group_items][3][title]'] = 'between-date'; + $edit['options[group_info][group_items][3][operator]'] = 'between'; + $edit['options[group_info][group_items][3][value][min]'] = format_date(150000, 'custom', 'Y-m-d H:i:s'); + $edit['options[group_info][group_items][3][value][max]'] = format_date(250000, 'custom', 'Y-m-d H:i:s'); + + $this->drupalPostForm(NULL, $edit, t('Apply')); + + $this->drupalPostForm('admin/structure/views/view/test_filter_date_between', [], t('Save')); + $this->assertConfigSchemaByName('views.view.test_filter_date_between'); + } + }