function TimestampAgoFormatterTest::setUp
Same name in other branches
- 9 core/tests/Drupal/FunctionalTests/Datetime/TimestampAgoFormatterTest.php \Drupal\FunctionalTests\Datetime\TimestampAgoFormatterTest::setUp()
- 10 core/tests/Drupal/FunctionalTests/Datetime/TimestampAgoFormatterTest.php \Drupal\FunctionalTests\Datetime\TimestampAgoFormatterTest::setUp()
- 11.x core/tests/Drupal/FunctionalTests/Datetime/TimestampAgoFormatterTest.php \Drupal\FunctionalTests\Datetime\TimestampAgoFormatterTest::setUp()
Overrides BrowserTestBase::setUp
File
-
core/
tests/ Drupal/ FunctionalTests/ Datetime/ TimestampAgoFormatterTest.php, line 52
Class
- TimestampAgoFormatterTest
- Tests the functionality of TimestampAgoFormatter core field formatter.
Namespace
Drupal\FunctionalTests\DatetimeCode
protected function setUp() {
parent::setUp();
$web_user = $this->drupalCreateUser([
'access administration pages',
'view test entity',
'administer entity_test content',
'administer entity_test fields',
'administer entity_test display',
'administer entity_test form display',
'view the administration theme',
]);
$this->drupalLogin($web_user);
$field_name = 'field_timestamp';
$type = 'timestamp';
$widget_type = 'datetime_timestamp';
$formatter_type = 'timestamp_ago';
$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();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.