Changeset 47122 for trunk/tests/phpunit/tests/feed/rss2.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/feed/rss2.php
r46586 r47122 19 19 */ 20 20 public static function wpSetUpBeforeClass( $factory ) { 21 // Create a user 21 // Create a user. 22 22 self::$user_id = $factory->user->create( 23 23 array( … … 28 28 ); 29 29 30 // Create a taxonomy 30 // Create a taxonomy. 31 31 self::$category = $factory->category->create_and_get( 32 32 array( … … 42 42 43 43 self::$posts = array(); 44 // Create a few posts 44 // Create a few posts. 45 45 for ( $i = 1; $i <= $count; $i++ ) { 46 46 self::$posts[] = $factory->post->create( … … 55 55 } 56 56 57 // Assign a category to those posts 57 // Assign a category to those posts. 58 58 foreach ( self::$posts as $post ) { 59 59 wp_set_object_terms( $post, self::$category->slug, 'category' ); … … 69 69 $this->post_count = (int) get_option( 'posts_per_rss' ); 70 70 $this->excerpt_only = get_option( 'rss_use_excerpt' ); 71 // this seems to break something71 // This seems to break something. 72 72 update_option( 'use_smilies', false ); 73 73 … … 114 114 $this->assertEquals( 'http://purl.org/dc/elements/1.1/', $rss[0]['attributes']['xmlns:dc'] ); 115 115 116 // rss should have exactly one child element (channel)116 // RSS should have exactly one child element (channel). 117 117 $this->assertEquals( 1, count( $rss[0]['child'] ) ); 118 118 } … … 128 128 $xml = xml_to_array( $feed ); 129 129 130 // get the rss -> channel element130 // Get the rss -> channel element. 131 131 $channel = xml_find( $xml, 'rss', 'channel' ); 132 132 133 // The channel should be free of attributes 133 // The channel should be free of attributes. 134 134 $this->assertTrue( empty( $channel[0]['attributes'] ) ); 135 135 136 // Verify the channel is present and contains a title child element 136 // Verify the channel is present and contains a title child element. 137 137 $title = xml_find( $xml, 'rss', 'channel', 'title' ); 138 138 $this->assertEquals( get_option( 'blogname' ), $title[0]['content'] ); … … 181 181 $xml = xml_to_array( $feed ); 182 182 183 // Get all the <item> child elements of the <channel> element 183 // Get all the <item> child elements of the <channel> element. 184 184 $items = xml_find( $xml, 'rss', 'channel', 'item' ); 185 185 … … 187 187 $this->assertCount( $this->post_count, $items ); 188 188 189 // We Really only need to test X number of items unless the content is different189 // We really only need to test X number of items unless the content is different. 190 190 $items = array_slice( $items, 1 ); 191 191 192 // Check each of the desired entries against the known post data 192 // Check each of the desired entries against the known post data. 193 193 foreach ( $items as $key => $item ) { 194 194 195 // Get post for comparison 195 // Get post for comparison. 196 196 $guid = xml_find( $items[ $key ]['child'], 'guid' ); 197 197 preg_match( '/\?p=(\d+)/', $guid[0]['content'], $matches ); 198 198 $post = get_post( $matches[1] ); 199 199 200 // Title 200 // Title. 201 201 $title = xml_find( $items[ $key ]['child'], 'title' ); 202 202 $this->assertEquals( $post->post_title, $title[0]['content'] ); 203 203 204 // Link 204 // Link. 205 205 $link = xml_find( $items[ $key ]['child'], 'link' ); 206 206 $this->assertEquals( get_permalink( $post ), $link[0]['content'] ); 207 207 208 // Comment link 208 // Comment link. 209 209 $comments_link = xml_find( $items[ $key ]['child'], 'comments' ); 210 210 $this->assertEquals( get_permalink( $post ) . '#respond', $comments_link[0]['content'] ); 211 211 212 // Pub date 212 // Pub date. 213 213 $pubdate = xml_find( $items[ $key ]['child'], 'pubDate' ); 214 214 $this->assertEquals( strtotime( $post->post_date_gmt ), strtotime( $pubdate[0]['content'] ) ); 215 215 216 // Author 216 // Author. 217 217 $creator = xml_find( $items[ $key ]['child'], 'dc:creator' ); 218 218 $user = new WP_User( $post->post_author ); 219 219 $this->assertEquals( $user->display_name, $creator[0]['content'] ); 220 220 221 // Categories (perhaps multiple) 221 // Categories (perhaps multiple). 222 222 $categories = xml_find( $items[ $key ]['child'], 'category' ); 223 223 $cats = array(); … … 233 233 } 234 234 $cats = array_filter( $cats ); 235 // Should be the same number of categories 235 // Should be the same number of categories. 236 236 $this->assertEquals( count( $cats ), count( $categories ) ); 237 237 238 // ..with the same names 238 // ..with the same names. 239 239 foreach ( $cats as $id => $cat ) { 240 240 $this->assertEquals( $cat, $categories[ $id ]['content'] ); 241 241 } 242 242 243 // GUID 243 // GUID. 244 244 $guid = xml_find( $items[ $key ]['child'], 'guid' ); 245 245 $this->assertEquals( 'false', $guid[0]['attributes']['isPermaLink'] ); 246 246 $this->assertEquals( $post->guid, $guid[0]['content'] ); 247 247 248 // Description / Excerpt 248 // Description / Excerpt. 249 249 if ( ! empty( $post->post_excerpt ) ) { 250 250 $description = xml_find( $items[ $key ]['child'], 'description' ); … … 252 252 } 253 253 254 // Post content 254 // Post content. 255 255 if ( ! $this->excerpt_only ) { 256 256 $content = xml_find( $items[ $key ]['child'], 'content:encoded' ); … … 258 258 } 259 259 260 // Comment rss260 // Comment RSS. 261 261 $comment_rss = xml_find( $items[ $key ]['child'], 'wfw:commentRss' ); 262 262 $this->assertEquals( html_entity_decode( get_post_comments_feed_link( $post->ID ) ), $comment_rss[0]['content'] ); … … 274 274 $xml = xml_to_array( $feed ); 275 275 276 // get all the rss -> channel -> item elements276 // Get all the rss -> channel -> item elements. 277 277 $items = xml_find( $xml, 'rss', 'channel', 'item' ); 278 278 279 // check each of the items against the known post data279 // Check each of the items against the known post data. 280 280 foreach ( $items as $key => $item ) { 281 // Get post for comparison 281 // Get post for comparison. 282 282 $guid = xml_find( $items[ $key ]['child'], 'guid' ); 283 283 preg_match( '/\?p=(\d+)/', $guid[0]['content'], $matches ); 284 284 $post = get_post( $matches[1] ); 285 285 286 // comment link286 // Comment link. 287 287 $comments_link = xml_find( $items[ $key ]['child'], 'comments' ); 288 288 $this->assertEmpty( $comments_link ); 289 289 290 // comment rss290 // Comment RSS. 291 291 $comment_rss = xml_find( $items[ $key ]['child'], 'wfw:commentRss' ); 292 292 $this->assertEmpty( $comment_rss ); … … 359 359 */ 360 360 function test_valid_main_comment_feed_endpoint() { 361 // Generate a bunch of comments 361 // Generate a bunch of comments. 362 362 foreach ( self::$posts as $post ) { 363 363 self::factory()->comment->create_post_comments( $post, 3 ); … … 448 448 */ 449 449 function test_valid_search_feed_endpoint() { 450 // An example of an valid search feed endpoint 450 // An example of an valid search feed endpoint. 451 451 $this->go_to( '?s=Lorem&feed=rss' ); 452 452
Note: See TracChangeset
for help on using the changeset viewer.