Make WordPress Core

Changeset 47081


Ignore:
Timestamp:
01/17/2020 02:50:39 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Date/Time: Add some basic tests for current_time().

Props pbearne, talldanwp, SergeyBiryukov.
Fixes #34378.

File:
1 edited

Legend:

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

    r46586 r47081  
    66 */
    77class Tests_Date_Current_Time extends WP_UnitTestCase {
     8
     9        /**
     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        }
    849
    950        /**
Note: See TracChangeset for help on using the changeset viewer.