From c73c0916dd25cf442ae4054a13bd0c3e931cf16f Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 19 Sep 2022 17:43:55 +0000 Subject: [PATCH] Tests: Reset timezone-related options if the tests change them. The `options` table is not explicitly reset after each test or test class, so if an option is changed during a test, it should be reset to the default value ''after'' the test. This commit does so for those tests which did not have such resetting in place yet, while one or more tests in the class ''do'' change the value of the `timezone_string` option. Note: The test suite executes a `ROLLBACK` query after each test, which should reset the `options` table in theory, however that appears to not always be enough, as some timezone-related tests can fail in a complete test suite run, while not failing when run in isolation. This commit aims to improve stability of the tests. Follow-up to [45857] / #45821. Props jrf, costdev. See #56468. git-svn-id: https://develop.svn.wordpress.org/trunk@54207 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/date/currentTime.php | 11 +++++++++++ tests/phpunit/tests/date/dateI18n.php | 11 +++++++++++ tests/phpunit/tests/date/getFeedBuildDate.php | 2 +- tests/phpunit/tests/date/getPermalink.php | 2 +- tests/phpunit/tests/date/getPostTime.php | 10 ++++++++++ tests/phpunit/tests/date/mysql2date.php | 3 +++ tests/phpunit/tests/date/query.php | 10 ++++++++++ tests/phpunit/tests/date/wpTimezone.php | 11 +++++++++++ tests/phpunit/tests/date/xmlrpc.php | 10 ++++++++++ tests/phpunit/tests/formatting/date.php | 11 +++++++++++ 10 files changed, 79 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/date/currentTime.php b/tests/phpunit/tests/date/currentTime.php index c98292ef0d..72d50abfba 100644 --- a/tests/phpunit/tests/date/currentTime.php +++ b/tests/phpunit/tests/date/currentTime.php @@ -7,6 +7,17 @@ */ class Tests_Date_CurrentTime extends WP_UnitTestCase { + /** + * Cleans up. + */ + public function tear_down() { + // Reset changed options to their default value. + update_option( 'gmt_offset', 0 ); + update_option( 'timezone_string', '' ); + + parent::tear_down(); + } + /** * @ticket 34378 */ diff --git a/tests/phpunit/tests/date/dateI18n.php b/tests/phpunit/tests/date/dateI18n.php index 9279aca4eb..5bd340b91d 100644 --- a/tests/phpunit/tests/date/dateI18n.php +++ b/tests/phpunit/tests/date/dateI18n.php @@ -7,6 +7,17 @@ */ class Tests_Date_DateI18n extends WP_UnitTestCase { + /** + * Cleans up. + */ + public function tear_down() { + // Reset changed options to their default value. + update_option( 'gmt_offset', 0 ); + update_option( 'timezone_string', '' ); + + parent::tear_down(); + } + /** * @ticket 28636 */ diff --git a/tests/phpunit/tests/date/getFeedBuildDate.php b/tests/phpunit/tests/date/getFeedBuildDate.php index c1d9edb66c..5f0416ce53 100644 --- a/tests/phpunit/tests/date/getFeedBuildDate.php +++ b/tests/phpunit/tests/date/getFeedBuildDate.php @@ -11,7 +11,7 @@ class Tests_Date_GetFeedBuildDate extends WP_UnitTestCase { public function tear_down() { global $wp_query; - update_option( 'timezone_string', 'UTC' ); + update_option( 'timezone_string', '' ); unset( $wp_query ); diff --git a/tests/phpunit/tests/date/getPermalink.php b/tests/phpunit/tests/date/getPermalink.php index 41977c7734..195717dbd8 100644 --- a/tests/phpunit/tests/date/getPermalink.php +++ b/tests/phpunit/tests/date/getPermalink.php @@ -10,7 +10,7 @@ class Tests_Date_GetPermalink extends WP_UnitTestCase { public function tear_down() { delete_option( 'permalink_structure' ); - update_option( 'timezone_string', 'UTC' ); + update_option( 'timezone_string', '' ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set date_default_timezone_set( 'UTC' ); diff --git a/tests/phpunit/tests/date/getPostTime.php b/tests/phpunit/tests/date/getPostTime.php index ad9eb0cf31..21b9c8675b 100644 --- a/tests/phpunit/tests/date/getPostTime.php +++ b/tests/phpunit/tests/date/getPostTime.php @@ -9,6 +9,16 @@ */ class Tests_Date_GetPostTime extends WP_UnitTestCase { + /** + * Cleans up. + */ + public function tear_down() { + // Reset the timezone option to the default value. + update_option( 'timezone_string', '' ); + + parent::tear_down(); + } + /** * @ticket 28310 */ diff --git a/tests/phpunit/tests/date/mysql2date.php b/tests/phpunit/tests/date/mysql2date.php index 7c83446b00..b53a57cfac 100644 --- a/tests/phpunit/tests/date/mysql2date.php +++ b/tests/phpunit/tests/date/mysql2date.php @@ -11,6 +11,9 @@ class Tests_Date_mysql2date extends WP_UnitTestCase { // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set date_default_timezone_set( 'UTC' ); + // Reset the timezone option to the default value. + update_option( 'timezone_string', '' ); + parent::tear_down(); } diff --git a/tests/phpunit/tests/date/query.php b/tests/phpunit/tests/date/query.php index e3f4ba0f6f..7e3cd73392 100644 --- a/tests/phpunit/tests/date/query.php +++ b/tests/phpunit/tests/date/query.php @@ -21,6 +21,16 @@ class Tests_Date_Query extends WP_UnitTestCase { $this->q = new WP_Date_Query( array( 'm' => 2 ) ); } + /** + * Cleans up. + */ + public function tear_down() { + // Reset the timezone option to the default value. + update_option( 'timezone_string', '' ); + + parent::tear_down(); + } + public function test_construct_date_query_empty() { $q = new WP_Date_Query( array() ); $this->assertSame( 'AND', $q->relation ); diff --git a/tests/phpunit/tests/date/wpTimezone.php b/tests/phpunit/tests/date/wpTimezone.php index 8b1f09e4d1..3b60462163 100644 --- a/tests/phpunit/tests/date/wpTimezone.php +++ b/tests/phpunit/tests/date/wpTimezone.php @@ -8,6 +8,17 @@ */ class Tests_Date_wpTimezone extends WP_UnitTestCase { + /** + * Cleans up. + */ + public function tear_down() { + // Reset changed options to their default value. + update_option( 'gmt_offset', 0 ); + update_option( 'timezone_string', '' ); + + parent::tear_down(); + } + /** * @ticket 24730 * diff --git a/tests/phpunit/tests/date/xmlrpc.php b/tests/phpunit/tests/date/xmlrpc.php index 6344265e1f..26285aa403 100644 --- a/tests/phpunit/tests/date/xmlrpc.php +++ b/tests/phpunit/tests/date/xmlrpc.php @@ -8,6 +8,16 @@ */ class Tests_Date_XMLRPC extends WP_XMLRPC_UnitTestCase { + /** + * Cleans up. + */ + public function tear_down() { + // Reset the timezone option to the default value. + update_option( 'timezone_string', '' ); + + parent::tear_down(); + } + /** * @ticket 30429 * diff --git a/tests/phpunit/tests/formatting/date.php b/tests/phpunit/tests/formatting/date.php index 32e68d8f1a..c08a94710c 100644 --- a/tests/phpunit/tests/formatting/date.php +++ b/tests/phpunit/tests/formatting/date.php @@ -6,6 +6,17 @@ */ class Tests_Formatting_Date extends WP_UnitTestCase { + /** + * Cleans up. + */ + public function tear_down() { + // Reset changed options to their default value. + update_option( 'gmt_offset', 0 ); + update_option( 'timezone_string', '' ); + + parent::tear_down(); + } + /** * Unpatched, this test passes only when Europe/London is not observing DST. *