mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
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:
@@ -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'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user