Ticket #41905: 41905.7.diff
File 41905.7.diff, 8.0 KB (added by , 7 years ago) |
---|
-
src/wp-includes/feed.php
diff --git src/wp-includes/feed.php src/wp-includes/feed.php index 731b66e..b722ea8 100644
function html_type_rss() { 449 449 * the user has the password for the post. If not then it will return before 450 450 * displaying. 451 451 * 452 * Also uses the function get_post_ custom() to get the post's 'enclosure'452 * Also uses the function get_post_meta() to get the post's 'enclosure' 453 453 * metadata field and parses the value to display the enclosure(s). The 454 454 * enclosure(s) consist of enclosure HTML tag(s) with a URI and other 455 455 * attributes. … … function rss_enclosure() { 460 460 if ( post_password_required() ) 461 461 return; 462 462 463 foreach ( (array) get_post_custom() as $key => $val) {464 if ($key == 'enclosure') { 465 foreach ( (array) $val as $enc) {466 $enclosure = explode("\n", $enc);467 468 // only get the first element, e.g. audio/mpeg from 'audio/mpeg mpga mp2 mp3' 469 $t = preg_split('/[ \t]/', trim($enclosure[2]) );470 $type = $t[0];471 472 /** 473 * Filters the RSS enclosure HTML link tag for the current post.474 *475 * @since 2.2.0476 *477 * @param string $html_link_tag The HTML link tag with a URI and other attributes.478 */479 echo apply_filters( 'rss_enclosure', '<enclosure url="' . trim( htmlspecialchars( $enclosure[0] ) ) . '" length="' . trim( $enclosure[1] ) . '" type="' . $type . '" />' . "\n" );480 }463 $meta_enclosures = get_post_meta( get_the_ID(), 'enclosure', false ); 464 465 foreach ( (array) $meta_enclosures as $key => $val ) { 466 foreach ( (array) $val as $enc ) { 467 $enclosure = explode( "\n", $enc ); 468 469 // Only get the first element, e.g. audio/mpeg from 'audio/mpeg mpga mp2 mp3'. 470 $t = preg_split( '/[ \t]/', trim( $enclosure[2] ) ); 471 $type = $t[0]; 472 473 /** 474 * Filters the RSS enclosure HTML link tag for the current post. 475 * 476 * @since 2.2.0 477 * 478 * @param string $html_link_tag The HTML link tag with a URI and other attributes. 479 */ 480 echo apply_filters( 'rss_enclosure', '<enclosure url="' . trim( htmlspecialchars( $enclosure[0] ) ) . '" length="' . trim( $enclosure[1] ) . '" type="' . $type . '" />' . "\n" ); 481 481 } 482 482 } 483 483 } … … function rss_enclosure() { 489 489 * the user has the password for the post. If not then it will return before 490 490 * displaying. 491 491 * 492 * Also uses the function get_post_ custom() to get the post's 'enclosure'492 * Also uses the function get_post_meta() to get the post's 'enclosure' 493 493 * metadata field and parses the value to display the enclosure(s). The 494 494 * enclosure(s) consist of link HTML tag(s) with a URI and other attributes. 495 495 * … … function atom_enclosure() { 499 499 if ( post_password_required() ) 500 500 return; 501 501 502 foreach ( (array) get_post_custom() as $key => $val ) { 503 if ($key == 'enclosure') { 504 foreach ( (array) $val as $enc ) { 505 $enclosure = explode("\n", $enc); 506 /** 507 * Filters the atom enclosure HTML link tag for the current post. 508 * 509 * @since 2.2.0 510 * 511 * @param string $html_link_tag The HTML link tag with a URI and other attributes. 512 */ 513 echo apply_filters( 'atom_enclosure', '<link href="' . trim( htmlspecialchars( $enclosure[0] ) ) . '" rel="enclosure" length="' . trim( $enclosure[1] ) . '" type="' . trim( $enclosure[2] ) . '" />' . "\n" ); 514 } 502 $meta_enclosures = get_post_meta( get_the_ID(), 'enclosure', false ); 503 504 foreach ( (array) $meta_enclosures as $key => $val ) { 505 foreach ( (array) $val as $enc ) { 506 $enclosure = explode( "\n", $enc ); 507 508 /** 509 * Filters the atom enclosure HTML link tag for the current post. 510 * 511 * @since 2.2.0 512 * 513 * @param string $html_link_tag The HTML link tag with a URI and other attributes. 514 */ 515 echo apply_filters( 'atom_enclosure', '<link href="' . trim( htmlspecialchars( $enclosure[0] ) ) . '" rel="enclosure" length="' . trim( $enclosure[1] ) . '" type="' . trim( $enclosure[2] ) . '" />' . "\n" ); 515 516 } 516 517 } 517 518 } -
tests/phpunit/tests/feed/atom.php
diff --git tests/phpunit/tests/feed/atom.php tests/phpunit/tests/feed/atom.php index fbe064b..aad5223 100644
class Tests_Feeds_Atom extends WP_UnitTestCase { 197 197 } 198 198 } 199 199 } 200 201 /** 202 * Tests atom_enclosures(). 203 * 204 * @ticket 41905 205 * @param array $meta_enclosures Meta enclosures. 206 * @param string $expect Expected value. 207 * 208 * @dataProvider data_test_atom_enclosures 209 */ 210 public function test_atom_enclosures( $meta_enclosures, $expect ) { 211 // Latest post ID. 212 $post_id = end( self::$posts ); 213 214 // Add enclosure meta. 215 foreach ( $meta_enclosures as $meta_enclosure ) { 216 add_post_meta( $post_id, 'enclosure', $meta_enclosure ); 217 } 218 219 // Setup global post object used by atom_enclosure(). 220 $GLOBALS['post'] = get_post( $post_id ); 221 222 // Atom enclosure. 223 atom_enclosure(); 224 225 // Cleanup. 226 unset( $GLOBALS['post'] ); 227 228 // Test output. 229 $this->expectOutputString( $expect ); 230 } 231 232 /** 233 * Dataprovider for test_atom_enclosures(). 234 * 235 * @ticket 42254 236 * 237 * @return array { 238 * @type array $0... { 239 * @type array $0 Meta enclosures. 240 * @type string $1 Expected value. 241 * } 242 * } 243 */ 244 public function data_test_atom_enclosures() { 245 return array( 246 array( 247 array( 248 "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465\nvideo/mp4", 249 ), 250 '<link href="https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4" rel="enclosure" length="318465" type="video/mp4" />' . "\n", 251 ), 252 array( 253 array( 254 "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465\nvideo/mp4", 255 "https://wordpress.dev/wp-content/uploads/2017/01/audio.mp3\n48934\naudio/mpeg", 256 ), 257 '<link href="https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4" rel="enclosure" length="318465" type="video/mp4" />' . "\n" 258 . '<link href="https://wordpress.dev/wp-content/uploads/2017/01/audio.mp3" rel="enclosure" length="48934" type="audio/mpeg" />' . "\n", 259 ), 260 ); 261 } 262 200 263 } -
tests/phpunit/tests/feed/rss2.php
diff --git tests/phpunit/tests/feed/rss2.php tests/phpunit/tests/feed/rss2.php index f0d7919..29b9539 100644
class Tests_Feeds_RSS2 extends WP_UnitTestCase { 454 454 // There should only be one <rss> child element. 455 455 $this->assertEquals( 1, count( $rss ) ); 456 456 } 457 458 /** 459 * Tests rss_enclosures() 460 * 461 * @ticket 41905 462 * @param array $meta_enclosures Meta enclosures. 463 * @param string $expect Expected value. 464 * 465 * @dataProvider data_test_rss_enclosures 466 */ 467 public function test_rss_enclosures( $meta_enclosures, $expect ) { 468 // Latest post ID. 469 $post_id = end( self::$posts ); 470 471 // Add enclosure meta. 472 foreach ( $meta_enclosures as $meta_enclosure ) { 473 add_post_meta( $post_id, 'enclosure', $meta_enclosure ); 474 } 475 476 // Setup global post object used by rss_enclosure(). 477 $GLOBALS['post'] = get_post( $post_id ); 478 479 // RSS enclosure. 480 rss_enclosure(); 481 482 // Cleanup. 483 unset( $GLOBALS['post'] ); 484 485 // Test output. 486 $this->expectOutputString( $expect ); 487 } 488 489 /** 490 * Dataprovider for test_atom_enclosures(). 491 * 492 * @ticket 42254 493 * 494 * @return array { 495 * @type array $0... { 496 * @type array $0 Meta enclosures. 497 * @type string $1 Expected value. 498 * } 499 * } 500 */ 501 public function data_test_rss_enclosures() { 502 return array( 503 array( 504 array( 505 "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465\nvideo/mp4", 506 ), 507 '<enclosure url="https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4" length="318465" type="video/mp4" />' . "\n", 508 ), 509 array( 510 array( 511 "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465\nvideo/mp4", 512 "https://wordpress.dev/wp-content/uploads/2017/01/audio.mp3\n48934\naudio/mpeg", 513 ), 514 '<enclosure url="https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4" length="318465" type="video/mp4" />' . "\n" 515 . '<enclosure url="https://wordpress.dev/wp-content/uploads/2017/01/audio.mp3" length="48934" type="audio/mpeg" />' . "\n", 516 ), 517 ); 518 } 457 519 }