Ticket #43658: 43658.diff
File 43658.diff, 3.0 KB (added by , 6 years ago) |
---|
-
src/wp-includes/media.php
diff --git src/wp-includes/media.php src/wp-includes/media.php index ace9021fd7..f0dad7d8d4 100644
function wp_enqueue_media( $args = array() ) { 3576 3576 $month_year->text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month_year->month ), $month_year->year ); 3577 3577 } 3578 3578 3579 // Filter to show only available mime types. 3580 $avail_post_mime_types = get_available_post_mime_types( 'attachment' ); 3581 $mimeTypes = wp_list_pluck( get_post_mime_types(), 0 ); 3582 foreach ( $mimeTypes as $mime_type => $label ) { 3583 if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) { 3584 unset( $mimeTypes[ $mime_type ] ); 3585 } 3586 } 3579 3587 $settings = array( 3580 3588 'tabs' => $tabs, 3581 3589 'tabUrl' => add_query_arg( array( 'chromeless' => true ), admin_url( 'media-upload.php' ) ), 3582 'mimeTypes' => wp_list_pluck( get_post_mime_types(), 0 ),3590 'mimeTypes' => $mimeTypes, 3583 3591 /** This filter is documented in wp-admin/includes/media.php */ 3584 3592 'captions' => ! apply_filters( 'disable_captions', '' ), 3585 3593 'nonce' => array( -
tests/phpunit/tests/functions.php
diff --git tests/phpunit/tests/functions.php tests/phpunit/tests/functions.php index 88b9a46475..839fc988ec 100644
class Tests_Functions extends WP_UnitTestCase { 465 465 $this->assertNotEmpty( $mimes ); 466 466 } 467 467 468 /** 469 * Test that the media grid uses the correct available single media type. 470 * @ticket 43658 471 */ 472 function test_wp_enqueue_media_single_mime_type() { 473 $filename = DIR_TESTDATA . '/images/test-image.jpg'; 474 $contents = file_get_contents( $filename ); 475 $upload = wp_upload_bits( basename( $filename ), null, $contents ); 476 $attachment_id = $this->_make_attachment( $upload ); 477 478 add_filter( 479 'media_view_settings', 480 function( $settings ) { 481 $this->assertEquals( array( 'image' ), array_keys( $settings['mimeTypes'] ) ); 482 return $settings; 483 } 484 ); 485 wp_enqueue_media(); 486 remove_all_filters( 'media_view_settings' ); 487 } 488 489 /** 490 * Test that the media grid uses the correct available multiple media types. 491 * @ticket 43658 492 */ 493 function test_wp_enqueue_media_multiple_mime_types() { 494 $filename = DIR_TESTDATA . '/images/test-image.jpg'; 495 $contents = file_get_contents( $filename ); 496 $upload = wp_upload_bits( basename( $filename ), null, $contents ); 497 $attachment_id = $this->_make_attachment( $upload ); 498 499 $filename = DIR_TESTDATA . '/uploads/small-audio.mp3'; 500 $contents = file_get_contents( $filename ); 501 $upload = wp_upload_bits( basename( $filename ), null, $contents ); 502 $attachment_id = $this->_make_attachment( $upload ); 503 504 add_filter( 505 'media_view_settings', 506 function( $settings ) { 507 $this->assertEquals( array( 'image', 'audio' ), array_keys( $settings['mimeTypes'] ) ); 508 return $settings; 509 } 510 ); 511 wp_enqueue_media(); 512 } 513 468 514 /** 469 515 * @ticket 21594 470 516 */