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.
Fixes #48957.

git-svn-id: https://develop.svn.wordpress.org/trunk@46974 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2019-12-17 20:41:09 +00:00
parent 9d69e005ea
commit a4b65bfca8
2 changed files with 74 additions and 28 deletions
@@ -37,4 +37,46 @@ class Tests_Date_Get_Feed_Build_Date extends WP_UnitTestCase {
$this->assertEquals( '2018-07-23T03:13:23+00:00', get_feed_build_date( DATE_RFC3339 ) );
}
/**
* Test that get_feed_build_date() works with invalid post dates.
*
* @ticket 48957
*/
public function test_should_fall_back_to_last_post_modified() {
global $wp_query;
update_option( 'timezone_string', 'Europe/Kiev' );
$datetime = new DateTimeImmutable( 'now', wp_timezone() );
$datetime_utc = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
$wp_query->posts = array();
$this->assertFalse( get_feed_build_date( DATE_RFC3339 ), 'False when unable to determine valid time' );
$this->factory->post->create(
array(
'post_date' => $datetime->format( 'Y-m-d H:i:s' ),
)
);
$this->assertEquals(
$datetime_utc->format( DATE_RFC3339 ),
get_feed_build_date( DATE_RFC3339 ),
'Fall back to time of last post modified with no posts'
);
$post_id_broken = $this->factory->post->create();
$post_broken = get_post( $post_id_broken );
$post_broken->post_modified_gmt = 0;
$wp_query->posts = array( $post_broken );
$this->assertEquals(
$datetime_utc->format( DATE_RFC3339 ),
get_feed_build_date( DATE_RFC3339 ),
'Fall back to time of last post modified with broken post object'
);
}
}