You are here

protected function FilterDateTimeTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/datetime/tests/src/Kernel/Views/FilterDateTimeTest.php \Drupal\Tests\datetime\Kernel\Views\FilterDateTimeTest::setUp()

Parameters

bool $import_test_views: Should the views specified on the test class be imported. If you need to setup some additional stuff, like fields, you need to call false and then call createTestViews for your own.

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\Views

Code

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;
  }
}