X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Ftests%2FDrupal%2FFunctionalTests%2FDatetime%2FTimestampAgoFormatterTest.php;fp=web%2Fcore%2Ftests%2FDrupal%2FFunctionalTests%2FDatetime%2FTimestampAgoFormatterTest.php;h=dde8a06a6ca4c5c4dc56fc53ab1893f8c2905f96;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/tests/Drupal/FunctionalTests/Datetime/TimestampAgoFormatterTest.php b/web/core/tests/Drupal/FunctionalTests/Datetime/TimestampAgoFormatterTest.php new file mode 100644 index 000000000..dde8a06a6 --- /dev/null +++ b/web/core/tests/Drupal/FunctionalTests/Datetime/TimestampAgoFormatterTest.php @@ -0,0 +1,122 @@ +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(); + } + + /** + * Tests the formatter settings. + */ + public function testSettings() { + $this->drupalGet('entity_test/structure/entity_test/display'); + + $edit = [ + 'fields[field_timestamp][region]' => 'content', + 'fields[field_timestamp][type]' => 'timestamp_ago', + ]; + $this->drupalPostForm(NULL, $edit, t('Save')); + + $this->drupalPostForm(NULL, [], 'field_timestamp_settings_edit'); + $edit = [ + 'fields[field_timestamp][settings_edit_form][settings][future_format]' => 'ends in @interval', + 'fields[field_timestamp][settings_edit_form][settings][past_format]' => 'started @interval ago', + 'fields[field_timestamp][settings_edit_form][settings][granularity]' => 3, + ]; + $this->drupalPostForm(NULL, $edit, 'Update'); + $this->drupalPostForm(NULL, [], 'Save'); + + $this->assertSession()->pageTextContains('ends in 1 year 1 month 1 week'); + $this->assertSession()->pageTextContains('started 1 year 1 month 1 week ago'); + } + +}