| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * @group date |
| | 5 | * @group datetime |
| | 6 | */ |
| | 7 | class Tests_Wp_Timezone extends WP_UnitTestCase { |
| | 8 | |
| | 9 | /** |
| | 10 | * @dataProvider timezone_offset_provider |
| | 11 | * |
| | 12 | * @param float $gmt_offset Numeric offset from UTC. |
| | 13 | * @param string $tz_name Expected timezone name. |
| | 14 | */ |
| | 15 | public function test_should_convert_gmt_offset( $gmt_offset, $tz_name ) { |
| | 16 | |
| | 17 | delete_option( 'timezone_string' ); |
| | 18 | update_option( 'gmt_offset', $gmt_offset ); |
| | 19 | |
| | 20 | $this->assertEquals( $tz_name, wp_timezone_string() ); |
| | 21 | |
| | 22 | $timezone = wp_timezone(); |
| | 23 | |
| | 24 | $this->assertEquals( $tz_name, $timezone->getName() ); |
| | 25 | } |
| | 26 | |
| | 27 | public function test_should_return_timezone_string() { |
| | 28 | |
| | 29 | update_option( 'timezone_string', 'Europe/Kiev' ); |
| | 30 | |
| | 31 | $this->assertEquals( 'Europe/Kiev', wp_timezone_string() ); |
| | 32 | |
| | 33 | $timezone = wp_timezone(); |
| | 34 | |
| | 35 | $this->assertEquals( 'Europe/Kiev', $timezone->getName() ); |
| | 36 | } |
| | 37 | |
| | 38 | /** |
| | 39 | * Data provider to test numeric offset conversion. |
| | 40 | * |
| | 41 | * @return array |
| | 42 | */ |
| | 43 | public function timezone_offset_provider() { |
| | 44 | |
| | 45 | return [ |
| | 46 | [ - 12, '-12:00' ], |
| | 47 | [ - 11.5, '-11:30' ], |
| | 48 | [ - 11, '-11:00' ], |
| | 49 | [ - 10.5, '-10:30' ], |
| | 50 | [ - 10, '-10:00' ], |
| | 51 | [ - 9.5, '-09:30' ], |
| | 52 | [ - 9, '-09:00' ], |
| | 53 | [ - 8.5, '-08:30' ], |
| | 54 | [ - 8, '-08:00' ], |
| | 55 | [ - 7.5, '-07:30' ], |
| | 56 | [ - 7, '-07:00' ], |
| | 57 | [ - 6.5, '-06:30' ], |
| | 58 | [ - 6, '-06:00' ], |
| | 59 | [ - 5.5, '-05:30' ], |
| | 60 | [ - 5, '-05:00' ], |
| | 61 | [ - 4.5, '-04:30' ], |
| | 62 | [ - 4, '-04:00' ], |
| | 63 | [ - 3.5, '-03:30' ], |
| | 64 | [ - 3, '-03:00' ], |
| | 65 | [ - 2.5, '-02:30' ], |
| | 66 | [ - 2, '-02:00' ], |
| | 67 | [ '-1.5', '-01:30' ], |
| | 68 | [ - 1.5, '-01:30' ], |
| | 69 | [ - 1, '-01:00' ], |
| | 70 | [ - 0.5, '-00:30' ], |
| | 71 | [ 0, '+00:00' ], |
| | 72 | [ '0', '+00:00' ], |
| | 73 | [ 0.5, '+00:30' ], |
| | 74 | [ 1, '+01:00' ], |
| | 75 | [ 1.5, '+01:30' ], |
| | 76 | [ '1.5', '+01:30' ], |
| | 77 | [ 2, '+02:00' ], |
| | 78 | [ 2.5, '+02:30' ], |
| | 79 | [ 3, '+03:00' ], |
| | 80 | [ 3.5, '+03:30' ], |
| | 81 | [ 4, '+04:00' ], |
| | 82 | [ 4.5, '+04:30' ], |
| | 83 | [ 5, '+05:00' ], |
| | 84 | [ 5.5, '+05:30' ], |
| | 85 | [ 5.75, '+05:45' ], |
| | 86 | [ 6, '+06:00' ], |
| | 87 | [ 6.5, '+06:30' ], |
| | 88 | [ 7, '+07:00' ], |
| | 89 | [ 7.5, '+07:30' ], |
| | 90 | [ 8, '+08:00' ], |
| | 91 | [ 8.5, '+08:30' ], |
| | 92 | [ 8.75, '+08:45' ], |
| | 93 | [ 9, '+09:00' ], |
| | 94 | [ 9.5, '+09:30' ], |
| | 95 | [ 10, '+10:00' ], |
| | 96 | [ 10.5, '+10:30' ], |
| | 97 | [ 11, '+11:00' ], |
| | 98 | [ 11.5, '+11:30' ], |
| | 99 | [ 12, '+12:00' ], |
| | 100 | [ 12.75, '+12:45' ], |
| | 101 | [ 13, '+13:00' ], |
| | 102 | [ 13.75, '+13:45' ], |
| | 103 | [ 14, '+14:00' ], |
| | 104 | ]; |
| | 105 | } |
| | 106 | } |
| | 107 | |
| | 108 | |