From 38fd9114f1aa1c97fcee0371325e522c16713138 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Wed, 24 Mar 2021 20:11:40 +0200 Subject: [PATCH] ISAICP-6449: Add a regression test. --- .../add_document.collection.feature | 5 +++ tests/src/Context/JoinupContext.php | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+) 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. *