WordPress.org

Make WordPress Core

Changeset 38871


Ignore:
Timestamp:
10/23/2016 07:18:21 AM (3 years ago)
Author:
swissspidy
Message:

Date/Time: Fix unit tests after [38804].

The tests for date_i18n() need to use a delta for comparing timestamps.

Fixes #38381. See #37910.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/date/dateI18n.php

    r38804 r38871  
    77class Tests_Date_I18n extends WP_UnitTestCase {
    88    public function test_should_format_date() {
    9         $expected = date( 'Y-m-d H:i:s' );
    10         $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s' ) );
     9        $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 );
    1110    }
    1211
    1312    public function test_should_use_custom_timestamp() {
    14         $expected = '2012-12-01 00:00:00';
    15 
    16         $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ) ) );
     13        $this->assertEquals( '2012-12-01 00:00:00', date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ) ) );
    1714    }
    1815
    1916    public function test_date_should_be_in_gmt() {
    20         $expected = date( 'Y-m-d H:i:s' );
    21 
    22         $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', false, true ) );
     17        $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 );
    2318    }
    2419
    2520    public function test_custom_timestamp_ignores_gmt_setting() {
    26         $expected = '2012-12-01 00:00:00';
    27 
    28         $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ), false ) );
     21        $this->assertEquals( '2012-12-01 00:00:00', date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ) ) );
    2922    }
    3023
    3124    public function test_custom_timezone_setting() {
    32         update_option( 'timezone_string', 'Europe/London' );
    33         $expected = date( 'Y-m-d H:i:s', strtotime( date( 'Y-m-d H:i:s' ) ) + HOUR_IN_SECONDS );
     25        update_option( 'timezone_string', 'Europe/Zurich' );
    3426
    35         $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s' ) );
     27        $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 );
    3628    }
    3729
    3830    public function test_date_should_be_in_gmt_with_custom_timezone_setting() {
    39         update_option( 'timezone_string', 'Europe/London' );
    40         $expected = date( 'Y-m-d H:i:s' );
     31        update_option( 'timezone_string', 'Europe/Zurich' );
    4132
    42         $this->assertNotEquals( date_i18n( 'Y-m-d H:i:s', false, false ), date_i18n( 'Y-m-d H:i:s', false, true ) );
    43         $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', false, true ) );
     33        $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 );
    4434    }
    4535
    4636    public function test_date_should_be_in_gmt_with_custom_timezone_setting_and_timestamp() {
    47         update_option( 'timezone_string', 'Europe/London' );
     37        update_option( 'timezone_string', 'Europe/Zurich' );
    4838
    49         $expected = '2012-12-01 00:00:00';
    50 
    51         $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ), false ) );
    52         $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ), true ) );
     39        $this->assertEquals( '2012-12-01 00:00:00', date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ) ) );
    5340    }
    5441
     
    6855
    6956        $expected = 'Saturday_Translated (Sat_Translated) 01 December_Translated (Dec_Translated) 00:00:00 am_Translated AM_Translated';
    70         $actual = date_i18n( 'l (D) d F (M) H:i:s a A', strtotime( '2012-12-01 00:00:00' ), false );
     57        $actual = date_i18n( 'l (D) d F (M) H:i:s a A', strtotime( '2012-12-01 00:00:00' ) );
    7158
    7259        // Restore original locale.
     
    7966        update_option( 'timezone_string', 'Europe/Zurich' );
    8067
    81         $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 ) );
     68        $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' ) ) );
    8269    }
    8370}
Note: See TracChangeset for help on using the changeset viewer.