function EntityTestDateRangeTest::setUp

Same name in other branches
  1. 8.9.x core/modules/datetime_range/tests/src/Functional/EntityResource/EntityTest/EntityTestDateRangeTest.php \Drupal\Tests\datetime_range\Functional\EntityResource\EntityTest\EntityTestDateRangeTest::setUp()
  2. 10 core/modules/datetime_range/tests/src/Functional/EntityResource/EntityTest/EntityTestDateRangeTest.php \Drupal\Tests\datetime_range\Functional\EntityResource\EntityTest\EntityTestDateRangeTest::setUp()
  3. 11.x core/modules/datetime_range/tests/src/Functional/EntityResource/EntityTest/EntityTestDateRangeTest.php \Drupal\Tests\datetime_range\Functional\EntityResource\EntityTest\EntityTestDateRangeTest::setUp()

Overrides ConfigEntityResourceTestBase::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

public 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();
}

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