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
This commit is contained in:
Scott Taylor 2015-09-24 03:33:21 +00:00
parent 9d71ae4122
commit bab2316129
2 changed files with 39 additions and 1 deletions

View File

@ -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;

View File

@ -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() );
}
}