diff --git tests/phpunit/tests/date/dateI18n.php tests/phpunit/tests/date/dateI18n.php
index 109e4d3..e616f43 100644
|
|
|
6 | 6 | */ |
7 | 7 | class Tests_Date_I18n extends WP_UnitTestCase { |
8 | 8 | 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 ); |
11 | 10 | } |
12 | 11 | |
13 | 12 | 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' ) ) ); |
17 | 14 | } |
18 | 15 | |
19 | 16 | 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 ); |
23 | 18 | } |
24 | 19 | |
25 | 20 | 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' ) ) ); |
29 | 22 | } |
30 | 23 | |
31 | 24 | 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' ); |
34 | 26 | |
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 ); |
36 | 28 | } |
37 | 29 | |
38 | 30 | 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' ); |
41 | 32 | |
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 ); |
44 | 34 | } |
45 | 35 | |
46 | 36 | public function test_date_should_be_in_gmt_with_custom_timezone_setting_and_timestamp() { |
47 | | update_option( 'timezone_string', 'Europe/London' ); |
48 | | |
49 | | $expected = '2012-12-01 00:00:00'; |
| 37 | update_option( 'timezone_string', 'Europe/Zurich' ); |
50 | 38 | |
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' ) ) ); |
53 | 40 | } |
54 | 41 | |
55 | 42 | public function test_adjusts_format_based_on_locale() { |
… |
… |
class Tests_Date_I18n extends WP_UnitTestCase { |
67 | 54 | $GLOBALS['wp_locale'] = $locale; |
68 | 55 | |
69 | 56 | $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' ) ); |
71 | 58 | |
72 | 59 | // Restore original locale. |
73 | 60 | $GLOBALS['wp_locale'] = $original_locale; |
… |
… |
class Tests_Date_I18n extends WP_UnitTestCase { |
78 | 65 | public function test_adjusts_format_based_on_timezone_string() { |
79 | 66 | update_option( 'timezone_string', 'Europe/Zurich' ); |
80 | 67 | |
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' ) ) ); |
82 | 69 | } |
83 | 70 | } |