protected function TimestampTest::setUp in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/FunctionalTests/Datetime/TimestampTest.php \Drupal\FunctionalTests\Datetime\TimestampTest::setUp()
Overrides BrowserTestBase::setUp
File
- core/
tests/ Drupal/ FunctionalTests/ Datetime/ TimestampTest.php, line 54
Class
- TimestampTest
- Tests the functionality of Timestamp core field UI.
Namespace
Drupal\FunctionalTests\DatetimeCode
protected function setUp() {
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,
]);
$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();
}