mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
Feeds: ensure build/update date matches current query.
Displaying the correct build date in feeds is as important today as it was twelve years ago when this ticket was opened. Fix an issue where all feeds in WordPress showed the same date for their last build date (the datapoint is `lastBuildDate`, `updated` or `dc:date` depending on the feed type). Introduce a new `get_last_build_date` filter to adjust the date used for `lastBuildDate`. Developers who previously filtered `get_lastcommentmodified` to alter feed dates should use this filter instead. * `get_last_build_date` extracts the latest post (or comment) in the current WP_Query object. * In all feed templates, use `get_last_build_date` vs `get_lastpostmodified( 'GMT' );`. Props stevenkword, spacedmonkey, ryanshoover, mauteri, nacin, jorbin, MikeNGarrett, Denis-de-Bernardy, peaceablewhale. Fixes #4575. git-svn-id: https://develop.svn.wordpress.org/trunk@44948 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -36,20 +36,23 @@ class Tests_Feeds_RSS2 extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
// Set a predictable time for testing date archives.
|
||||
self::$post_date = '2003-05-27 10:07:53';
|
||||
self::$post_date = strtotime( '2003-05-27 10:07:53' );
|
||||
|
||||
$count = get_option( 'posts_per_rss' ) + 1;
|
||||
|
||||
self::$posts = array();
|
||||
// Create a few posts
|
||||
self::$posts = $factory->post->create_many(
|
||||
$count,
|
||||
array(
|
||||
'post_author' => self::$user_id,
|
||||
'post_date' => self::$post_date,
|
||||
'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec velit massa, ultrices eu est suscipit, mattis posuere est. Donec vitae purus lacus. Cras vitae odio odio.',
|
||||
'post_excerpt' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
|
||||
)
|
||||
);
|
||||
for ( $i = 1; $i <= $count; $i++ ) {
|
||||
self::$posts[] = $factory->post->create(
|
||||
array(
|
||||
'post_author' => self::$user_id,
|
||||
// Separate post dates 5 seconds apart.
|
||||
'post_date' => gmdate( 'Y-m-d H:i:s', self::$post_date + ( 5 * $i ) ),
|
||||
'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec velit massa, ultrices eu est suscipit, mattis posuere est. Donec vitae purus lacus. Cras vitae odio odio.',
|
||||
'post_excerpt' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Assign a category to those posts
|
||||
foreach ( self::$posts as $post ) {
|
||||
@@ -396,6 +399,7 @@ class Tests_Feeds_RSS2 extends WP_UnitTestCase {
|
||||
// Queries performed on valid feed endpoints should contain posts.
|
||||
$this->assertTrue( have_posts() );
|
||||
|
||||
|
||||
// Check to see if we have the expected XML output from the feed template.
|
||||
$feed = $this->do_rss2();
|
||||
|
||||
@@ -463,4 +467,31 @@ class Tests_Feeds_RSS2 extends WP_UnitTestCase {
|
||||
// There should only be one <rss> child element.
|
||||
$this->assertEquals( 1, count( $rss ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test <rss> element has correct last build date.
|
||||
*
|
||||
* @ticket 4575
|
||||
*
|
||||
* @dataProvider data_test_get_last_build_date
|
||||
*/
|
||||
public function test_get_last_build_date( $url, $element ) {
|
||||
$this->go_to( $url );
|
||||
$feed = $this->do_rss2();
|
||||
$xml = xml_to_array( $feed );
|
||||
|
||||
// Get the <rss> child element of <xml>.
|
||||
$rss = xml_find( $xml, $element );
|
||||
$last_build_date = $rss[0]['child'][0]['child'][4]['content'];
|
||||
$this->assertEquals( strtotime( get_last_build_date() ), strtotime( $last_build_date ) );
|
||||
}
|
||||
|
||||
|
||||
public function data_test_get_last_build_date() {
|
||||
return array(
|
||||
array( '/?feed=rss2', 'rss' ),
|
||||
array( '/?feed=commentsrss2', 'rss' ),
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user