Make WordPress Core


Ignore:
Timestamp:
12/17/2019 08:52:44 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Date/Time: Ensure that get_feed_build_date() correctly handles a modified post object with invalid date.

  • Clarify in the documentation that the function returns false on failure.
  • Consistently pass the return value through the get_feed_build_date filter.

Props Rarst, dd32, azaozz, tellyworth.
Merges [46974] and [46973] to the 5.3 branch.
Fixes #48957.

Location:
branches/5.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.3

  • branches/5.3/tests/phpunit/tests/date/getFeedBuildDate.php

    r46774 r46977  
    3737                $this->assertEquals( '2018-07-23T03:13:23+00:00', get_feed_build_date( DATE_RFC3339 ) );
    3838        }
     39
     40        /**
     41         * Test that get_feed_build_date() works with invalid post dates.
     42         *
     43         * @ticket 48957
     44         */
     45        public function test_should_fall_back_to_last_post_modified() {
     46                global $wp_query;
     47
     48                update_option( 'timezone_string', 'Europe/Kiev' );
     49                $datetime     = new DateTimeImmutable( 'now', wp_timezone() );
     50                $datetime_utc = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
     51
     52                $wp_query->posts = array();
     53
     54                $this->assertFalse( get_feed_build_date( DATE_RFC3339 ), 'False when unable to determine valid time' );
     55
     56                $this->factory->post->create(
     57                        array(
     58                                'post_date' => $datetime->format( 'Y-m-d H:i:s' ),
     59                        )
     60                );
     61
     62                $this->assertEquals(
     63                        $datetime_utc->format( DATE_RFC3339 ),
     64                        get_feed_build_date( DATE_RFC3339 ),
     65                        'Fall back to time of last post modified with no posts'
     66                );
     67
     68                $post_id_broken = $this->factory->post->create();
     69                $post_broken    = get_post( $post_id_broken );
     70
     71                $post_broken->post_modified_gmt = 0;
     72
     73                $wp_query->posts = array( $post_broken );
     74
     75                $this->assertEquals(
     76                        $datetime_utc->format( DATE_RFC3339 ),
     77                        get_feed_build_date( DATE_RFC3339 ),
     78                        'Fall back to time of last post modified with broken post object'
     79                );
     80        }
    3981}
Note: See TracChangeset for help on using the changeset viewer.