function DateTimeHandlerTestBase::setUp

Same name in this branch
  1. 8.9.x core/modules/datetime/tests/src/Kernel/Views/DateTimeHandlerTestBase.php \Drupal\Tests\datetime\Kernel\Views\DateTimeHandlerTestBase::setUp()
Same name and namespace in other branches
  1. 9 core/modules/datetime/tests/src/Kernel/Views/DateTimeHandlerTestBase.php \Drupal\Tests\datetime\Kernel\Views\DateTimeHandlerTestBase::setUp()
  2. 10 core/modules/datetime/tests/src/Kernel/Views/DateTimeHandlerTestBase.php \Drupal\Tests\datetime\Kernel\Views\DateTimeHandlerTestBase::setUp()
  3. 11.x core/modules/datetime/tests/src/Kernel/Views/DateTimeHandlerTestBase.php \Drupal\Tests\datetime\Kernel\Views\DateTimeHandlerTestBase::setUp()

Overrides ViewTestBase::setUp

File

core/modules/datetime/src/Tests/Views/DateTimeHandlerTestBase.php, line 46

Class

DateTimeHandlerTestBase
Base class for testing datetime handlers.

Namespace

Drupal\datetime\Tests\Views

Code

protected function setUp($import_test_views = TRUE) {
  parent::setUp($import_test_views);
  // Add a date field to page nodes.
  $node_type = NodeType::create([
    'type' => 'page',
    'name' => 'page',
  ]);
  $node_type->save();
  $fieldStorage = FieldStorageConfig::create([
    'field_name' => static::$field_name,
    'entity_type' => 'node',
    'type' => 'datetime',
    'settings' => [
      'datetime_type' => DateTimeItem::DATETIME_TYPE_DATETIME,
    ],
  ]);
  $fieldStorage->save();
  $field = FieldConfig::create([
    'field_storage' => $fieldStorage,
    'bundle' => 'page',
    'required' => TRUE,
  ]);
  $field->save();
  // Views needs to be aware of the new field.
  $this->container
    ->get('views.views_data')
    ->clear();
  // Set column map.
  $this->map = [
    'nid' => 'nid',
  ];
  // Load test views.
  ViewTestData::createTestViews(get_class($this), [
    'datetime_test',
  ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.