From 8127aaed053941661a1073fa8371303048748bf6 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 19 Sep 2022 21:18:59 +0000 Subject: [PATCH] Tests: Replace the timezone used in date/time tests. The `Europe/Kiev` timezone has been deprecated in PHP 8.2 and replaced with `Europe/Kyiv`. The tests updated in this commit are testing the WordPress date/time functionality. They are **not** testing whether WP or PHP can handle deprecated timezone names correctly. To ensure the tests follow the original purpose, the use of `Europe/Kiev` within these tests is now replaced with the `Europe/Helsinki` timezone, which is within the same timezone as `Europe/Kyiv`. This should ensure that these tests run without issue and test what they are supposed to be testing on every supported PHP version (unless at some point in the future `Europe/Helsinki` would be renamed, but that's a bridge to cross if and when). Note: Separate tests should/will be added to ensure that relevant date/time related functions handle a deprecated timezone correctly, but that is not something ''these'' tests are supposed to be testing. Follow-up to [45853], [45856], [45876], [45882], [45887], [45908], [45914], [46577], [46154], [46580], [46864], [46974], [54207]. Props jrf, costdev. See #56468. git-svn-id: https://develop.svn.wordpress.org/trunk@54217 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/date/currentTime.php | 4 ++-- tests/phpunit/tests/date/dateI18n.php | 14 +++++++------- tests/phpunit/tests/date/getFeedBuildDate.php | 2 +- tests/phpunit/tests/date/getPostTime.php | 6 +++--- tests/phpunit/tests/date/mysql2date.php | 8 ++++---- tests/phpunit/tests/date/query.php | 4 ++-- tests/phpunit/tests/date/wpTimezone.php | 6 +++--- tests/phpunit/tests/date/xmlrpc.php | 6 +++--- tests/phpunit/tests/formatting/date.php | 2 +- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/phpunit/tests/date/currentTime.php b/tests/phpunit/tests/date/currentTime.php index 72d50abfba..0c4ff698d1 100644 --- a/tests/phpunit/tests/date/currentTime.php +++ b/tests/phpunit/tests/date/currentTime.php @@ -92,7 +92,7 @@ class Tests_Date_CurrentTime extends WP_UnitTestCase { * @ticket 40653 */ public function test_should_return_wp_timestamp() { - update_option( 'timezone_string', 'Europe/Kiev' ); + update_option( 'timezone_string', 'Europe/Helsinki' ); $timestamp = time(); $datetime = new DateTime( '@' . $timestamp ); @@ -117,7 +117,7 @@ class Tests_Date_CurrentTime extends WP_UnitTestCase { * @ticket 40653 */ public function test_should_return_correct_local_time() { - update_option( 'timezone_string', 'Europe/Kiev' ); + update_option( 'timezone_string', 'Europe/Helsinki' ); $timestamp = time(); $datetime_local = new DateTime( '@' . $timestamp ); diff --git a/tests/phpunit/tests/date/dateI18n.php b/tests/phpunit/tests/date/dateI18n.php index 5bd340b91d..b52f43e0e2 100644 --- a/tests/phpunit/tests/date/dateI18n.php +++ b/tests/phpunit/tests/date/dateI18n.php @@ -22,7 +22,7 @@ class Tests_Date_DateI18n extends WP_UnitTestCase { * @ticket 28636 */ public function test_should_return_current_time_on_invalid_timestamp() { - $timezone = 'Europe/Kiev'; + $timezone = 'Europe/Helsinki'; update_option( 'timezone_string', $timezone ); $datetime = new DateTime( 'now', new DateTimeZone( $timezone ) ); @@ -35,7 +35,7 @@ class Tests_Date_DateI18n extends WP_UnitTestCase { * @ticket 28636 */ public function test_should_handle_zero_timestamp() { - $timezone = 'Europe/Kiev'; + $timezone = 'Europe/Helsinki'; update_option( 'timezone_string', $timezone ); $datetime = DateTimeImmutable::createFromFormat( @@ -154,7 +154,7 @@ class Tests_Date_DateI18n extends WP_UnitTestCase { * @ticket 25768 */ public function test_should_return_wp_timestamp() { - update_option( 'timezone_string', 'Europe/Kiev' ); + update_option( 'timezone_string', 'Europe/Helsinki' ); $datetime = new DateTimeImmutable( 'now', wp_timezone() ); $timestamp = $datetime->getTimestamp(); @@ -204,10 +204,10 @@ class Tests_Date_DateI18n extends WP_UnitTestCase { public function dst_times() { return array( - 'Before DST start' => array( '2019-03-31 02:59:00', 'Europe/Kiev' ), - 'After DST start' => array( '2019-03-31 04:01:00', 'Europe/Kiev' ), - 'Before DST end' => array( '2019-10-27 02:59:00', 'Europe/Kiev' ), - 'After DST end' => array( '2019-10-27 04:01:00', 'Europe/Kiev' ), + 'Before DST start' => array( '2019-03-31 02:59:00', 'Europe/Helsinki' ), + 'After DST start' => array( '2019-03-31 04:01:00', 'Europe/Helsinki' ), + 'Before DST end' => array( '2019-10-27 02:59:00', 'Europe/Helsinki' ), + 'After DST end' => array( '2019-10-27 04:01:00', 'Europe/Helsinki' ), ); } } diff --git a/tests/phpunit/tests/date/getFeedBuildDate.php b/tests/phpunit/tests/date/getFeedBuildDate.php index 5f0416ce53..39cfd988d1 100644 --- a/tests/phpunit/tests/date/getFeedBuildDate.php +++ b/tests/phpunit/tests/date/getFeedBuildDate.php @@ -47,7 +47,7 @@ class Tests_Date_GetFeedBuildDate extends WP_UnitTestCase { public function test_should_fall_back_to_last_post_modified() { global $wp_query; - update_option( 'timezone_string', 'Europe/Kiev' ); + update_option( 'timezone_string', 'Europe/Helsinki' ); $datetime = new DateTimeImmutable( 'now', wp_timezone() ); $datetime_utc = $datetime->setTimezone( new DateTimeZone( 'UTC' ) ); diff --git a/tests/phpunit/tests/date/getPostTime.php b/tests/phpunit/tests/date/getPostTime.php index 21b9c8675b..441e886210 100644 --- a/tests/phpunit/tests/date/getPostTime.php +++ b/tests/phpunit/tests/date/getPostTime.php @@ -61,7 +61,7 @@ class Tests_Date_GetPostTime extends WP_UnitTestCase { * @ticket 25002 */ public function test_should_return_wp_timestamp() { - $timezone = 'Europe/Kiev'; + $timezone = 'Europe/Helsinki'; update_option( 'timezone_string', $timezone ); $datetime = new DateTimeImmutable( 'now', new DateTimeZone( $timezone ) ); @@ -90,7 +90,7 @@ class Tests_Date_GetPostTime extends WP_UnitTestCase { * @ticket 25002 */ public function test_should_return_time() { - $timezone = 'Europe/Kiev'; + $timezone = 'Europe/Helsinki'; update_option( 'timezone_string', $timezone ); $datetime = new DateTimeImmutable( 'now', new DateTimeZone( $timezone ) ); @@ -131,7 +131,7 @@ class Tests_Date_GetPostTime extends WP_UnitTestCase { ) ); - update_option( 'timezone_string', 'Europe/Kiev' ); + update_option( 'timezone_string', 'Europe/Helsinki' ); $this->assertSame( $rfc3339, get_post_time( DATE_RFC3339, true, $post_id ) ); $this->assertSame( $rfc3339, get_post_modified_time( DATE_RFC3339, true, $post_id ) ); diff --git a/tests/phpunit/tests/date/mysql2date.php b/tests/phpunit/tests/date/mysql2date.php index b53a57cfac..e8418467c7 100644 --- a/tests/phpunit/tests/date/mysql2date.php +++ b/tests/phpunit/tests/date/mysql2date.php @@ -36,7 +36,7 @@ class Tests_Date_mysql2date extends WP_UnitTestCase { * @ticket 28992 */ public function test_mysql2date_should_format_time() { - $timezone = 'Europe/Kiev'; + $timezone = 'Europe/Helsinki'; update_option( 'timezone_string', $timezone ); $datetime = new DateTime( 'now', new DateTimeZone( $timezone ) ); $rfc3339 = $datetime->format( DATE_RFC3339 ); @@ -50,7 +50,7 @@ class Tests_Date_mysql2date extends WP_UnitTestCase { * @ticket 28992 */ public function test_mysql2date_should_format_time_with_changed_time_zone() { - $timezone = 'Europe/Kiev'; + $timezone = 'Europe/Helsinki'; // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set date_default_timezone_set( $timezone ); update_option( 'timezone_string', $timezone ); @@ -66,7 +66,7 @@ class Tests_Date_mysql2date extends WP_UnitTestCase { * @ticket 28992 */ public function test_mysql2date_should_return_wp_timestamp() { - $timezone = 'Europe/Kiev'; + $timezone = 'Europe/Helsinki'; update_option( 'timezone_string', $timezone ); $datetime = new DateTime( 'now', new DateTimeZone( $timezone ) ); $wp_timestamp = $datetime->getTimestamp() + $datetime->getOffset(); @@ -80,7 +80,7 @@ class Tests_Date_mysql2date extends WP_UnitTestCase { * @ticket 28992 */ public function test_mysql2date_should_return_unix_timestamp_for_gmt_time() { - $timezone = 'Europe/Kiev'; + $timezone = 'Europe/Helsinki'; update_option( 'timezone_string', $timezone ); $datetime = new DateTime( 'now', new DateTimeZone( 'UTC' ) ); $timestamp = $datetime->getTimestamp(); diff --git a/tests/phpunit/tests/date/query.php b/tests/phpunit/tests/date/query.php index 7e3cd73392..a432675f94 100644 --- a/tests/phpunit/tests/date/query.php +++ b/tests/phpunit/tests/date/query.php @@ -571,7 +571,7 @@ class Tests_Date_Query extends WP_UnitTestCase { * @param bool $default_to_max Flag to default missing values to max. */ public function test_build_mysql_datetime_with_custom_timezone( $datetime, $expected, $default_to_max = false ) { - update_option( 'timezone_string', 'Europe/Kiev' ); + update_option( 'timezone_string', 'Europe/Helsinki' ); $q = new WP_Date_Query( array() ); @@ -593,7 +593,7 @@ class Tests_Date_Query extends WP_UnitTestCase { * @ticket 41782 */ public function test_build_mysql_datetime_with_relative_date() { - update_option( 'timezone_string', 'Europe/Kiev' ); + update_option( 'timezone_string', 'Europe/Helsinki' ); $q = new WP_Date_Query( array() ); diff --git a/tests/phpunit/tests/date/wpTimezone.php b/tests/phpunit/tests/date/wpTimezone.php index 3b60462163..e48a1b03b5 100644 --- a/tests/phpunit/tests/date/wpTimezone.php +++ b/tests/phpunit/tests/date/wpTimezone.php @@ -42,13 +42,13 @@ class Tests_Date_wpTimezone extends WP_UnitTestCase { * @ticket 24730 */ public function test_should_return_timezone_string() { - update_option( 'timezone_string', 'Europe/Kiev' ); + update_option( 'timezone_string', 'Europe/Helsinki' ); - $this->assertSame( 'Europe/Kiev', wp_timezone_string() ); + $this->assertSame( 'Europe/Helsinki', wp_timezone_string() ); $timezone = wp_timezone(); - $this->assertSame( 'Europe/Kiev', $timezone->getName() ); + $this->assertSame( 'Europe/Helsinki', $timezone->getName() ); } /** diff --git a/tests/phpunit/tests/date/xmlrpc.php b/tests/phpunit/tests/date/xmlrpc.php index 26285aa403..3258909cfb 100644 --- a/tests/phpunit/tests/date/xmlrpc.php +++ b/tests/phpunit/tests/date/xmlrpc.php @@ -34,7 +34,7 @@ class Tests_Date_XMLRPC extends WP_XMLRPC_UnitTestCase { $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' ); } - $timezone = 'Europe/Kiev'; + $timezone = 'Europe/Helsinki'; update_option( 'timezone_string', $timezone ); $datetime = new DateTimeImmutable( 'now', new DateTimeZone( $timezone ) ); @@ -154,7 +154,7 @@ class Tests_Date_XMLRPC extends WP_XMLRPC_UnitTestCase { * @covers wp_xmlrpc_server::mw_editPost */ public function test_date_edit_post() { - $timezone = 'Europe/Kiev'; + $timezone = 'Europe/Helsinki'; update_option( 'timezone_string', $timezone ); $datetime = new DateTimeImmutable( 'now', new DateTimeZone( $timezone ) ); @@ -223,7 +223,7 @@ class Tests_Date_XMLRPC extends WP_XMLRPC_UnitTestCase { * @covers wp_xmlrpc_server::wp_editComment */ public function test_date_edit_comment() { - $timezone = 'Europe/Kiev'; + $timezone = 'Europe/Helsinki'; update_option( 'timezone_string', $timezone ); $datetime = new DateTimeImmutable( 'now', new DateTimeZone( $timezone ) ); diff --git a/tests/phpunit/tests/formatting/date.php b/tests/phpunit/tests/formatting/date.php index c08a94710c..d3e0971789 100644 --- a/tests/phpunit/tests/formatting/date.php +++ b/tests/phpunit/tests/formatting/date.php @@ -233,7 +233,7 @@ class Tests_Formatting_Date extends WP_UnitTestCase { public function timezone_provider() { return array( array( - 'timezone_string' => 'Europe/Kiev', + 'timezone_string' => 'Europe/Helsinki', 'gmt_offset' => 3, ), array(