The title is only a placeholder until we discover more about the exact problem.
In #2490574: Validate that the publication date is in the future after adding the constraint to prevent past dates, I discovered a problem at comment 22 in helpTestScheduler where a date in the past was preventing a node being created, when the test code was intending to set a date in the future. However, when viewing the formatted date actually passed to the function it was in the future.
Looking at the generated page when attempting to save the new node, the example date beneath the input field was a time 11 hours in advance of my server time. I recall reading somewhere that drupal now uses a default timezone in Australia to make a big hourly difference with GMT. I think has got to be related to it.
I will get some screen grabs to more fully show this, and also search out where I read about the default timezone setting.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 2630836-4-default_timezone_vs_users_timezone.patch | 856 bytes | jonathan1055 |
| #2 | SchedulerTempWork.php_.txt | 3.89 KB | jonathan1055 |
Comments
Comment #2
jonathan1055 commentedI've made some progress on this. I created a new working test file to try out all the combinations and to discover what was causing the problem. In summary I found that:
strToTime(-1 day)compared totime()-60*60*24helpTestSchedulerthen the dates are all correcthelpTestSchedulerthe formatted date for-1 dayis 13 hours back from current time instead of 24helpTestSchedulerand removing chunks of code, it is only whendrupalLoginis called that the problem arisesdrupalLogoutdoes not revert the date to the expect value. It seems we remain in the GMT+11 timezoneI have attached my working file, in case it helps anyone who wants to try this. Just save it to your /src/tests folder, i.e. the same location as the other test files, and remove the _.txt extension. Then it should be selectable from your /admin/config/development/testing page. Note that I am running in GMT, my local machine and webserver is set to GMT and my admin user is GMT. But running the interactive tests in other user timezones should still show the problem.
Comment #3
jonathan1055 commentedAfter doing some more testing I can now see what is going on, and it's going to be a simple fix in the test code. The key to making the test scenarios match a real user is in ensuring that the adminUser is logged in when anything is done in the tests which mimic a real user. The problem we had was that the input date and time values were created before the adminUser was logged in, and thus they were formatted using the standard GMT/UTC timezone. But when the constraints were evaluated, as part of form submission, the user was logged in, so the formatted date and time was in the past according to if that value had been typed in by the user.
The simple fix is to put the drupalLogin() before creating the test date and time values. Then they will be consistent with the values being tested during evaluation of the constraints. Just like if a real user was doing it.
This sounds obvious now when explained like this, but I'm very happy to have solved it, as it was blocking progress on a couple of other constraint tests. I'll make a patch and add it here.
Comment #4
jonathan1055 commentedPatch for /src/Tests/SchedulerFunctionalTest.php
This should run, but will produce the same number of passes and fails. I will then commit to the test branch and main branch, then re-queue the patch in #2490574: Validate that the publication date is in the future
Comment #6
jonathan1055 commentedThe commits for this patch are in #2594615: Automated testing in 8.x [meta] in comment #92.
The test results in #2490574: Validate that the publication date is in the future show that when the constraint is added we no longer get the failure
Hence marking this issue fixed!