From 4a65ecc64a6e48a94ae6365f45aa12102dc96f29 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 23 Oct 2016 07:18:21 +0000 Subject: [PATCH] Date/Time: Fix unit tests after [38804]. The tests for `date_i18n()` need to use a delta for comparing timestamps. Fixes #38381. See #37910. git-svn-id: https://develop.svn.wordpress.org/trunk@38871 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/date/dateI18n.php | 37 +++++++++------------------ 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/tests/phpunit/tests/date/dateI18n.php b/tests/phpunit/tests/date/dateI18n.php index 109e4d34d3..e616f43bf2 100644 --- a/tests/phpunit/tests/date/dateI18n.php +++ b/tests/phpunit/tests/date/dateI18n.php @@ -6,50 +6,37 @@ */ class Tests_Date_I18n extends WP_UnitTestCase { public function test_should_format_date() { - $expected = date( 'Y-m-d H:i:s' ); - $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s' ) ); + $this->assertEquals( strtotime( date( 'Y-m-d H:i:s' ) ), strtotime( date_i18n( 'Y-m-d H:i:s' ) ), 'The dates should be equal', 2 ); } public function test_should_use_custom_timestamp() { - $expected = '2012-12-01 00:00:00'; - - $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ) ) ); + $this->assertEquals( '2012-12-01 00:00:00', date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ) ) ); } public function test_date_should_be_in_gmt() { - $expected = date( 'Y-m-d H:i:s' ); - - $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', false, true ) ); + $this->assertEquals( strtotime( date( 'Y-m-d H:i:s' ) ), strtotime( date_i18n( 'Y-m-d H:i:s', false, true ) ), 'The dates should be equal', 2 ); } public function test_custom_timestamp_ignores_gmt_setting() { - $expected = '2012-12-01 00:00:00'; - - $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ), false ) ); + $this->assertEquals( '2012-12-01 00:00:00', date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ) ) ); } public function test_custom_timezone_setting() { - update_option( 'timezone_string', 'Europe/London' ); - $expected = date( 'Y-m-d H:i:s', strtotime( date( 'Y-m-d H:i:s' ) ) + HOUR_IN_SECONDS ); + update_option( 'timezone_string', 'Europe/Zurich' ); - $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s' ) ); + $this->assertEquals( strtotime( date( 'Y-m-d H:i:s', time() + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ), strtotime( date_i18n( 'Y-m-d H:i:s' ) ), 'The dates should be equal', 2 ); } public function test_date_should_be_in_gmt_with_custom_timezone_setting() { - update_option( 'timezone_string', 'Europe/London' ); - $expected = date( 'Y-m-d H:i:s' ); + update_option( 'timezone_string', 'Europe/Zurich' ); - $this->assertNotEquals( date_i18n( 'Y-m-d H:i:s', false, false ), date_i18n( 'Y-m-d H:i:s', false, true ) ); - $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', false, true ) ); + $this->assertEquals( strtotime( date( 'Y-m-d H:i:s' ) ), strtotime( date_i18n( 'Y-m-d H:i:s', false, true ) ), 'The dates should be equal', 2 ); } public function test_date_should_be_in_gmt_with_custom_timezone_setting_and_timestamp() { - update_option( 'timezone_string', 'Europe/London' ); + update_option( 'timezone_string', 'Europe/Zurich' ); - $expected = '2012-12-01 00:00:00'; - - $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ), false ) ); - $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ), true ) ); + $this->assertEquals( '2012-12-01 00:00:00', date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ) ) ); } public function test_adjusts_format_based_on_locale() { @@ -67,7 +54,7 @@ class Tests_Date_I18n extends WP_UnitTestCase { $GLOBALS['wp_locale'] = $locale; $expected = 'Saturday_Translated (Sat_Translated) 01 December_Translated (Dec_Translated) 00:00:00 am_Translated AM_Translated'; - $actual = date_i18n( 'l (D) d F (M) H:i:s a A', strtotime( '2012-12-01 00:00:00' ), false ); + $actual = date_i18n( 'l (D) d F (M) H:i:s a A', strtotime( '2012-12-01 00:00:00' ) ); // Restore original locale. $GLOBALS['wp_locale'] = $original_locale; @@ -78,6 +65,6 @@ class Tests_Date_I18n extends WP_UnitTestCase { public function test_adjusts_format_based_on_timezone_string() { update_option( 'timezone_string', 'Europe/Zurich' ); - $this->assertEquals( '2012-12-01 00:00:00 CEST +02:00 Europe/Zurich', date_i18n( 'Y-m-d H:i:s T P e', strtotime( '2012-12-01 00:00:00' ), false ) ); + $this->assertEquals( '2012-12-01 00:00:00 CEST +02:00 Europe/Zurich', date_i18n( 'Y-m-d H:i:s T P e', strtotime( '2012-12-01 00:00:00' ) ) ); } }