diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Core/Field/TimestampFormatterWithTimeagoTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Core/Field/TimestampFormatterWithTimeagoTest.php new file mode 100644 index 0000000000..93acfd8d54 --- /dev/null +++ b/core/tests/Drupal/FunctionalJavascriptTests/Core/Field/TimestampFormatterWithTimeagoTest.php @@ -0,0 +1,89 @@ + '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' => [ + 'timeago' => [ + '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); + } + + /** + * Tests the 'timestamp' formatter when is used with 'time ago' setting. + */ + public function testTimestampFormatterWithTimeago() { + $entity = EntityTest::create([ + 'type' => 'entity_test', + 'name' => $this->randomString(), + 'time_field' => $this->container->get('datetime.time')->getRequestTime(), + ]); + $entity->save(); + + $this->drupalGet($entity->toUrl()); + + $this->assertJsCondition("jQuery('time:contains(\"5 seconds\")').length > 0"); + } + +}