From bab231612948fdee26aadef10658f8ac7d825700 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 24 Sep 2015 03:33:21 +0000 Subject: [PATCH] Date/Time: Add unit tests for `the_date()`. Props jubstuff. Fixes #33750. git-svn-id: https://develop.svn.wordpress.org/trunk@34474 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/general-template.php | 2 +- tests/phpunit/tests/functions.php | 38 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index 9d22905b8c..6ec16b72b0 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -1898,7 +1898,7 @@ function the_date_xml() { function the_date( $d = '', $before = '', $after = '', $echo = true ) { global $currentday, $previousday; - if ( $currentday != $previousday ) { + if ( is_new_day() ) { $the_date = $before . get_the_date( $d ) . $after; $previousday = $currentday; diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 69d9390edd..0966fa1ca1 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -671,4 +671,42 @@ class Tests_Functions extends WP_UnitTestCase { $json = wp_json_encode( $data, 0, 1 ); $this->assertFalse( $json ); } + + /** + * @ticket 33750 + */ + function test_the_date() { + ob_start(); + the_date(); + $actual = ob_get_clean(); + $this->assertEquals( '', $actual ); + + $GLOBALS['post'] = $this->factory->post->create_and_get( array( + 'post_date' => '2015-09-16 08:00:00' + ) ); + + ob_start(); + $GLOBALS['currentday'] = '18.09.15'; + $GLOBALS['previousday'] = '17.09.15'; + the_date(); + $this->assertEquals( 'September 16, 2015', ob_get_clean() ); + + ob_start(); + $GLOBALS['currentday'] = '18.09.15'; + $GLOBALS['previousday'] = '17.09.15'; + the_date( 'Y' ); + $this->assertEquals( '2015', ob_get_clean() ); + + ob_start(); + $GLOBALS['currentday'] = '18.09.15'; + $GLOBALS['previousday'] = '17.09.15'; + the_date( 'Y', 'before ', ' after' ); + $this->assertEquals( 'before 2015 after', ob_get_clean() ); + + ob_start(); + $GLOBALS['currentday'] = '18.09.15'; + $GLOBALS['previousday'] = '17.09.15'; + the_date( 'Y', 'before ', ' after', false ); + $this->assertEquals( '', ob_get_clean() ); + } }