Make WordPress Core

Changeset 34474


Ignore:
Timestamp:
09/24/2015 03:33:21 AM (11 years ago)
Author:
wonderboymusic
Message:

Date/Time: Add unit tests for the_date().

Props jubstuff.
Fixes #33750.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r34463 r34474  
    18991899        global $currentday, $previousday;
    19001900
    1901         if ( $currentday != $previousday ) {
     1901        if ( is_new_day() ) {
    19021902                $the_date = $before . get_the_date( $d ) . $after;
    19031903                $previousday = $currentday;
  • trunk/tests/phpunit/tests/functions.php

    r34104 r34474  
    672672                $this->assertFalse( $json );
    673673        }
     674
     675        /**
     676         * @ticket 33750
     677         */
     678        function test_the_date() {
     679                ob_start();
     680                the_date();
     681                $actual = ob_get_clean();
     682                $this->assertEquals( '', $actual );
     683
     684                $GLOBALS['post']        = $this->factory->post->create_and_get( array(
     685                        'post_date' => '2015-09-16 08:00:00'
     686                ) );
     687
     688                ob_start();
     689                $GLOBALS['currentday']  = '18.09.15';
     690                $GLOBALS['previousday'] = '17.09.15';
     691                the_date();
     692                $this->assertEquals( 'September 16, 2015', ob_get_clean() );
     693
     694                ob_start();
     695                $GLOBALS['currentday']  = '18.09.15';
     696                $GLOBALS['previousday'] = '17.09.15';
     697                the_date( 'Y' );
     698                $this->assertEquals( '2015', ob_get_clean() );
     699
     700                ob_start();
     701                $GLOBALS['currentday']  = '18.09.15';
     702                $GLOBALS['previousday'] = '17.09.15';
     703                the_date( 'Y', 'before ', ' after' );
     704                $this->assertEquals( 'before 2015 after', ob_get_clean() );
     705
     706                ob_start();
     707                $GLOBALS['currentday']  = '18.09.15';
     708                $GLOBALS['previousday'] = '17.09.15';
     709                the_date( 'Y', 'before ', ' after', false );
     710                $this->assertEquals( '', ob_get_clean() );
     711        }
    674712}
Note: See TracChangeset for help on using the changeset viewer.