function TimestampTest::setUp

Same name in other branches
  1. 9 core/tests/Drupal/FunctionalTests/Datetime/TimestampTest.php \Drupal\FunctionalTests\Datetime\TimestampTest::setUp()
  2. 8.9.x core/tests/Drupal/FunctionalTests/Datetime/TimestampTest.php \Drupal\FunctionalTests\Datetime\TimestampTest::setUp()
  3. 10 core/tests/Drupal/FunctionalTests/Datetime/TimestampTest.php \Drupal\FunctionalTests\Datetime\TimestampTest::setUp()

Overrides BrowserTestBase::setUp

File

core/tests/Drupal/FunctionalTests/Datetime/TimestampTest.php, line 56

Class

TimestampTest
Tests the functionality of Timestamp core field UI.

Namespace

Drupal\FunctionalTests\Datetime

Code

protected function setUp() : void {
    parent::setUp();
    $web_user = $this->drupalCreateUser([
        'access content',
        'view test entity',
        'administer entity_test content',
        'administer entity_test form display',
        'administer content types',
        'administer node fields',
    ]);
    $this->drupalLogin($web_user);
    $field_name = 'field_timestamp';
    $type = 'timestamp';
    $widget_type = 'datetime_timestamp';
    $formatter_type = 'timestamp';
    $this->fieldStorage = FieldStorageConfig::create([
        'field_name' => $field_name,
        'entity_type' => 'entity_test',
        'type' => $type,
    ]);
    $this->fieldStorage
        ->save();
    $this->field = FieldConfig::create([
        'field_storage' => $this->fieldStorage,
        'bundle' => 'entity_test',
        'required' => TRUE,
        'description' => 'Description for timestamp field.',
    ]);
    $this->field
        ->save();
    EntityFormDisplay::load('entity_test.entity_test.default')->setComponent($field_name, [
        'type' => $widget_type,
    ])
        ->save();
    $this->displayOptions = [
        'type' => $formatter_type,
        'label' => 'hidden',
    ];
    EntityViewDisplay::create([
        'targetEntityType' => $this->field
            ->getTargetEntityTypeId(),
        'bundle' => $this->field
            ->getTargetBundle(),
        'mode' => 'full',
        'status' => TRUE,
    ])
        ->setComponent($field_name, $this->displayOptions)
        ->save();
}

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