Make WordPress Core


Ignore:
Timestamp:
05/22/2019 09:57:29 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Date/Time: Bring some consistency to the_date() and the_weekday_date():

  • Make the_date() always apply the the filter and return a value.
  • Use is_new_day() in the_weekday_date().
  • Add a unit test for the_weekday_date().

Fixes #47354.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/date/theDate.php

    r43591 r45378  
    8282        return $input;
    8383    }
     84
     85    /**
     86     * @ticket 33750
     87     */
     88    function test_the_date() {
     89        ob_start();
     90        the_date();
     91        $actual = ob_get_clean();
     92        $this->assertEquals( '', $actual );
     93
     94        $GLOBALS['post'] = self::factory()->post->create_and_get(
     95            array(
     96                'post_date' => '2015-09-16 08:00:00',
     97            )
     98        );
     99
     100        ob_start();
     101        $GLOBALS['currentday']  = '18.09.15';
     102        $GLOBALS['previousday'] = '17.09.15';
     103        the_date();
     104        $this->assertEquals( 'September 16, 2015', ob_get_clean() );
     105
     106        ob_start();
     107        $GLOBALS['currentday']  = '18.09.15';
     108        $GLOBALS['previousday'] = '17.09.15';
     109        the_date( 'Y' );
     110        $this->assertEquals( '2015', ob_get_clean() );
     111
     112        ob_start();
     113        $GLOBALS['currentday']  = '18.09.15';
     114        $GLOBALS['previousday'] = '17.09.15';
     115        the_date( 'Y', 'before ', ' after' );
     116        $this->assertEquals( 'before 2015 after', ob_get_clean() );
     117
     118        ob_start();
     119        $GLOBALS['currentday']  = '18.09.15';
     120        $GLOBALS['previousday'] = '17.09.15';
     121        the_date( 'Y', 'before ', ' after', false );
     122        $this->assertEquals( '', ob_get_clean() );
     123    }
     124
     125    /**
     126     * @ticket 47354
     127     */
     128    function test_the_weekday_date() {
     129        ob_start();
     130        the_weekday_date();
     131        $actual = ob_get_clean();
     132        $this->assertEquals( '', $actual );
     133
     134        $GLOBALS['post'] = self::factory()->post->create_and_get(
     135            array(
     136                'post_date' => '2015-09-16 08:00:00',
     137            )
     138        );
     139
     140        ob_start();
     141        $GLOBALS['currentday']  = '18.09.15';
     142        $GLOBALS['previousday'] = '17.09.15';
     143        the_weekday_date();
     144        $this->assertEquals( 'Wednesday', ob_get_clean() );
     145
     146        ob_start();
     147        $GLOBALS['currentday']  = '18.09.15';
     148        $GLOBALS['previousday'] = '17.09.15';
     149        the_weekday_date( 'before ', ' after' );
     150        $this->assertEquals( 'before Wednesday after', ob_get_clean() );
     151    }
    84152}
Note: See TracChangeset for help on using the changeset viewer.