diff --git a/config/sync/field.field.node.document.field_document_publication_date.yml b/config/sync/field.field.node.document.field_document_publication_date.yml index 0eed94e250..394401271c 100644 --- a/config/sync/field.field.node.document.field_document_publication_date.yml +++ b/config/sync/field.field.node.document.field_document_publication_date.yml @@ -17,7 +17,10 @@ label: 'Publication date' description: '' required: false translatable: false -default_value: { } +default_value: + - + default_date_type: now + default_date: now default_value_callback: '' settings: { } field_type: datetime diff --git a/config/sync/field.storage.node.field_document_publication_date.yml b/config/sync/field.storage.node.field_document_publication_date.yml index 88d67d5513..f73349dc0c 100644 --- a/config/sync/field.storage.node.field_document_publication_date.yml +++ b/config/sync/field.storage.node.field_document_publication_date.yml @@ -4,11 +4,7 @@ status: true dependencies: module: - datetime - - field_permissions - node -third_party_settings: - field_permissions: - permission_type: public _core: default_config_hash: GZlK0SBCOEfMaprdtmTdeKKrhh_gI6XBChrBkVxi9xQ id: node.field_document_publication_date diff --git a/tests/features/joinup_document/add_document.collection.feature b/tests/features/joinup_document/add_document.collection.feature index 2fc6bc23ba..166585e859 100644 --- a/tests/features/joinup_document/add_document.collection.feature +++ b/tests/features/joinup_document/add_document.collection.feature @@ -84,6 +84,11 @@ Feature: "Add document" visibility options. When I go to the homepage of the "Hunter in the Swords" collection Then I should see the link "An amazing document" + # Check that the publication date field is prefilled with the current time. + When I go to the homepage of the "Hunter in the Swords" collection + And I click "Add document" in the plus button menu + Then I see "Publication date" filled with the current time + # Regression test to ensure that no critical errors are thrown when a new # revision is created for a document that has a remote file attached. # @see https://citnet.tech.ec.europa.eu/CITnet/jira/browse/ISAICP-3670 diff --git a/tests/src/Context/JoinupContext.php b/tests/src/Context/JoinupContext.php index b3d7e4d556..4e266b1cb1 100644 --- a/tests/src/Context/JoinupContext.php +++ b/tests/src/Context/JoinupContext.php @@ -914,6 +914,37 @@ public function clearDateRangeField($field, $component, $date = NULL) { $element->setValue(''); } + /** + * Asserts that a date/time field is prefilled with the current time. + * + * @param string $field + * The date/time field name. + * + * @throws \Exception + * When the field is not found. + * + * @Then I see :field filled with the current time + */ + public function assertDateTimeFieldValue(string $field): void { + $now = new \DateTimeImmutable(); + + $date_part = $this->findDateRangeComponent($field, 'date')->getAttribute('value'); + $time_part = $this->findDateRangeComponent($field, 'time')->getAttribute('value'); + if (empty($date_part) || empty($time_part)) { + throw new ExpectationFailedException("The '{$field}' date/time field is not filled with the current time."); + } + + $date = new \DateTimeImmutable("{$date_part} {$time_part}"); + + $interval = $now->diff($date); + // Given that such a test cannot do an exact assertion, because of the + // testing environment latency, we consider 3 seconds as an acceptable + // fuzziness. + if ($interval->f > 3000) { + throw new ExpectationFailedException("The '{$field}' date/time field is not filled with the current time."); + } + } + /** * Finds a datetime field. *