function DateTimeTimeAgoFormatterTest::setUp
Same name in other branches
- 9 core/modules/datetime/tests/src/Functional/DateTimeTimeAgoFormatterTest.php \Drupal\Tests\datetime\Functional\DateTimeTimeAgoFormatterTest::setUp()
- 8.9.x core/modules/datetime/tests/src/Functional/DateTimeTimeAgoFormatterTest.php \Drupal\Tests\datetime\Functional\DateTimeTimeAgoFormatterTest::setUp()
- 11.x core/modules/datetime/tests/src/Functional/DateTimeTimeAgoFormatterTest.php \Drupal\Tests\datetime\Functional\DateTimeTimeAgoFormatterTest::setUp()
Overrides BrowserTestBase::setUp
File
-
core/
modules/ datetime/ tests/ src/ Functional/ DateTimeTimeAgoFormatterTest.php, line 54
Class
- DateTimeTimeAgoFormatterTest
- Tests the functionality of DateTimeTimeAgoFormatter field formatter.
Namespace
Drupal\Tests\datetime\FunctionalCode
protected function setUp() : void {
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_datetime';
$type = 'datetime';
$widget_type = 'datetime_default';
$formatter_type = 'datetime_time_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.