public function FilterDateTest::testDateOffsets in Drupal 9
Same name in this branch
- 9 core/modules/datetime_range/tests/src/Kernel/Views/FilterDateTest.php \Drupal\Tests\datetime_range\Kernel\Views\FilterDateTest::testDateOffsets()
- 9 core/modules/datetime/tests/src/Kernel/Views/FilterDateTest.php \Drupal\Tests\datetime\Kernel\Views\FilterDateTest::testDateOffsets()
Same name and namespace in other branches
- 8 core/modules/datetime_range/tests/src/Kernel/Views/FilterDateTest.php \Drupal\Tests\datetime_range\Kernel\Views\FilterDateTest::testDateOffsets()
- 10 core/modules/datetime_range/tests/src/Kernel/Views/FilterDateTest.php \Drupal\Tests\datetime_range\Kernel\Views\FilterDateTest::testDateOffsets()
Tests offsets with date-only fields.
File
- core/
modules/ datetime_range/ tests/ src/ Kernel/ Views/ FilterDateTest.php, line 119
Class
- FilterDateTest
- Tests date-only fields.
Namespace
Drupal\Tests\datetime_range\Kernel\ViewsCode
public function testDateOffsets() {
$view = Views::getView('test_filter_datetime');
$field_start = static::$field_name . '_value';
$field_end = static::$field_name . '_end_value';
// Test simple operations.
$view
->initHandlers();
// Search nodes with:
// - start date greater than or equal to 'yesterday'.
// - end date lower than or equal to 'today'.
// Expected results: nodes 0 and 1.
$view->filter[$field_start]->operator = '>=';
$view->filter[$field_start]->value['type'] = 'offset';
$view->filter[$field_start]->value['value'] = '-1 day';
$view->filter[$field_end]->operator = '<=';
$view->filter[$field_end]->value['type'] = 'offset';
$view->filter[$field_end]->value['value'] = 'now';
$view
->setDisplay('default');
$this
->executeView($view);
$expected_result = [
[
'nid' => $this->nodes[0]
->id(),
],
[
'nid' => $this->nodes[1]
->id(),
],
];
$this
->assertIdenticalResultset($view, $expected_result, $this->map);
$view
->destroy();
// Search nodes with:
// - start date greater than or equal to 'yesterday'.
// - end date greater than 'today'.
// Expected results: node 2.
$view
->initHandlers();
$view->filter[$field_start]->operator = '>=';
$view->filter[$field_start]->value['type'] = 'offset';
$view->filter[$field_start]->value['value'] = '-1 day';
$view->filter[$field_end]->operator = '>';
$view->filter[$field_end]->value['type'] = 'offset';
$view->filter[$field_end]->value['value'] = 'now';
$view
->setDisplay('default');
$this
->executeView($view);
$expected_result = [
[
'nid' => $this->nodes[2]
->id(),
],
];
$this
->assertIdenticalResultset($view, $expected_result, $this->map);
}