Make WordPress Core


Ignore:
Timestamp:
08/31/2020 10:41:02 PM (4 years 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.