DrupalDriver icon indicating copy to clipboard operation
DrupalDriver copied to clipboard

'Date only' date type field is not being created while running behat tests

Open amitsharmadoj opened this issue 5 years ago • 5 comments

After upgrading drupal core from 8.3.9 to 8.6.1, behat from 3.1.0 to 3.3.1 and drupal-driver from 1.2.x-dev to 2.0.x-dev, behat tests are failing for dates of 'Date only' date type. D8 has two date types 'Date and time' and 'Date only' for 'Date' field. There is no issue with 'Date and time' date type. It looks drupal-driver is not able to create dates of 'Date only' date type. I have tried different date formats but none is working. I can create pages with 'Date only' dates and they appear correctly on the page in the desired format, it is just the behat test which is failing to generate it on the page. It looks DatetimeHandler class in not handling 'Date only' date type.

My test.feature looks like (field_publication_date is 'Date only' date) @api Feature: I can see publication data on publication page. Background: Given I am an anonymous user And "publication" content: | title | moderation_state | field_publication_author | field_publication_date | | test-title | published | test-author | 2016-09-01 |

Scenario: I can see the correct publication data Given I am on "/test-title" And I should see the text "test-author" And I should see the text "September 2016"

Error: 001 Scenario: I can see publication data on publication page # features/publication.feature:35 And I should see the text "September 2016" # features/publication.feature:44 The text "September 2016" was not found anywhere in the text of the current page. (Behat\Mink\Exception\ResponseTextException)

Format tried: 2016-09-01, 2016/09/01, 01/09/2016, 01-09-2016, 2016-09-01T05:00:00, 2016-09-01 12:12:12, 1 minutes ago etc. As I said it doesn't looks like format issue. Behat is not able to create date of 'Date only' type. I have also tried putting break just before date test statement to see if date is being created in different format other than expected but date field along with its label is not at all present on the page.

Versions used:

behat/behat:    v3.3.1 
behat/gherkin:    v4.5.1 
behat/mink:    v1.7.1 
drupal/drupal-driver:   2.0.x-dev
drupal/core:    8.6.1

--

amitsharmadoj avatar Nov 01 '18 00:11 amitsharmadoj

Patch created and it resolved my issue https://patch-diff.githubusercontent.com/raw/jhedstrom/DrupalDriver/pull/201.patch

amitsharmadoj avatar Nov 01 '18 03:11 amitsharmadoj

Yeah I just ran into this as well. I upgraded from 1.4.0 to 2.1.0. It was broken with this PR https://github.com/jhedstrom/DrupalDriver/pull/126 and this commit: https://github.com/jhedstrom/DrupalDriver/commit/e778cb87268ab17bb89c6cc5f4479ab2974b41b4

I'm not sure that patch is appropriate though. It seems like it would always ignore time if it was provided? Seems like instead we need to detect if a time was provided or not some other way.

bkosborne avatar Oct 26 '20 00:10 bkosborne

Okay, I submitted my own PR that fixes this by checking if the date field is configured as a date-only or datetime field: https://github.com/jhedstrom/DrupalDriver/pull/229

bkosborne avatar Oct 26 '20 13:10 bkosborne

#229 doesn't work, the scenario described above failed with the date in behat printed 1 day behind. I improved the old one, conflicts resolved https://github.com/jhedstrom/DrupalDriver/pull/235

drishu avatar May 10 '21 07:05 drishu

Just tested #235 and it is working fine for me now! Thanks for the effort.

BramDriesen avatar Nov 10 '21 15:11 BramDriesen