Skip to content

Commit

Permalink
Date/Time: Add some basic tests for current_time().
Browse files Browse the repository at this point in the history
Props pbearne, talldanwp, SergeyBiryukov.
Fixes #34378.

git-svn-id: https://develop.svn.wordpress.org/trunk@47081 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Jan 17, 2020
1 parent 0ead760 commit 8660569
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/phpunit/tests/date/currentTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,47 @@
*/
class Tests_Date_Current_Time extends WP_UnitTestCase {

/**
* @ticket 34378
*/
public function test_current_time_with_date_format_string() {
update_option( 'gmt_offset', 6 );

$format = 'F j, Y, g:i a';
$timestamp = time();
$wp_timestamp = $timestamp + 6 * HOUR_IN_SECONDS;

$this->assertEquals( strtotime( gmdate( $format ) ), strtotime( current_time( $format, true ) ), 'The dates should be equal', 2 );
$this->assertEquals( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( $format ) ), 'The dates should be equal', 2 );
}

/**
* @ticket 34378
*/
public function test_current_time_with_mysql_format() {
update_option( 'gmt_offset', 6 );

$format = 'Y-m-d H:i:s';
$timestamp = time();
$wp_timestamp = $timestamp + 6 * HOUR_IN_SECONDS;

$this->assertEquals( strtotime( gmdate( $format ) ), strtotime( current_time( 'mysql', true ) ), 'The dates should be equal', 2 );
$this->assertEquals( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( 'mysql' ) ), 'The dates should be equal', 2 );
}

/**
* @ticket 34378
*/
public function test_current_time_with_timestamp() {
update_option( 'gmt_offset', 6 );

$timestamp = time();
$wp_timestamp = $timestamp + 6 * HOUR_IN_SECONDS;

$this->assertEquals( $timestamp, current_time( 'timestamp', true ), 'The dates should be equal', 2 );
$this->assertEquals( $wp_timestamp, current_time( 'timestamp' ), 'The dates should be equal', 2 );
}

/**
* @ticket 37440
*/
Expand Down

0 comments on commit 8660569

Please sign in to comment.