You are here

protected function EntityTestDateRangeTest::setUp in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/datetime_range/tests/src/Functional/EntityResource/EntityTest/EntityTestDateRangeTest.php \Drupal\Tests\datetime_range\Functional\EntityResource\EntityTest\EntityTestDateRangeTest::setUp()
  2. 9 core/modules/datetime_range/tests/src/Functional/EntityResource/EntityTest/EntityTestDateRangeTest.php \Drupal\Tests\datetime_range\Functional\EntityResource\EntityTest\EntityTestDateRangeTest::setUp()

File

core/modules/datetime_range/tests/src/Functional/EntityResource/EntityTest/EntityTestDateRangeTest.php, line 50

Class

EntityTestDateRangeTest
Tests the 'daterange' field's normalization.

Namespace

Drupal\Tests\datetime_range\Functional\EntityResource\EntityTest

Code

protected function setUp() : void {
  parent::setUp();

  // Add datetime_range field.
  FieldStorageConfig::create([
    'field_name' => static::$fieldName,
    'type' => 'daterange',
    'entity_type' => static::$entityTypeId,
    'settings' => [
      'datetime_type' => DateRangeItem::DATETIME_TYPE_ALLDAY,
    ],
  ])
    ->save();
  FieldConfig::create([
    'field_name' => static::$fieldName,
    'entity_type' => static::$entityTypeId,
    'bundle' => $this->entity
      ->bundle(),
  ])
    ->save();

  // Reload entity so that it has the new field.
  $this->entity = $this->entityStorage
    ->load($this->entity
    ->id());
  $this->entity
    ->set(static::$fieldName, [
    'value' => static::$dateString,
    'end_value' => static::$dateString,
  ]);
  $this->entity
    ->save();
}