From d6a1abb9fd5f0f882304fa405237d90b80de0cba Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Fri, 14 Oct 2022 06:56:01 +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, SergeyBiryukov. Merges [54217] to the 5.8 branch. See #56468. git-svn-id: https://develop.svn.wordpress.org/branches/5.8@54514 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 | 12 ++++++------ tests/phpunit/tests/date/query.php | 4 ++-- tests/phpunit/tests/date/wpTimezone.php | 6 +++--- tests/phpunit/tests/date/xmlrpc.php | 8 ++++---- tests/phpunit/tests/formatting/date.php | 2 +- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/phpunit/tests/date/currentTime.php b/tests/phpunit/tests/date/currentTime.php index dd567701f9..fa05738b72 100644 --- a/tests/phpunit/tests/date/currentTime.php +++ b/tests/phpunit/tests/date/currentTime.php @@ -81,7 +81,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 ); @@ -106,7 +106,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 9279aca4eb..79598539cd 100644 --- a/tests/phpunit/tests/date/dateI18n.php +++ b/tests/phpunit/tests/date/dateI18n.php @@ -11,7 +11,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 ) ); @@ -24,7 +24,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( @@ -143,7 +143,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(); @@ -193,10 +193,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 325fcb423f..800e60118c 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 ad9eb0cf31..58cb4eb7fe 100644 --- a/tests/phpunit/tests/date/getPostTime.php +++ b/tests/phpunit/tests/date/getPostTime.php @@ -51,7 +51,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 ) ); @@ -80,7 +80,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 ) ); @@ -121,7 +121,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 ebed6300de..d90022d860 100644 --- a/tests/phpunit/tests/date/mysql2date.php +++ b/tests/phpunit/tests/date/mysql2date.php @@ -33,7 +33,7 @@ class Tests_Date_mysql2date extends WP_UnitTestCase { * @ticket 28992 */ 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 ); @@ -47,7 +47,7 @@ class Tests_Date_mysql2date extends WP_UnitTestCase { * @ticket 28992 */ 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 ); @@ -62,8 +62,8 @@ class Tests_Date_mysql2date extends WP_UnitTestCase { /** * @ticket 28992 */ - function test_mysql2date_should_return_wp_timestamp() { - $timezone = 'Europe/Kiev'; + public function test_mysql2date_should_return_wp_timestamp() { + $timezone = 'Europe/Helsinki'; update_option( 'timezone_string', $timezone ); $datetime = new DateTime( 'now', new DateTimeZone( $timezone ) ); $wp_timestamp = $datetime->getTimestamp() + $datetime->getOffset(); @@ -76,8 +76,8 @@ class Tests_Date_mysql2date extends WP_UnitTestCase { /** * @ticket 28992 */ - function test_mysql2date_should_return_unix_timestamp_for_gmt_time() { - $timezone = 'Europe/Kiev'; + public function test_mysql2date_should_return_unix_timestamp_for_gmt_time() { + $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 87cb8b7632..8ef6f8d241 100644 --- a/tests/phpunit/tests/date/query.php +++ b/tests/phpunit/tests/date/query.php @@ -561,7 +561,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() ); @@ -583,7 +583,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 8b1f09e4d1..fdd369917b 100644 --- a/tests/phpunit/tests/date/wpTimezone.php +++ b/tests/phpunit/tests/date/wpTimezone.php @@ -31,13 +31,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 6fe96618bc..015878856d 100644 --- a/tests/phpunit/tests/date/xmlrpc.php +++ b/tests/phpunit/tests/date/xmlrpc.php @@ -14,7 +14,7 @@ class Tests_Date_XMLRPC extends WP_XMLRPC_UnitTestCase { * @covers wp_xmlrpc_server::mw_newPost */ public function test_date_new_post() { - $timezone = 'Europe/Kiev'; + $timezone = 'Europe/Helsinki'; update_option( 'timezone_string', $timezone ); $datetime = new DateTimeImmutable( 'now', new DateTimeZone( $timezone ) ); @@ -134,7 +134,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 ) ); @@ -202,8 +202,8 @@ class Tests_Date_XMLRPC extends WP_XMLRPC_UnitTestCase { * * @covers wp_xmlrpc_server::wp_editComment */ - function test_date_edit_comment() { - $timezone = 'Europe/Kiev'; + public function test_date_edit_comment() { + $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 9b540929e0..c945ccc4de 100644 --- a/tests/phpunit/tests/formatting/date.php +++ b/tests/phpunit/tests/formatting/date.php @@ -197,7 +197,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(