You are here

protected function DateTimeHandlerTestBase::setUp in Drupal 8

Same name in this branch
  1. 8 core/modules/datetime/src/Tests/Views/DateTimeHandlerTestBase.php \Drupal\datetime\Tests\Views\DateTimeHandlerTestBase::setUp()
  2. 8 core/modules/datetime/tests/src/Kernel/Views/DateTimeHandlerTestBase.php \Drupal\Tests\datetime\Kernel\Views\DateTimeHandlerTestBase::setUp()

Sets up a Drupal site for running functional and integration tests.

Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.

Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

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',
  ]);
}