<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[36519] trunk/tests/phpunit/tests/feed: Improve Automated Feed Tests</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/36519">36519</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/36519","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>jorbin</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-02-12 19:02:25 +0000 (Fri, 12 Feb 2016)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Improve Automated Feed Tests

Multiple improvements to the RSS2 automated tests along with the addition of Atom tests.
1. General whitespace cleanup (since the rss2 file serves as the base of the atom file).
2. Adds an author and category to the tests.
3. Since the content of the posts is the same, we don't need to test all of the post content.
4. Adds many posts so that the post count can be checked

Props stevenkword
Fixes <a href="https://core.trac.wordpress.org/ticket/35160">#35160</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsfeedrss2php">trunk/tests/phpunit/tests/feed/rss2.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsfeedatomphp">trunk/tests/phpunit/tests/feed/atom.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunittestsfeedatomphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/feed/atom.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/feed/atom.php                           (rev 0)
+++ trunk/tests/phpunit/tests/feed/atom.php     2016-02-12 19:02:25 UTC (rev 36519)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,214 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Test the Atom feed by generating a feed, parsing it, and checking that the
+ * parsed contents match the contents of the posts stored in the database.  Since
+ * we're using a real XML parser, this confirms that the feed is valid, well formed,
+ * and contains the right stuff.
+ *
+ * @group feed
+ */
+class Tests_Feeds_Atom extends WP_UnitTestCase {
+       static $user_id;
+       static $posts;
+       static $category;
+
+       /**
+        * Setup a new user and attribute some posts.
+        */
+       public static function wpSetUpBeforeClass( $factory ) {
+               // Create a user
+               self::$user_id = $factory->user->create( array(
+                       'role'         => 'author',
+                       'user_login'   => 'test_author',
+                       'display_name' => 'Test A. Uthor',
+               ) );
+
+               // Create a taxonomy
+               self::$category = self::factory()->category->create_and_get( array(
+                       'name' => 'Test Category',
+                       'slug' => 'test-cat',
+               ) );
+
+               // Create a few posts
+               self::$posts = $factory->post->create_many( 42, array(
+                       'post_author'  => self::$user_id,
+                       '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 ) {
+                       wp_set_object_terms( $post, self::$category->slug, 'category' );
+               }
+
+       }
+
+       /**
+        * Destroy the user we created and related posts.
+        */
+       public static function wpTearDownAfterClass() {
+               // Delete our user
+               self::delete_user( self::$user_id );
+
+               // Delete all of our posts
+               foreach ( self::$posts as $post ) {
+                       wp_delete_post( $post, true );
+               }
+
+               // Delete our taxonomy
+               wp_delete_category( self::$category->term_id );
+       }
+
+       /**
+        * Setup.
+        */
+       public function setUp() {
+               parent::setUp();
+
+               $this->post_count = (int) get_option( 'posts_per_rss' );
+               $this->excerpt_only = get_option( 'rss_use_excerpt' );
+       }
+
+       /**
+        * This is a bit of a hack used to buffer feed content.
+        */
+       function do_atom() {
+               ob_start();
+               // Nasty hack! In the future it would better to leverage do_feed( 'atom' ).
+               global $post;
+               try {
+                       @require( ABSPATH . 'wp-includes/feed-atom.php' );
+                       $out = ob_get_clean();
+               } catch ( Exception $e ) {
+                       $out = ob_get_clean();
+                       throw( $e );
+               }
+               return $out;
+       }
+
+       /**
+        * Test the <feed> element to make sure its present and populated
+        * with the expected child elements and attributes.
+        */
+       function test_feed_element() {
+               $this->go_to( '/?feed=atom' );
+               $feed = $this->do_atom();
+               $xml = xml_to_array( $feed );
+
+               // Get the <feed> child element of <xml>.
+               $atom = xml_find( $xml, 'feed' );
+
+               // There should only be one <feed> child element.
+               $this->assertCount( 1, $atom );
+
+               // Verify attributes.
+               $this->assertEquals( 'http://www.w3.org/2005/Atom', $atom[0]['attributes']['xmlns'] );
+               $this->assertEquals( 'http://purl.org/syndication/thread/1.0', $atom[0]['attributes']['xmlns:thr'] );
+               $this->assertEquals( site_url( '/wp-atom.php' ) , $atom[0]['attributes']['xml:base'] );
+
+               // Verify the <feed> element is present and contains a <title> child element.
+               $title = xml_find( $xml, 'feed', 'title' );
+               $this->assertEquals( get_option( 'blogname' ), $title[0]['content'] );
+
+               // Verify the <feed> element is present and contains a <updated> child element.
+               $updated = xml_find( $xml, 'feed', 'updated' );
+               $this->assertEquals( strtotime( get_lastpostmodified() ), strtotime( $updated[0]['content'] ) );
+
+               // Verify the <feed> element is present and contains a <subtitle> child element.
+               $subtitle = xml_find( $xml, 'feed', 'subtitle' );
+               $this->assertEquals( get_option( 'blogdescription' ), $subtitle[0]['content'] );
+
+               // Verify the <feed> element is present and contains two <link> child elements.
+               $link = xml_find( $xml, 'feed', 'link' );
+               $this->assertCount( 2, $link );
+
+               // Verify the <feed> element is present and contains a <link rel="alternate"> child element.
+               $this->assertEquals( 'alternate', $link[0]['attributes']['rel'] );
+               $this->assertEquals( home_url(), $link[0]['attributes']['href'] );
+
+               // Verify the <feed> element is present and contains a <link rel="href"> child element.
+               $this->assertEquals( 'self', $link[1]['attributes']['rel'] );
+               $this->assertEquals( home_url( '/?feed=atom' ), $link[1]['attributes']['href'] );
+       }
+
+       /**
+        * 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'] );
+                               }
+                       }
+               }
+       }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestsfeedrss2php"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/feed/rss2.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/feed/rss2.php   2016-02-12 18:34:46 UTC (rev 36518)
+++ trunk/tests/phpunit/tests/feed/rss2.php     2016-02-12 19:02:25 UTC (rev 36519)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,44 +1,82 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * test the RSS 2.0 feed by generating a feed, parsing it, and checking that the
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Test the RSS 2.0 feed by generating a feed, parsing it, and checking that the
</ins><span class="cx" style="display: block; padding: 0 10px">  * parsed contents match the contents of the posts stored in the database.  Since
</span><span class="cx" style="display: block; padding: 0 10px">  * we're using a real XML parser, this confirms that the feed is valid, well formed,
</span><span class="cx" style="display: block; padding: 0 10px">  * and contains the right stuff.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @group feed
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-class Tests_Feed_RSS2 extends WP_UnitTestCase {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+class Tests_Feeds_RSS2 extends WP_UnitTestCase {
</ins><span class="cx" style="display: block; padding: 0 10px">         static $user_id;
</span><span class="cx" style="display: block; padding: 0 10px">        static $posts;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        static $category;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        /**
+        * Setup a new user and attribute some posts.
+        */
</ins><span class="cx" style="display: block; padding: 0 10px">         public static function wpSetUpBeforeClass( $factory ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                self::$user_id = $factory->user->create();
-               self::$posts = $factory->post->create_many( 5, array(
-                       'post_author' => self::$user_id,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Create a user
+               self::$user_id = $factory->user->create( array(
+                       'role'         => 'author',
+                       'user_login'   => 'test_author',
+                       'display_name' => 'Test A. Uthor',
</ins><span class="cx" style="display: block; padding: 0 10px">                 ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               // Create a taxonomy
+               self::$category = self::factory()->category->create_and_get( array(
+                       'name' => 'Test Category',
+                       'slug' => 'test-cat',
+               ) );
+
+               // Create a few posts
+               self::$posts = $factory->post->create_many( 42, array(
+                       'post_author'  => self::$user_id,
+                       '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 ) {
+                       wp_set_object_terms( $post, self::$category->slug, 'category' );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        /**
+        * Destroy the user we created and related posts.
+        */
</ins><span class="cx" style="display: block; padding: 0 10px">         public static function wpTearDownAfterClass() {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // Delete our user
</ins><span class="cx" style="display: block; padding: 0 10px">                 self::delete_user( self::$user_id );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // Delete all of our posts
</ins><span class="cx" style="display: block; padding: 0 10px">                 foreach ( self::$posts as $post ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        wp_delete_post( $post, true );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               // Delete our taxonomy
+               wp_delete_category( self::$category->term_id );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        /**
+        * Setup.
+        */
</ins><span class="cx" style="display: block; padding: 0 10px">         public function setUp() {
</span><span class="cx" style="display: block; padding: 0 10px">                parent::setUp();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->post_count = get_option('posts_per_rss');
-               $this->excerpt_only = get_option('rss_use_excerpt');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->post_count = (int) get_option( 'posts_per_rss' );
+               $this->excerpt_only = get_option( 'rss_use_excerpt' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 // this seems to break something
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                update_option('use_smilies', false);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         update_option( 'use_smilies', false );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        /**
+        * This is a bit of a hack used to buffer feed content.
+        */
</ins><span class="cx" style="display: block; padding: 0 10px">         function do_rss2() {
</span><span class="cx" style="display: block; padding: 0 10px">                ob_start();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // nasty hack
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Nasty hack! In the future it would better to leverage do_feed( 'rss2' ).
</ins><span class="cx" style="display: block; padding: 0 10px">                 global $post;
</span><span class="cx" style="display: block; padding: 0 10px">                try {
</span><span class="cx" style="display: block; padding: 0 10px">                        @require(ABSPATH . 'wp-includes/feed-rss2.php');
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -50,61 +88,77 @@
</span><span class="cx" style="display: block; padding: 0 10px">                return $out;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        function test_rss() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+        * Test the <rss> element to make sure its present and populated
+        * with the expected child elements and attributes.
+        */
+       function test_rss_element() {
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->go_to( '/?feed=rss2' );
</span><span class="cx" style="display: block; padding: 0 10px">                $feed = $this->do_rss2();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $xml = xml_to_array($feed);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $xml = xml_to_array( $feed );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // get the rss element
-               $rss = xml_find($xml, 'rss');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Get the <rss> child element of <xml>.
+               $rss = xml_find( $xml, 'rss' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // there should only be one rss element
-               $this->assertEquals(1, count($rss));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // There should only be one <rss> child element.
+               $this->assertEquals( 1, count( $rss ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals('2.0', $rss[0]['attributes']['version']);
-               $this->assertEquals('http://purl.org/rss/1.0/modules/content/', $rss[0]['attributes']['xmlns:content']);
-               $this->assertEquals('http://wellformedweb.org/CommentAPI/', $rss[0]['attributes']['xmlns:wfw']);
-               $this->assertEquals('http://purl.org/dc/elements/1.1/', $rss[0]['attributes']['xmlns:dc']);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( '2.0', $rss[0]['attributes']['version'] );
+               $this->assertEquals( 'http://purl.org/rss/1.0/modules/content/', $rss[0]['attributes']['xmlns:content'] );
+               $this->assertEquals( 'http://wellformedweb.org/CommentAPI/', $rss[0]['attributes']['xmlns:wfw'] );
+               $this->assertEquals( 'http://purl.org/dc/elements/1.1/', $rss[0]['attributes']['xmlns:dc'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // rss should have exactly one child element (channel)
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals(1, count($rss[0]['child']));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( 1, count( $rss[0]['child'] ) );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        function test_channel() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+        * [test_channel_element description]
+        * @return [type] [description]
+        */
+       function test_channel_element() {
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->go_to( '/?feed=rss2' );
</span><span class="cx" style="display: block; padding: 0 10px">                $feed = $this->do_rss2();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $xml = xml_to_array($feed);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $xml = xml_to_array( $feed );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // get the rss -> channel element
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $channel = xml_find($xml, 'rss', 'channel');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $channel = xml_find( $xml, 'rss', 'channel' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertTrue(empty($channel[0]['attributes']));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // The channel should be free of attributes
+               $this->assertTrue( empty( $channel[0]['attributes'] ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $title = xml_find($xml, 'rss', 'channel', 'title');
-               $this->assertEquals(get_option('blogname'), $title[0]['content']);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Verify the channel is present and contains a title child element
+               $title = xml_find( $xml, 'rss', 'channel', 'title' );
+               $this->assertEquals( get_option( 'blogname' ), $title[0]['content'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $desc = xml_find($xml, 'rss', 'channel', 'description');
-               $this->assertEquals(get_option('blogdescription'), $desc[0]['content']);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $desc = xml_find( $xml, 'rss', 'channel', 'description' );
+               $this->assertEquals( get_option( 'blogdescription' ), $desc[0]['content'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $link = xml_find($xml, 'rss', 'channel', 'link');
-               $this->assertEquals(get_option('siteurl'), $link[0]['content']);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $link = xml_find( $xml, 'rss', 'channel', 'link' );
+               $this->assertEquals( get_option( 'siteurl' ), $link[0]['content'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $pubdate = xml_find($xml, 'rss', 'channel', 'lastBuildDate');
-               $this->assertEquals(strtotime(get_lastpostmodified()), strtotime($pubdate[0]['content']));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $pubdate = xml_find( $xml, 'rss', 'channel', 'lastBuildDate' );
+               $this->assertEquals( strtotime( get_lastpostmodified() ), strtotime( $pubdate[0]['content'] ) );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket UT32
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        function test_items() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function test_item_elements() {
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->go_to( '/?feed=rss2' );
</span><span class="cx" style="display: block; padding: 0 10px">                $feed = $this->do_rss2();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $xml = xml_to_array($feed);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $xml = xml_to_array( $feed );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // get all the rss -> channel -> item elements
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Get all the <item> child elements of the <channel> element
</ins><span class="cx" style="display: block; padding: 0 10px">                 $items = xml_find( $xml, 'rss', 'channel', 'item' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // check each of the items against the known post data
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Verify we are displaying the correct number of posts.
+               $this->assertCount( $this->post_count, $items );
+
+               // We Really only need to test X number of items unless the content is different
+               $items = array_slice( $items, 1 );
+
+               // Check each of the desired entries against the known post data
</ins><span class="cx" style="display: block; padding: 0 10px">                 foreach ( $items as $key => $item ) {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Get post for comparison
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -112,28 +166,28 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        preg_match( '/\?p=(\d+)/', $guid[0]['content'], $matches );
</span><span class="cx" style="display: block; padding: 0 10px">                        $post = get_post( $matches[1] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // title
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Title
</ins><span class="cx" style="display: block; padding: 0 10px">                         $title = xml_find( $items[$key]['child'], 'title' );
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertEquals( $post->post_title, $title[0]['content'] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // link
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Link
</ins><span class="cx" style="display: block; padding: 0 10px">                         $link = xml_find( $items[$key]['child'], 'link' );
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertEquals( get_permalink( $post ), $link[0]['content'] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // comment link
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Comment link
</ins><span class="cx" style="display: block; padding: 0 10px">                         $comments_link = xml_find( $items[$key]['child'], 'comments' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->assertEquals( get_permalink( $post) . '#respond', $comments_link[0]['content'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->assertEquals( get_permalink( $post ) . '#respond', $comments_link[0]['content'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // pub date
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Pub date
</ins><span class="cx" style="display: block; padding: 0 10px">                         $pubdate = xml_find( $items[$key]['child'], 'pubDate' );
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertEquals( strtotime( $post->post_date_gmt ), strtotime( $pubdate[0]['content'] ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // author
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Author
</ins><span class="cx" style="display: block; padding: 0 10px">                         $creator = xml_find( $items[$key]['child'], 'dc:creator' );
</span><span class="cx" style="display: block; padding: 0 10px">                        $user = new WP_User( $post->post_author );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->assertEquals( $user->user_login, $creator[0]['content'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->assertEquals( $user->display_name, $creator[0]['content'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // categories (perhaps multiple)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Categories (perhaps multiple)
</ins><span class="cx" style="display: block; padding: 0 10px">                         $categories = xml_find( $items[$key]['child'], 'category' );
</span><span class="cx" style="display: block; padding: 0 10px">                        $cats = array();
</span><span class="cx" style="display: block; padding: 0 10px">                        foreach ( get_the_category( $post->ID ) as $term ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -147,34 +201,34 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                        $cats = array_filter( $cats );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // should be the same number of categories
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Should be the same number of categories
</ins><span class="cx" style="display: block; padding: 0 10px">                         $this->assertEquals( count( $cats ), count( $categories ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // ..with the same names
</span><span class="cx" style="display: block; padding: 0 10px">                        foreach ( $cats as $id => $cat ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $this->assertEquals( $cat, $categories[$id]['content']);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $this->assertEquals( $cat, $categories[$id]['content'] );
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // GUID
</span><span class="cx" style="display: block; padding: 0 10px">                        $guid = xml_find( $items[$key]['child'], 'guid' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->assertEquals('false', $guid[0]['attributes']['isPermaLink'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->assertEquals( 'false', $guid[0]['attributes']['isPermaLink'] );
</ins><span class="cx" style="display: block; padding: 0 10px">                         $this->assertEquals( $post->guid, $guid[0]['content'] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // description/excerpt
-                       if ( !empty( $post->post_excerpt ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Description / Excerpt
+                       if ( ! empty( $post->post_excerpt ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $description = xml_find( $items[$key]['child'], 'description' );
</span><span class="cx" style="display: block; padding: 0 10px">                                $this->assertEquals( trim( $post->post_excerpt ), trim( $description[0]['content'] ) );
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // post content
-                       if ( !$this->excerpt_only ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Post content
+                       if ( ! $this->excerpt_only ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $content = xml_find( $items[$key]['child'], 'content:encoded' );
</span><span class="cx" style="display: block; padding: 0 10px">                                $this->assertEquals( trim( apply_filters( 'the_content', $post->post_content ) ), trim( $content[0]['content'] ) );
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // comment rss
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Comment rss
</ins><span class="cx" style="display: block; padding: 0 10px">                         $comment_rss = xml_find( $items[$key]['child'], 'wfw:commentRss' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->assertEquals( html_entity_decode( get_post_comments_feed_link( $post->ID) ), $comment_rss[0]['content'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->assertEquals( html_entity_decode( get_post_comments_feed_link( $post->ID ) ), $comment_rss[0]['content'] );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -186,7 +240,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->go_to( '/?feed=rss2' );
</span><span class="cx" style="display: block; padding: 0 10px">                $feed = $this->do_rss2();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $xml = xml_to_array($feed);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $xml = xml_to_array( $feed );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // get all the rss -> channel -> item elements
</span><span class="cx" style="display: block; padding: 0 10px">                $items = xml_find( $xml, 'rss', 'channel', 'item' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -209,4 +263,5 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                remove_filter( 'comments_open', '__return_false' );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>