Ticket #41905: 41905.9.diff
File 41905.9.diff, 8.8 KB (added by , 6 years ago) |
---|
-
src/wp-includes/feed.php
diff --git src/wp-includes/feed.php src/wp-includes/feed.php index c8f5fd5..e1b41bc 100644
function html_type_rss() { 455 455 /** 456 456 * Display the rss enclosure for the current post. 457 457 * 458 * Uses the global $postto check whether the post requires a password and if458 * Uses the global `$post` to check whether the post requires a password and if 459 459 * the user has the password for the post. If not then it will return before 460 460 * displaying. 461 461 * 462 * Also uses the function get_post_ custom() to get the post's 'enclosure'462 * Also uses the function get_post_meta() to get the post's 'enclosure' 463 463 * metadata field and parses the value to display the enclosure(s). The 464 464 * enclosure(s) consist of enclosure HTML tag(s) with a URI and other 465 465 * attributes. … … function rss_enclosure() { 471 471 return; 472 472 } 473 473 474 foreach ( (array) get_post_custom() as $key => $val ) {475 if ( $key == 'enclosure' ) { 476 foreach ( (array) $val as $enc) {477 $enclosure = explode( "\n", $enc );478 479 // only get the first element, e.g. audio/mpeg from 'audio/mpeg mpga mp2 mp3' 480 $t = preg_split( '/[ \t]/', trim( $enclosure[2] ) );481 $type = $t[0];482 483 /** 484 * Filters the RSS enclosure HTML link tag for the current post.485 *486 * @since 2.2.0487 *488 * @param string $html_link_tag The HTML link tag with a URI and other attributes.489 */490 echo apply_filters( 'rss_enclosure', '<enclosure url="' . esc_url( trim( $enclosure[0] ) ) . '" length="' . absint( trim( $enclosure[1] ) ) . '" type="' . esc_attr( $type ) . '" />' . "\n" );491 }474 $meta_enclosures = get_post_meta( get_the_ID(), 'enclosure', false ); 475 476 foreach ( (array) $meta_enclosures as $key => $val ) { 477 foreach ( (array) $val as $enc ) { 478 $enclosure = explode( "\n", $enc ); 479 480 // Only get the first element, e.g. audio/mpeg from 'audio/mpeg mpga mp2 mp3'. 481 $t = preg_split( '/[ \t]/', trim( $enclosure[2] ) ); 482 $type = $t[0]; 483 484 /** 485 * Filters the RSS enclosure HTML link tag for the current post. 486 * 487 * @since 2.2.0 488 * 489 * @param string $html_link_tag The HTML link tag with a URI and other attributes. 490 */ 491 echo apply_filters( 'rss_enclosure', '<enclosure url="' . esc_url( trim( $enclosure[0] ) ) . '" length="' . absint( trim( $enclosure[1] ) ) . '" type="' . esc_attr( $type ) . '" />' . "\n" ); 492 492 } 493 493 } 494 494 } … … function rss_enclosure() { 496 496 /** 497 497 * Display the atom enclosure for the current post. 498 498 * 499 * Uses the global $postto check whether the post requires a password and if499 * Uses the global `$post` to check whether the post requires a password and if 500 500 * the user has the password for the post. If not then it will return before 501 501 * displaying. 502 502 * 503 * Also uses the function get_post_ custom() to get the post's 'enclosure'503 * Also uses the function get_post_meta() to get the post's 'enclosure' 504 504 * metadata field and parses the value to display the enclosure(s). The 505 505 * enclosure(s) consist of link HTML tag(s) with a URI and other attributes. 506 506 * … … function atom_enclosure() { 511 511 return; 512 512 } 513 513 514 foreach ( (array) get_post_custom() as $key => $val ) { 515 if ( $key == 'enclosure' ) { 516 foreach ( (array) $val as $enc ) { 517 $enclosure = explode( "\n", $enc ); 518 /** 519 * Filters the atom enclosure HTML link tag for the current post. 520 * 521 * @since 2.2.0 522 * 523 * @param string $html_link_tag The HTML link tag with a URI and other attributes. 524 */ 525 echo apply_filters( 'atom_enclosure', '<link href="' . esc_url( trim( $enclosure[0] ) ) . '" rel="enclosure" length="' . absint( trim( $enclosure[1] ) ) . '" type="' . esc_attr( trim( $enclosure[2] ) ) . '" />' . "\n" ); 526 } 514 $meta_enclosures = get_post_meta( get_the_ID(), 'enclosure', false ); 515 516 foreach ( (array) $meta_enclosures as $key => $val ) { 517 foreach ( (array) $val as $enc ) { 518 $enclosure = explode( "\n", $enc ); 519 520 /** 521 * Filters the atom enclosure HTML link tag for the current post. 522 * 523 * @since 2.2.0 524 * 525 * @param string $html_link_tag The HTML link tag with a URI and other attributes. 526 */ 527 echo apply_filters( 'atom_enclosure', '<link href="' . esc_url( trim( $enclosure[0] ) ) . '" rel="enclosure" length="' . absint( trim( $enclosure[1] ) ) . '" type="' . esc_attr( trim( $enclosure[2] ) ) . '" />' . "\n" ); 527 528 } 528 529 } 529 530 } -
tests/phpunit/tests/feed/atom.php
diff --git tests/phpunit/tests/feed/atom.php tests/phpunit/tests/feed/atom.php index 9d6e3f8..e8b3f07 100644
class Tests_Feeds_Atom extends WP_UnitTestCase { 204 204 } 205 205 } 206 206 } 207 208 /** 209 * Tests atom_enclosures(). 210 * 211 * @ticket 41905 212 * 213 * @param array $meta_enclosures Meta enclosures. 214 * @param string $expect Expected value. 215 * 216 * @dataProvider data_test_atom_enclosures 217 */ 218 public function test_atom_enclosures( $meta_enclosures, $expect ) { 219 // Latest post ID. 220 $post_id = end( self::$posts ); 221 222 // Add enclosure meta. 223 foreach ( (array) $meta_enclosures as $meta_enclosure ) { 224 add_post_meta( $post_id, 'enclosure', $meta_enclosure ); 225 } 226 227 // Setup global post object used by atom_enclosure(). 228 $GLOBALS['post'] = get_post( $post_id ); 229 230 // Atom enclosure. 231 atom_enclosure(); 232 233 // Cleanup. 234 unset( $GLOBALS['post'] ); 235 236 // Test output. 237 $this->expectOutputString( $expect ); 238 } 239 240 /** 241 * Dataprovider for test_atom_enclosures(). 242 * 243 * @ticket 42254 244 * 245 * @return array { 246 * @type array { 247 * @type array $meta_enclosures Meta enclosures. 248 * @type string $expect Expected value. 249 * } 250 * } 251 */ 252 public function data_test_atom_enclosures() { 253 return array( 254 // No enclosures. 255 array( 256 array(), 257 '', 258 ), 259 // Single enclosure. 260 array( 261 array( 262 "https://wordpress.test/wp-content/uploads/2017/09/movie.mp4\n318465\nvideo/mp4", 263 ), 264 '<link href="https://wordpress.test/wp-content/uploads/2017/09/movie.mp4" rel="enclosure" length="318465" type="video/mp4" />' . "\n", 265 ), 266 // Multiple enclosures. 267 array( 268 array( 269 "https://wordpress.test/wp-content/uploads/2017/09/movie.mp4\n318465\nvideo/mp4", 270 "https://wordpress.test/wp-content/uploads/2017/01/audio.mp3\n48934\naudio/mpeg", 271 ), 272 '<link href="https://wordpress.test/wp-content/uploads/2017/09/movie.mp4" rel="enclosure" length="318465" type="video/mp4" />' . "\n" 273 . '<link href="https://wordpress.test/wp-content/uploads/2017/01/audio.mp3" rel="enclosure" length="48934" type="audio/mpeg" />' . "\n", 274 ), 275 ); 276 } 277 207 278 } -
tests/phpunit/tests/feed/rss2.php
diff --git tests/phpunit/tests/feed/rss2.php tests/phpunit/tests/feed/rss2.php index 79be2fc..bd2a660 100644
class Tests_Feeds_RSS2 extends WP_UnitTestCase { 463 463 // There should only be one <rss> child element. 464 464 $this->assertEquals( 1, count( $rss ) ); 465 465 } 466 467 /** 468 * Tests rss_enclosures(). 469 * 470 * @ticket 41905 471 * 472 * @param array $meta_enclosures Meta enclosures. 473 * @param string $expect Expected value. 474 * 475 * @dataProvider data_test_rss_enclosures 476 */ 477 public function test_rss_enclosures( $meta_enclosures, $expect ) { 478 // Latest post ID. 479 $post_id = end( self::$posts ); 480 481 // Add enclosure meta. 482 foreach ( (array) $meta_enclosures as $meta_enclosure ) { 483 add_post_meta( $post_id, 'enclosure', $meta_enclosure ); 484 } 485 486 // Setup global post object used by rss_enclosure(). 487 $GLOBALS['post'] = get_post( $post_id ); 488 489 // RSS enclosure. 490 rss_enclosure(); 491 492 // Cleanup. 493 unset( $GLOBALS['post'] ); 494 495 // Test output. 496 $this->expectOutputString( $expect ); 497 } 498 499 /** 500 * Dataprovider for test_rss_enclosures(). 501 * 502 * @ticket 42254 503 * 504 * @return array { 505 * @type array { 506 * @type array $meta_enclosures Meta enclosures. 507 * @type string $expect Expected value. 508 * } 509 * } 510 */ 511 public function data_test_rss_enclosures() { 512 return array( 513 // No enclosures. 514 array( 515 array(), 516 '', 517 ), 518 // Single enclosure. 519 array( 520 array( 521 "https://wordpress.test/wp-content/uploads/2017/09/movie.mp4\n318465\nvideo/mp4", 522 ), 523 '<enclosure url="https://wordpress.test/wp-content/uploads/2017/09/movie.mp4" length="318465" type="video/mp4" />' . "\n", 524 ), 525 // Multiple enclosures. 526 array( 527 array( 528 "https://wordpress.test/wp-content/uploads/2017/09/movie.mp4\n318465\nvideo/mp4", 529 "https://wordpress.test/wp-content/uploads/2017/01/audio.mp3\n48934\naudio/mpeg", 530 ), 531 '<enclosure url="https://wordpress.test/wp-content/uploads/2017/09/movie.mp4" length="318465" type="video/mp4" />' . "\n" 532 . '<enclosure url="https://wordpress.test/wp-content/uploads/2017/01/audio.mp3" length="48934" type="audio/mpeg" />' . "\n", 533 ), 534 ); 535 } 466 536 }