function FilterDateTest::_testFilterDateUI
Same name in other branches
- 8.9.x core/modules/views/tests/src/Functional/Handler/FilterDateTest.php \Drupal\Tests\views\Functional\Handler\FilterDateTest::_testFilterDateUI()
- 10 core/modules/views/tests/src/Functional/Handler/FilterDateTest.php \Drupal\Tests\views\Functional\Handler\FilterDateTest::_testFilterDateUI()
- 11.x core/modules/views/tests/src/Functional/Handler/FilterDateTest.php \Drupal\Tests\views\Functional\Handler\FilterDateTest::_testFilterDateUI()
Tests date filter UI.
1 call to FilterDateTest::_testFilterDateUI()
- FilterDateTest::testDateFilter in core/
modules/ views/ tests/ src/ Functional/ Handler/ FilterDateTest.php - Runs other test methods.
File
-
core/
modules/ views/ tests/ src/ Functional/ Handler/ FilterDateTest.php, line 218
Class
- FilterDateTest
- Tests the core Drupal\views\Plugin\views\filter\Date handler.
Namespace
Drupal\Tests\views\Functional\HandlerCode
protected function _testFilterDateUI() {
$this->drupalLogin($this->drupalCreateUser([
'administer views',
]));
$this->drupalGet('admin/structure/views/nojs/handler/test_filter_date_between/default/filter/created');
$this->submitForm([], 'Expose filter');
$this->submitForm([], '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]'] = $this->dateFormatter
->format(150000, 'custom', 'Y-m-d H:i:s');
$edit['options[group_info][group_items][3][value][max]'] = $this->dateFormatter
->format(250000, 'custom', 'Y-m-d H:i:s');
$this->submitForm($edit, 'Apply');
$this->drupalGet('admin/structure/views/nojs/handler/test_filter_date_between/default/filter/created');
foreach ($edit as $name => $value) {
$this->assertSession()
->fieldValueEquals($name, $value);
if (strpos($name, '[value][type]')) {
$radio = $this->cssSelect('input[name="' . $name . '"][checked="checked"][type="radio"]');
$this->assertEquals($value, $radio[0]->getAttribute('value'));
}
}
$this->drupalGet('admin/structure/views/view/test_filter_date_between');
$this->submitForm([], 'Save');
$this->assertConfigSchemaByName('views.view.test_filter_date_between');
// Test that the exposed filter works as expected.
$path = 'test_filter_date_between-path';
$this->drupalGet('admin/structure/views/view/test_filter_date_between/edit');
$this->submitForm([], 'Add Page');
$this->drupalGet('admin/structure/views/nojs/display/test_filter_date_between/page_1/path');
$this->submitForm([
'path' => $path,
], 'Apply');
$this->submitForm([], 'Save');
$this->drupalGet($path);
$this->submitForm([], 'Apply');
$results = $this->cssSelect('.view-content .field-content');
$this->assertCount(4, $results);
$this->submitForm([
'created' => '1',
], 'Apply');
$results = $this->cssSelect('.view-content .field-content');
$this->assertCount(1, $results);
$this->assertEquals($this->nodes[3]
->id(), $results[0]->getText());
$this->submitForm([
'created' => '2',
], 'Apply');
$results = $this->cssSelect('.view-content .field-content');
$this->assertCount(1, $results);
$this->assertEquals($this->nodes[3]
->id(), $results[0]->getText());
$this->submitForm([
'created' => '3',
], 'Apply');
$results = $this->cssSelect('.view-content .field-content');
$this->assertCount(1, $results);
$this->assertEquals($this->nodes[1]
->id(), $results[0]->getText());
// Change the filter to a single filter to test the schema when the operator
// is not exposed.
$this->drupalGet('admin/structure/views/nojs/handler/test_filter_date_between/default/filter/created');
$this->submitForm([], 'Single filter');
$edit = [];
$edit['options[operator]'] = '>';
$edit['options[value][type]'] = 'date';
$edit['options[value][value]'] = $this->dateFormatter
->format(350000, 'custom', 'Y-m-d H:i:s');
$this->submitForm($edit, 'Apply');
$this->drupalGet('admin/structure/views/view/test_filter_date_between');
$this->submitForm([], 'Save');
$this->assertConfigSchemaByName('views.view.test_filter_date_between');
// Test that the filter works as expected.
$this->drupalGet($path);
$results = $this->cssSelect('.view-content .field-content');
$this->assertCount(1, $results);
$this->assertEquals($this->nodes[3]
->id(), $results[0]->getText());
$this->submitForm([
'created' => $this->dateFormatter
->format(250000, 'custom', 'Y-m-d H:i:s'),
], 'Apply');
$results = $this->cssSelect('.view-content .field-content');
$this->assertCount(2, $results);
$this->assertEquals($this->nodes[2]
->id(), $results[0]->getText());
$this->assertEquals($this->nodes[3]
->id(), $results[1]->getText());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.