From 8660569e824622b8f90c1915451ccb3a3fabaa25 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 17 Jan 2020 02:50:39 +0000 Subject: [PATCH] Date/Time: Add some basic tests for `current_time()`. Props pbearne, talldanwp, SergeyBiryukov. Fixes #34378. git-svn-id: https://develop.svn.wordpress.org/trunk@47081 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/date/currentTime.php | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/phpunit/tests/date/currentTime.php b/tests/phpunit/tests/date/currentTime.php index 836f2737ee..69354acde8 100644 --- a/tests/phpunit/tests/date/currentTime.php +++ b/tests/phpunit/tests/date/currentTime.php @@ -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 */