Changeset 30283
- Timestamp:
- 11/08/2014 08:54:06 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/feed/rss2.php
r25002 r30283 92 92 93 93 // check each of the items against the known post data 94 for ($i=0; $i < $this->post_count; $i++) { 94 foreach ( $items as $key => $item ) { 95 96 // Get post for comparison 97 $guid = xml_find( $items[$key]['child'], 'guid' ); 98 preg_match( '/\?p=(\d+)/', $guid[0]['content'], $matches ); 99 $post = get_post( $matches[1] ); 95 100 96 101 // title 97 $title = xml_find( $items[$i]['child'], 'title');98 $this->assertEquals( $posts[$i]->post_title, $title[0]['content']);102 $title = xml_find( $items[$key]['child'], 'title' ); 103 $this->assertEquals( $post->post_title, $title[0]['content'] ); 99 104 100 105 // link 101 $link = xml_find( $items[$i]['child'], 'link');102 $this->assertEquals( get_permalink($posts[$i]->ID), $link[0]['content']);106 $link = xml_find( $items[$key]['child'], 'link' ); 107 $this->assertEquals( get_permalink( $post ), $link[0]['content'] ); 103 108 104 109 // comment link 105 $comments_link = xml_find( $items[$i]['child'], 'comments');106 $this->assertEquals( get_permalink($posts[$i]->ID) . '#comments', $comments_link[0]['content']);110 $comments_link = xml_find( $items[$key]['child'], 'comments' ); 111 $this->assertEquals( get_permalink( $post) . '#comments', $comments_link[0]['content'] ); 107 112 108 113 // pub date 109 $pubdate = xml_find( $items[$i]['child'], 'pubDate');110 $this->assertEquals( strtotime($posts[$i]->post_date), strtotime($pubdate[0]['content']));114 $pubdate = xml_find( $items[$key]['child'], 'pubDate' ); 115 $this->assertEquals( strtotime( $post->post_date_gmt ), strtotime( $pubdate[0]['content'] ) ); 111 116 112 117 // author 113 $creator = xml_find($items[$i]['child'], 'dc:creator'); 114 $this->assertEquals($this->author->user_nicename, $creator[0]['content']); 118 $creator = xml_find( $items[$key]['child'], 'dc:creator' ); 119 $user = new WP_User( $post->post_author ); 120 $this->assertEquals( $user->user_login, $creator[0]['content'] ); 115 121 116 122 // categories (perhaps multiple) 117 $categories = xml_find($items[$i]['child'], 'category'); 118 $cat_ids = wp_get_post_categories($post->ID); 119 if (empty($cat_ids)) $cat_ids = array(1); 123 $categories = xml_find( $items[$key]['child'], 'category' ); 124 $cats = array(); 125 foreach ( get_the_category( $post->ID ) as $term ) { 126 $cats[] = $term->name; 127 } 128 foreach ( get_the_tags( $post->ID ) as $term ) { 129 $cats[] = $term->name; 130 } 131 $cats = array_filter( $cats ); 120 132 // should be the same number of categories 121 $this->assertEquals(count($cat_ids), count($categories)); 133 $this->assertEquals( count( $cats ), count( $categories ) ); 134 122 135 // ..with the same names 123 for ($j=0; $j < count($cat_ids); $j++) 124 $this->assertEquals(get_cat_name($cat_ids[$j]), $categories[$j]['content']); 136 foreach ( $cats as $id => $cat ) { 137 $this->assertEquals( $cat, $categories[$id]['content']); 138 } 125 139 126 140 // GUID 127 $guid = xml_find( $items[$i]['child'], 'guid');128 $this->assertEquals('false', $guid[0]['attributes']['isPermaLink'] );129 $this->assertEquals( $posts[$i]->guid, $guid[0]['content']);141 $guid = xml_find( $items[$key]['child'], 'guid' ); 142 $this->assertEquals('false', $guid[0]['attributes']['isPermaLink'] ); 143 $this->assertEquals( $post->guid, $guid[0]['content'] ); 130 144 131 145 // description/excerpt 132 $description = xml_find($items[$i]['child'], 'description'); 133 $this->assertEquals(trim($posts[$i]->post_excerpt), trim($description[0]['content'])); 146 if ( !empty( $post->post_excerpt ) ) { 147 $description = xml_find( $items[$key]['child'], 'description' ); 148 $this->assertEquals( trim( $post->post_excerpt ), trim( $description[0]['content'] ) ); 149 } 134 150 135 151 // post content 136 if ( !$this->excerpt_only) {137 $content = xml_find( $items[$i]['child'], 'content:encoded');138 $this->assertEquals( trim(apply_filters('the_content', $posts[$i]->post_content)), trim($content[0]['content']));152 if ( !$this->excerpt_only ) { 153 $content = xml_find( $items[$key]['child'], 'content:encoded' ); 154 $this->assertEquals( trim( apply_filters( 'the_content', $post->post_content ) ), trim( $content[0]['content'] ) ); 139 155 } 140 156 141 157 // comment rss 142 $comment_rss = xml_find( $items[$i]['child'], 'wfw:commentRss');143 $this->assertEquals( html_entity_decode(get_post_comments_feed_link($posts[$i]->ID)), $comment_rss[0]['content']);158 $comment_rss = xml_find( $items[$key]['child'], 'wfw:commentRss' ); 159 $this->assertEquals( html_entity_decode( get_post_comments_feed_link( $post->ID) ), $comment_rss[0]['content'] ); 144 160 } 145 146 161 } 147 162 }
Note: See TracChangeset
for help on using the changeset viewer.