function EntityTestDateonlyTest::setUp

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

Overrides EntityResourceTestBase::setUp

File

core/modules/datetime/tests/src/Functional/EntityResource/EntityTest/EntityTestDateonlyTest.php, line 50

Class

EntityTestDateonlyTest
Tests the datetime field constraint with 'date' items.

Namespace

Drupal\Tests\datetime\Functional\EntityResource\EntityTest

Code

public function setUp() {
    parent::setUp();
    // Add datetime field.
    FieldStorageConfig::create([
        'field_name' => static::$fieldName,
        'type' => 'datetime',
        'entity_type' => static::$entityTypeId,
        'settings' => [
            'datetime_type' => DateTimeItem::DATETIME_TYPE_DATE,
        ],
    ])->save();
    FieldConfig::create([
        'field_name' => static::$fieldName,
        'entity_type' => static::$entityTypeId,
        'bundle' => $this->entity
            ->bundle(),
        'settings' => [
            'default_value' => static::$dateString,
        ],
    ])
        ->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,
    ]);
    $this->entity
        ->save();
}

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