Make WordPress Core

Ticket #34378: 34378.diff

File 34378.diff, 1.8 KB (added by SergeyBiryukov, 5 years ago)
  • tests/phpunit/tests/date/currentTime.php

     
    77class Tests_Date_Current_Time extends WP_UnitTestCase {
    88
    99        /**
     10         * @ticket 34378
     11         */
     12        public function test_current_time_with_date_format_string() {
     13                update_option( 'gmt_offset', 6 );
     14
     15                $format       = 'F j, Y, g:i a';
     16                $timestamp    = time();
     17                $wp_timestamp = $timestamp + 6 * HOUR_IN_SECONDS;
     18
     19                $this->assertEquals( strtotime( gmdate( $format ) ), strtotime( current_time( $format, true ) ), 'The dates should be equal', 2 );
     20                $this->assertEquals( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( $format ) ), 'The dates should be equal', 2 );
     21        }
     22
     23        /**
     24         * @ticket 34378
     25         */
     26        public function test_current_time_with_mysql_format() {
     27                update_option( 'gmt_offset', 6 );
     28
     29                $format       = 'Y-m-d H:i:s';
     30                $timestamp    = time();
     31                $wp_timestamp = $timestamp + 6 * HOUR_IN_SECONDS;
     32
     33                $this->assertEquals( strtotime( gmdate( $format ) ), strtotime( current_time( 'mysql', true ) ), 'The dates should be equal', 2 );
     34                $this->assertEquals( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( 'mysql' ) ), 'The dates should be equal', 2 );
     35        }
     36
     37        /**
     38         * @ticket 34378
     39         */
     40        public function test_current_time_with_timestamp() {
     41                update_option( 'gmt_offset', 6 );
     42
     43                $timestamp    = time();
     44                $wp_timestamp = $timestamp + 6 * HOUR_IN_SECONDS;
     45
     46                $this->assertEquals( $timestamp, current_time( 'timestamp', true ), 'The dates should be equal', 2 );
     47                $this->assertEquals( $wp_timestamp, current_time( 'timestamp' ), 'The dates should be equal', 2 );
     48        }
     49
     50        /**
    1051         * @ticket 37440
    1152         */
    1253        public function test_should_work_with_changed_timezone() {