function TimestampFormatterWithTimeDiffTest::setUp

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/FunctionalJavascriptTests/Core/Field/TimestampFormatterWithTimeDiffTest.php \Drupal\FunctionalJavascriptTests\Core\Field\TimestampFormatterWithTimeDiffTest::setUp()

Overrides BrowserTestBase::setUp

File

core/tests/Drupal/FunctionalJavascriptTests/Core/Field/TimestampFormatterWithTimeDiffTest.php, line 41

Class

TimestampFormatterWithTimeDiffTest
Tests the 'timestamp' formatter when is used with time difference setting.

Namespace

Drupal\FunctionalJavascriptTests\Core\Field

Code

protected function setUp() : void {
  parent::setUp();
  FieldStorageConfig::create([
    'entity_type' => 'entity_test',
    'field_name' => 'time_field',
    'type' => 'timestamp',
  ])->save();
  FieldConfig::create([
    'entity_type' => 'entity_test',
    'bundle' => 'entity_test',
    'field_name' => 'time_field',
    'label' => $this->randomString(),
  ])
    ->save();
  $display = EntityViewDisplay::create([
    'targetEntityType' => 'entity_test',
    'bundle' => 'entity_test',
    'mode' => 'default',
  ]);
  $display->setComponent('time_field', [
    'type' => 'timestamp',
    'settings' => [
      'time_diff' => [
        'enabled' => TRUE,
        'future_format' => '@interval hence',
        'past_format' => '@interval ago',
        'granularity' => 2,
        'refresh' => 1,
      ],
    ],
  ])
    ->setStatus(TRUE)
    ->save();
  $account = $this->createUser([
    'view test entity',
    'administer entity_test content',
  ]);
  $this->drupalLogin($account);
  $this->entity = EntityTest::create([
    'type' => 'entity_test',
    'name' => $this->randomString(),
    'time_field' => $this->container
      ->get('datetime.time')
      ->getRequestTime(),
  ]);
  $this->entity
    ->save();
}

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