WordPress.org

Make WordPress Core

Changeset 48924


Ignore:
Timestamp:
08/31/2020 10:41:02 PM (3 months ago)
Author:
SergeyBiryukov
Message:

Tests: Move the tests for get_the_modified_time() to a more appropriate place.

Add some new tests to better cover the functionality, for consistency with get_the_date() and get_the_time().

Follow-up to [48911], [48912], [48918].

Props wittich.
Fixes #51184.

Location:
trunk/tests/phpunit/tests
Files:
1 added
3 edited

Legend:

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

    r48912 r48924  
    1111     * @ticket 51184
    1212     */
    13     function test_get_comment_date_returns_correct_time_with_comment_id() {
     13    public function test_get_comment_date_returns_correct_time_with_comment_id() {
    1414        $c = self::factory()->comment->create( array( 'comment_date' => '2020-08-29 01:51:00' ) );
    1515
     
    2020     * @ticket 51184
    2121     */
    22     function test_get_comment_date_returns_correct_time_with_empty_format() {
     22    public function test_get_comment_date_returns_correct_time_with_empty_format() {
    2323        $c = self::factory()->comment->create( array( 'comment_date' => '2020-08-29 01:51:00' ) );
    2424
     
    3030     * @ticket 51184
    3131     */
    32     function test_get_comment_time_returns_correct_time() {
     32    public function test_get_comment_time_returns_correct_time() {
    3333        $c = self::factory()->comment->create( array( 'comment_date' => '2020-08-29 01:51:00' ) );
    3434
     
    4040     * @ticket 51184
    4141     */
    42     function test_get_comment_time_returns_correct_time_with_empty_format() {
     42    public function test_get_comment_time_returns_correct_time_with_empty_format() {
    4343        $c = self::factory()->comment->create( array( 'comment_date' => '2020-08-29 01:51:00' ) );
    4444
  • trunk/tests/phpunit/tests/date/getTheDate.php

    r48912 r48924  
    1111     * @ticket 13771
    1212     */
    13     function test_get_the_date_returns_correct_time_with_post_id() {
     13    public function test_get_the_date_returns_correct_time_with_post_id() {
    1414        $post_id = self::factory()->post->create( array( 'post_date' => '2014-03-01 16:35:00' ) );
    1515
     
    2020     * @ticket 28310
    2121     */
    22     function test_get_the_date_returns_false_with_null_or_non_existing_post() {
     22    public function test_get_the_date_returns_false_with_null_or_non_existing_post() {
    2323        $this->assertFalse( get_the_date() );
    2424        $this->assertFalse( get_the_date( 'F j, Y h:i:s' ) );
     
    3030     * @ticket 51184
    3131     */
    32     function test_get_the_date_returns_correct_time_with_empty_format() {
     32    public function test_get_the_date_returns_correct_time_with_empty_format() {
    3333        $post_id = self::factory()->post->create( array( 'post_date' => '2020-08-29 01:51:00' ) );
    3434
     
    4040     * @ticket 28310
    4141     */
    42     function test_get_the_time_returns_correct_time_with_post_id() {
     42    public function test_get_the_time_returns_correct_time_with_post_id() {
    4343        $post_id = self::factory()->post->create( array( 'post_date' => '2014-03-01 16:35:00' ) );
    4444
     
    4949     * @ticket 28310
    5050     */
    51     function test_get_the_time_returns_false_with_null_or_non_existing_post() {
     51    public function test_get_the_time_returns_false_with_null_or_non_existing_post() {
    5252        $this->assertFalse( get_the_time() );
    5353        $this->assertFalse( get_the_time( 'h:i:s' ) );
     
    5959     * @ticket 51184
    6060     */
    61     function test_get_the_time_returns_correct_time_with_empty_format() {
     61    public function test_get_the_time_returns_correct_time_with_empty_format() {
    6262        $post_id = self::factory()->post->create( array( 'post_date' => '2020-08-29 01:51:00' ) );
    6363
  • trunk/tests/phpunit/tests/general/template.php

    r48907 r48924  
    416416        $this->custom_logo_id  = $this->_make_attachment( $upload );
    417417        return $this->custom_logo_id;
    418     }
    419 
    420     /**
    421      * Test get_the_modified_time
    422      *
    423      * @ticket 37059
    424      *
    425      * @since 4.6.0
    426      */
    427     function test_get_the_modified_time_default() {
    428         $details = array(
    429             'post_date'     => '2016-01-21 15:34:36',
    430             'post_date_gmt' => '2016-01-21 15:34:36',
    431         );
    432         $post_id = $this->factory->post->create( $details );
    433         $post    = get_post( $post_id );
    434 
    435         $GLOBALS['post'] = $post;
    436 
    437         $expected = '1453390476';
    438         $format   = 'G';
    439         $actual   = get_the_modified_time( $format );
    440         $this->assertEquals( $expected, $actual );
    441     }
    442 
    443     /**
    444      * Test get_the_modified_time failures are filtered
    445      *
    446      * @ticket 37059
    447      *
    448      * @since 4.6.0
    449      */
    450     function test_get_the_modified_time_failures_are_filtered() {
    451         // Remove global post object.
    452         $GLOBALS['post'] = null;
    453 
    454         $expected = 'filtered modified time failure result';
    455         add_filter( 'get_the_modified_time', array( $this, '_filter_get_the_modified_time_failure' ) );
    456         $actual = get_the_modified_time();
    457         $this->assertEquals( $expected, $actual );
    458         remove_filter( 'get_the_modified_time', array( $this, '_filter_get_the_modified_time_failure' ) );
    459     }
    460 
    461     function _filter_get_the_modified_time_failure( $the_time ) {
    462         $expected = false;
    463         $actual   = $the_time;
    464         $this->assertEquals( $expected, $actual );
    465 
    466         if ( false === $the_time ) {
    467             return 'filtered modified time failure result';
    468         }
    469         return $the_time;
    470     }
    471 
    472     /**
    473      * Test get_the_modified_time with post_id parameter.
    474      *
    475      * @ticket 37059
    476      *
    477      * @since 4.6.0
    478      */
    479     function test_get_the_modified_date_with_post_id() {
    480         $details  = array(
    481             'post_date'     => '2016-01-21 15:34:36',
    482             'post_date_gmt' => '2016-01-21 15:34:36',
    483         );
    484         $post_id  = $this->factory->post->create( $details );
    485         $format   = 'Y-m-d';
    486         $expected = '2016-01-21';
    487         $actual   = get_the_modified_date( $format, $post_id );
    488         $this->assertEquals( $expected, $actual );
    489     }
    490 
    491     /**
    492      * Test get_the_modified_date
    493      *
    494      * @ticket 37059
    495      *
    496      * @since 4.6.0
    497      */
    498     function test_get_the_modified_date_default() {
    499         $details = array(
    500             'post_date'     => '2016-01-21 15:34:36',
    501             'post_date_gmt' => '2016-01-21 15:34:36',
    502         );
    503         $post_id = $this->factory->post->create( $details );
    504         $post    = get_post( $post_id );
    505 
    506         $GLOBALS['post'] = $post;
    507 
    508         $expected = '2016-01-21';
    509         $format   = 'Y-m-d';
    510         $actual   = get_the_modified_date( $format );
    511         $this->assertEquals( $expected, $actual );
    512     }
    513 
    514     /**
    515      * Test get_the_modified_date failures are filtered
    516      *
    517      * @ticket 37059
    518      *
    519      * @since 4.6.0
    520      */
    521     function test_get_the_modified_date_failures_are_filtered() {
    522         // Remove global post object.
    523         $GLOBALS['post'] = null;
    524 
    525         $expected = 'filtered modified date failure result';
    526         add_filter( 'get_the_modified_date', array( $this, '_filter_get_the_modified_date_failure' ) );
    527         $actual = get_the_modified_date();
    528         $this->assertEquals( $expected, $actual );
    529         remove_filter( 'get_the_modified_date', array( $this, '_filter_get_the_modified_date_failure' ) );
    530     }
    531 
    532     function _filter_get_the_modified_date_failure( $the_date ) {
    533         $expected = false;
    534         $actual   = $the_date;
    535         $this->assertEquals( $expected, $actual );
    536 
    537         if ( false === $the_date ) {
    538             return 'filtered modified date failure result';
    539         }
    540         return $the_date;
    541     }
    542 
    543     /**
    544      * Test get_the_modified_time with post_id parameter.
    545      *
    546      * @ticket 37059
    547      *
    548      * @since 4.6.0
    549      */
    550     function test_get_the_modified_time_with_post_id() {
    551         $details  = array(
    552             'post_date'     => '2016-01-21 15:34:36',
    553             'post_date_gmt' => '2016-01-21 15:34:36',
    554         );
    555         $post_id  = $this->factory->post->create( $details );
    556         $format   = 'G';
    557         $expected = '1453390476';
    558         $actual   = get_the_modified_time( $format, $post_id );
    559         $this->assertEquals( $expected, $actual );
    560418    }
    561419
Note: See TracChangeset for help on using the changeset viewer.