Changeset 42343 for trunk/tests/phpunit/tests/feed/rss2.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/feed/rss2.php
r40523 r42343 20 20 public static function wpSetUpBeforeClass( $factory ) { 21 21 // Create a user 22 self::$user_id = $factory->user->create( array( 23 'role' => 'author', 24 'user_login' => 'test_author', 25 'display_name' => 'Test A. Uthor', 26 ) ); 22 self::$user_id = $factory->user->create( 23 array( 24 'role' => 'author', 25 'user_login' => 'test_author', 26 'display_name' => 'Test A. Uthor', 27 ) 28 ); 27 29 28 30 // Create a taxonomy 29 self::$category = $factory->category->create_and_get( array( 30 'name' => 'Foo Category', 31 'slug' => 'foo', 32 ) ); 31 self::$category = $factory->category->create_and_get( 32 array( 33 'name' => 'Foo Category', 34 'slug' => 'foo', 35 ) 36 ); 33 37 34 38 // Set a predictable time for testing date archives. … … 38 42 39 43 // Create a few posts 40 self::$posts = $factory->post->create_many( $count, array( 41 'post_author' => self::$user_id, 42 'post_date' => self::$post_date, 43 '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.', 44 'post_excerpt' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 45 ) ); 44 self::$posts = $factory->post->create_many( 45 $count, array( 46 'post_author' => self::$user_id, 47 'post_date' => self::$post_date, 48 '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.', 49 'post_excerpt' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 50 ) 51 ); 46 52 47 53 // Assign a category to those posts … … 57 63 parent::setUp(); 58 64 59 $this->post_count = (int) get_option( 'posts_per_rss' );65 $this->post_count = (int) get_option( 'posts_per_rss' ); 60 66 $this->excerpt_only = get_option( 'rss_use_excerpt' ); 61 67 // this seems to break something … … 74 80 global $post; 75 81 try { 76 @require( ABSPATH . 'wp-includes/feed-rss2.php');82 @require( ABSPATH . 'wp-includes/feed-rss2.php' ); 77 83 $out = ob_get_clean(); 78 } catch ( Exception $e) {84 } catch ( Exception $e ) { 79 85 $out = ob_get_clean(); 80 86 throw($e); … … 90 96 $this->go_to( '/?feed=rss2' ); 91 97 $feed = $this->do_rss2(); 92 $xml = xml_to_array( $feed );98 $xml = xml_to_array( $feed ); 93 99 94 100 // Get the <rss> child element of <xml>. … … 109 115 /** 110 116 * [test_channel_element description] 117 * 111 118 * @return [type] [description] 112 119 */ … … 114 121 $this->go_to( '/?feed=rss2' ); 115 122 $feed = $this->do_rss2(); 116 $xml = xml_to_array( $feed );123 $xml = xml_to_array( $feed ); 117 124 118 125 // get the rss -> channel element … … 138 145 /** 139 146 * Test that translated feeds have a valid listed date. 147 * 140 148 * @group 39141 141 149 */ … … 145 153 $locale = clone $GLOBALS['wp_locale']; 146 154 147 $locale->weekday[2] = 'Tuesday_Translated';148 $locale->weekday_abbrev[ 'Tuesday_Translated'] = 'Tue_Translated';155 $locale->weekday[2] = 'Tuesday_Translated'; 156 $locale->weekday_abbrev['Tuesday_Translated'] = 'Tue_Translated'; 149 157 150 158 $GLOBALS['wp_locale'] = $locale; … … 166 174 $this->go_to( '/?feed=rss2' ); 167 175 $feed = $this->do_rss2(); 168 $xml = xml_to_array( $feed );176 $xml = xml_to_array( $feed ); 169 177 170 178 // Get all the <item> child elements of the <channel> element … … 181 189 182 190 // Get post for comparison 183 $guid = xml_find( $items[ $key]['child'], 'guid' );191 $guid = xml_find( $items[ $key ]['child'], 'guid' ); 184 192 preg_match( '/\?p=(\d+)/', $guid[0]['content'], $matches ); 185 193 $post = get_post( $matches[1] ); 186 194 187 195 // Title 188 $title = xml_find( $items[ $key]['child'], 'title' );196 $title = xml_find( $items[ $key ]['child'], 'title' ); 189 197 $this->assertEquals( $post->post_title, $title[0]['content'] ); 190 198 191 199 // Link 192 $link = xml_find( $items[ $key]['child'], 'link' );200 $link = xml_find( $items[ $key ]['child'], 'link' ); 193 201 $this->assertEquals( get_permalink( $post ), $link[0]['content'] ); 194 202 195 203 // Comment link 196 $comments_link = xml_find( $items[ $key]['child'], 'comments' );204 $comments_link = xml_find( $items[ $key ]['child'], 'comments' ); 197 205 $this->assertEquals( get_permalink( $post ) . '#respond', $comments_link[0]['content'] ); 198 206 199 207 // Pub date 200 $pubdate = xml_find( $items[ $key]['child'], 'pubDate' );208 $pubdate = xml_find( $items[ $key ]['child'], 'pubDate' ); 201 209 $this->assertEquals( strtotime( $post->post_date_gmt ), strtotime( $pubdate[0]['content'] ) ); 202 210 203 211 // Author 204 $creator = xml_find( $items[ $key]['child'], 'dc:creator' );205 $user = new WP_User( $post->post_author );212 $creator = xml_find( $items[ $key ]['child'], 'dc:creator' ); 213 $user = new WP_User( $post->post_author ); 206 214 $this->assertEquals( $user->display_name, $creator[0]['content'] ); 207 215 208 216 // Categories (perhaps multiple) 209 $categories = xml_find( $items[ $key]['child'], 'category' );210 $cats = array();217 $categories = xml_find( $items[ $key ]['child'], 'category' ); 218 $cats = array(); 211 219 foreach ( get_the_category( $post->ID ) as $term ) { 212 220 $cats[] = $term->name; … … 225 233 // ..with the same names 226 234 foreach ( $cats as $id => $cat ) { 227 $this->assertEquals( $cat, $categories[ $id]['content'] );235 $this->assertEquals( $cat, $categories[ $id ]['content'] ); 228 236 } 229 237 230 238 // GUID 231 $guid = xml_find( $items[ $key]['child'], 'guid' );239 $guid = xml_find( $items[ $key ]['child'], 'guid' ); 232 240 $this->assertEquals( 'false', $guid[0]['attributes']['isPermaLink'] ); 233 241 $this->assertEquals( $post->guid, $guid[0]['content'] ); … … 235 243 // Description / Excerpt 236 244 if ( ! empty( $post->post_excerpt ) ) { 237 $description = xml_find( $items[ $key]['child'], 'description' );245 $description = xml_find( $items[ $key ]['child'], 'description' ); 238 246 $this->assertEquals( trim( $post->post_excerpt ), trim( $description[0]['content'] ) ); 239 247 } … … 241 249 // Post content 242 250 if ( ! $this->excerpt_only ) { 243 $content = xml_find( $items[ $key]['child'], 'content:encoded' );251 $content = xml_find( $items[ $key ]['child'], 'content:encoded' ); 244 252 $this->assertEquals( trim( apply_filters( 'the_content', $post->post_content ) ), trim( $content[0]['content'] ) ); 245 253 } 246 254 247 255 // Comment rss 248 $comment_rss = xml_find( $items[ $key]['child'], 'wfw:commentRss' );256 $comment_rss = xml_find( $items[ $key ]['child'], 'wfw:commentRss' ); 249 257 $this->assertEquals( html_entity_decode( get_post_comments_feed_link( $post->ID ) ), $comment_rss[0]['content'] ); 250 258 } … … 259 267 $this->go_to( '/?feed=rss2' ); 260 268 $feed = $this->do_rss2(); 261 $xml = xml_to_array( $feed );269 $xml = xml_to_array( $feed ); 262 270 263 271 // get all the rss -> channel -> item elements … … 267 275 foreach ( $items as $key => $item ) { 268 276 // Get post for comparison 269 $guid = xml_find( $items[ $key]['child'], 'guid' );277 $guid = xml_find( $items[ $key ]['child'], 'guid' ); 270 278 preg_match( '/\?p=(\d+)/', $guid[0]['content'], $matches ); 271 279 $post = get_post( $matches[1] );
Note: See TracChangeset
for help on using the changeset viewer.