You are here

protected function TimestampAgoFormatterTest::setUp in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/FunctionalTests/Datetime/TimestampAgoFormatterTest.php \Drupal\FunctionalTests\Datetime\TimestampAgoFormatterTest::setUp()
  2. 9 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\Datetime

Code

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_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();
}