function FilterDateTimeTest::setUp
Same name in other branches
- 8.9.x core/modules/datetime/tests/src/Kernel/Views/FilterDateTimeTest.php \Drupal\Tests\datetime\Kernel\Views\FilterDateTimeTest::setUp()
- 10 core/modules/datetime/tests/src/Kernel/Views/FilterDateTimeTest.php \Drupal\Tests\datetime\Kernel\Views\FilterDateTimeTest::setUp()
- 11.x core/modules/datetime/tests/src/Kernel/Views/FilterDateTimeTest.php \Drupal\Tests\datetime\Kernel\Views\FilterDateTimeTest::setUp()
Overrides DateTimeHandlerTestBase::setUp
File
-
core/
modules/ datetime/ tests/ src/ Kernel/ Views/ FilterDateTimeTest.php, line 38
Class
- FilterDateTimeTest
- Tests the Drupal\datetime\Plugin\views\filter\Date handler.
Namespace
Drupal\Tests\datetime\Kernel\ViewsCode
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
static::$date = REQUEST_TIME + 86400;
// Set the timezone.
date_default_timezone_set(static::$timezone);
$this->config('system.date')
->set('timezone.default', static::$timezone)
->save();
// Add some basic test nodes.
$dates = [
'2000-10-10T00:01:30',
'2001-10-10T12:12:12',
'2002-10-10T14:14:14',
// The date storage timezone is used (this mimics the steps taken in the
// widget: \Drupal\datetime\Plugin\Field\FieldWidget::messageFormValues().
\Drupal::service('date.formatter')->format(static::$date, 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT, DateTimeItemInterface::STORAGE_TIMEZONE),
];
foreach ($dates as $date) {
$node = Node::create([
'title' => $this->randomMachineName(8),
'type' => 'page',
'field_date' => [
'value' => $date,
],
]);
$node->save();
$this->nodes[] = $node;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.