/** * Validate <entry> child elements. */ function test_entry_elements() { $this->go_to('/?feed=atom'); $feed = $this->do_atom(); $xml = xml_to_array($feed); // Get all the <entry> child elements of the <feed> element. $entries = xml_find($xml, 'feed', 'entry'); // Verify we are displaying the correct number of posts. $this->assertCount($this->post_count, $entries); // We Really only need to test X number of entries unless the content is different $entries = array_slice($entries, 1); // Check each of the desired entries against the known post data. foreach ($entries as $key => $entry) { // Get post for comparison $id = xml_find($entries[$key]['child'], 'id'); preg_match('/\\?p=(\\d+)/', $id[0]['content'], $matches); $post = get_post($matches[1]); // Author $author = xml_find($entries[$key]['child'], 'author', 'name'); $user = new WP_User($post->post_author); $this->assertEquals($user->display_name, $author[0]['content']); // Title $title = xml_find($entries[$key]['child'], 'title'); $this->assertEquals($post->post_title, $title[0]['content']); // Link rel="alternate" $link_alts = xml_find($entries[$key]['child'], 'link'); foreach ($link_alts as $link_alt) { if ('alternate' == $link_alt['attributes']['rel']) { $this->assertEquals(get_permalink($post), $link_alt['attributes']['href']); } } // Id $guid = xml_find($entries[$key]['child'], 'id'); $this->assertEquals($post->guid, $id[0]['content']); // Updated $updated = xml_find($entries[$key]['child'], 'updated'); $this->assertEquals(strtotime($post->post_modified_gmt), strtotime($updated[0]['content'])); // Published $published = xml_find($entries[$key]['child'], 'published'); $this->assertEquals(strtotime($post->post_date_gmt), strtotime($published[0]['content'])); // Category foreach (get_the_category($post->ID) as $term) { $terms[] = $term->name; } $categories = xml_find($entries[$key]['child'], 'category'); foreach ($categories as $category) { $this->assertTrue(in_array($category['attributes']['term'], $terms)); } unset($terms); // Content if (!$this->excerpt_only) { $content = xml_find($entries[$key]['child'], 'content'); $this->assertEquals(trim(apply_filters('the_content', $post->post_content)), trim($content[0]['content'])); } // Link rel="replies" $link_replies = xml_find($entries[$key]['child'], 'link'); foreach ($link_replies as $link_reply) { if ('replies' == $link_reply['attributes']['rel'] && 'application/atom+xml' == $link_reply['attributes']['type']) { $this->assertEquals(get_post_comments_feed_link($post->ID, 'atom'), $link_reply['attributes']['href']); } } } }
/** * @ticket 9134 */ function test_items_comments_closed() { add_filter('comments_open', '__return_false'); $this->go_to('/?feed=rss2'); $feed = $this->do_rss2(); $xml = xml_to_array($feed); // get all the rss -> channel -> item elements $items = xml_find($xml, 'rss', 'channel', 'item'); // check each of the items against the known post data foreach ($items as $key => $item) { // Get post for comparison $guid = xml_find($items[$key]['child'], 'guid'); preg_match('/\\?p=(\\d+)/', $guid[0]['content'], $matches); $post = get_post($matches[1]); // comment link $comments_link = xml_find($items[$key]['child'], 'comments'); $this->assertEmpty($comments_link); // comment rss $comment_rss = xml_find($items[$key]['child'], 'wfw:commentRss'); $this->assertEmpty($comment_rss); } remove_filter('comments_open', '__return_false'); }
/** * @ticket UT32 */ function test_items() { $this->go_to('/?feed=rss2'); $feed = $this->do_rss2(); $xml = xml_to_array($feed); // get all the rss -> channel -> item elements $items = xml_find($xml, 'rss', 'channel', 'item'); $posts = get_posts('numberposts=' . $this->post_count); // check each of the items against the known post data foreach ($items as $key => $item) { // Get post for comparison $guid = xml_find($items[$key]['child'], 'guid'); preg_match('/\\?p=(\\d+)/', $guid[0]['content'], $matches); $post = get_post($matches[1]); // title $title = xml_find($items[$key]['child'], 'title'); $this->assertEquals($post->post_title, $title[0]['content']); // link $link = xml_find($items[$key]['child'], 'link'); $this->assertEquals(get_permalink($post), $link[0]['content']); // comment link $comments_link = xml_find($items[$key]['child'], 'comments'); $this->assertEquals(get_permalink($post) . '#respond', $comments_link[0]['content']); // pub date $pubdate = xml_find($items[$key]['child'], 'pubDate'); $this->assertEquals(strtotime($post->post_date_gmt), strtotime($pubdate[0]['content'])); // author $creator = xml_find($items[$key]['child'], 'dc:creator'); $user = new WP_User($post->post_author); $this->assertEquals($user->user_login, $creator[0]['content']); // categories (perhaps multiple) $categories = xml_find($items[$key]['child'], 'category'); $cats = array(); foreach (get_the_category($post->ID) as $term) { $cats[] = $term->name; } $tags = get_the_tags($post->ID); if ($tags) { foreach (get_the_tags($post->ID) as $term) { $cats[] = $term->name; } } $cats = array_filter($cats); // should be the same number of categories $this->assertEquals(count($cats), count($categories)); // ..with the same names foreach ($cats as $id => $cat) { $this->assertEquals($cat, $categories[$id]['content']); } // GUID $guid = xml_find($items[$key]['child'], 'guid'); $this->assertEquals('false', $guid[0]['attributes']['isPermaLink']); $this->assertEquals($post->guid, $guid[0]['content']); // description/excerpt if (!empty($post->post_excerpt)) { $description = xml_find($items[$key]['child'], 'description'); $this->assertEquals(trim($post->post_excerpt), trim($description[0]['content'])); } // post content if (!$this->excerpt_only) { $content = xml_find($items[$key]['child'], 'content:encoded'); $this->assertEquals(trim(apply_filters('the_content', $post->post_content)), trim($content[0]['content'])); } // comment rss $comment_rss = xml_find($items[$key]['child'], 'wfw:commentRss'); $this->assertEquals(html_entity_decode(get_post_comments_feed_link($post->ID)), $comment_rss[0]['content']); } }
function test_valid_search_feed_endpoint() { // An example of an valid search feed endpoint $this->go_to('?s=Lorem&feed=rss'); // Verify the query object is a feed. $this->assertQueryTrue('is_feed', 'is_search'); // 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(); $xml = xml_to_array($feed); // Get the <rss> child element of <xml>. $rss = xml_find($xml, 'rss'); // There should only be one <rss> child element. $this->assertEquals(1, count($rss)); }
/** * @ticket UT32 */ function test_items() { $this->go_to('/feed/'); $feed = $this->do_rss2(); $xml = xml_to_array($feed); // get all the rss -> channel -> item elements $items = xml_find($xml, 'rss', 'channel', 'item'); $posts = get_posts('numberposts=' . $this->post_count); // check each of the items against the known post data for ($i = 0; $i < $this->post_count; $i++) { // title $title = xml_find($items[$i]['child'], 'title'); $this->assertEquals($posts[$i]->post_title, $title[0]['content']); // link $link = xml_find($items[$i]['child'], 'link'); $this->assertEquals(get_permalink($posts[$i]->ID), $link[0]['content']); // comment link $comments_link = xml_find($items[$i]['child'], 'comments'); $this->assertEquals(get_permalink($posts[$i]->ID) . '#comments', $comments_link[0]['content']); // pub date $pubdate = xml_find($items[$i]['child'], 'pubDate'); $this->assertEquals(strtotime($posts[$i]->post_date), strtotime($pubdate[0]['content'])); // author $creator = xml_find($items[$i]['child'], 'dc:creator'); $this->assertEquals($this->author->user_nicename, $creator[0]['content']); // categories (perhaps multiple) $categories = xml_find($items[$i]['child'], 'category'); $cat_ids = wp_get_post_categories($post->ID); if (empty($cat_ids)) { $cat_ids = array(1); } // should be the same number of categories $this->assertEquals(count($cat_ids), count($categories)); // ..with the same names for ($j = 0; $j < count($cat_ids); $j++) { $this->assertEquals(get_cat_name($cat_ids[$j]), $categories[$j]['content']); } // GUID $guid = xml_find($items[$i]['child'], 'guid'); $this->assertEquals('false', $guid[0]['attributes']['isPermaLink']); $this->assertEquals($posts[$i]->guid, $guid[0]['content']); // description/excerpt $description = xml_find($items[$i]['child'], 'description'); $this->assertEquals(trim($posts[$i]->post_excerpt), trim($description[0]['content'])); // post content if (!$this->excerpt_only) { $content = xml_find($items[$i]['child'], 'content:encoded'); $this->assertEquals(trim(apply_filters('the_content', $posts[$i]->post_content)), trim($content[0]['content'])); } // comment rss $comment_rss = xml_find($items[$i]['child'], 'wfw:commentRss'); $this->assertEquals(html_entity_decode(get_post_comments_feed_link($posts[$i]->ID)), $comment_rss[0]['content']); } }