Problem/Motivation

#2497585: Simpletest should set a system timezone in setUp tried to make time zone default to non-UTC but it only does so after install. The result is that the admin user and therefore possibly also other users still being created with timezone UTC in his account.

Since user configurable timezones are enabled by default, logging in as that user or another one switches the timezone back to UTC. And then back when you log out and so on.

I don't know why this isn't visible in core tests, we have problems in #2604784: Add a test to check the date output for example, where we are trying to assert a formatted timestamp, created as anonymous user, viewed as a logged in user.

Proposed resolution

Explicitly call date_default_timezone_set('Australia/Sydney'); as the very first thing in setUp(), so that the timezone is consistent while the installer runs.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Berdir created an issue. See original summary.

berdir’s picture

Title: Inconsistent time zones in simpletest » Inconsistent time zones in web tests
Status: Active » Needs review
StatusFileSize
new934 bytes

Status: Needs review » Needs work

The last submitted patch, 2: web-test-timezone-2611082-2.patch, failed testing.

dawehner’s picture

We should ensure that we keep this behaviour with an additional test IMHO.

edurenye’s picture

I think this is failing because the drupalCreateNode, doesn't set a creation date, so it uses by default REQUEST_TIME, and it uses $_SERVER['REQUEST_TIME'], so doesn't use the time zone that we set in the test.

mpdonadio’s picture

Issue tags: +Needs tests

Yeah, this definitely needs a test to prevent a regression. I can try to work on the fails and a test tonight.

mpdonadio’s picture

Assigned: Unassigned » mpdonadio

Working on this now.

mpdonadio’s picture

Assigned: mpdonadio » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.16 KB
new3.59 KB
new2.91 KB

Pretty sure the change to NodeAttributesTest is correct, regardless of this (RDFa always uses UTC).

Still really confused what is happening here, especially having to explicitly add the timezone to the root user in the test and the fact that more things aren't failing if the assessment in the IS is really what is happening.

Added a test. Not sure it is really correct, so I left the tag. May want to expand it, too, to test the anonymous user?

Should UserSession set the timezone to the PHP default if it isn't provided?

The last submitted patch, 8: 2611082-test-only.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 8: 2611082-08.patch, failed testing.

berdir’s picture

Note that there's also #2510150: AccountProxy is not calling date_set_default_timezone() for anonymous users. So I'd expect that anonymous user is actually not working yet, this might also be the cause for some errors here.

I think the reason we don't have that many test fails is that usually, comparisons happen while logged in. And then it's consistently in UTC. Our monitoring test however triggers a log message as the anonymous user but was views as an authenticated user on the site.

We could try to merge the fix of that in here if it helps fixing tests. If not, I'd say we leave out explicit anonymous tests here and then add them there.

berdir’s picture

+++ b/core/modules/simpletest/src/Tests/TimeZoneTest.php
@@ -0,0 +1,42 @@
+  function testAccountTimeZones() {
+    $expected = 'Australia/Sydney';
+    $this->assertEqual($this->rootUser->getTimeZone(), $expected, 'Root user has correct time zone.');
+    $this->assertEqual($this->adminUser->getTimeZone(), $expected, 'Admin user has correct time zone.');
+  }

Should we also request a page as an authenticated user that prints the timezone, to compare that?

mpdonadio’s picture

I do think #2510150: AccountProxy is not calling date_set_default_timezone() for anonymous users may be blocking this, at least from getting a handle on what the real failures are.

Good idea for another test. Make a node. Set it to render the created date with a custom timestamp 'e' on the default display. Get the page logged in and logged out. Make sure are both the one we set.

Also kinda thinking that we should add

WebTestBase::DEFAULT_TIMEZONE = 'Australia/Sydney';

so we aren't passing the literals around.

tduong’s picture

Status: Needs work » Closed (duplicate)
Issue tags: -rc eligible, -Needs tests
Parent issue: » #2510150: AccountProxy is not calling date_set_default_timezone() for anonymous users

As said in #2510150: AccountProxy is not calling date_set_default_timezone() for anonymous users #26, I close this issue as we will now solve the bug there.