From 5c99d4ae9ce1b557cb41921a9ed117d1e5c4c10a Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Sun, 26 Feb 2017 16:05:25 +0000 Subject: [PATCH] Media: Fix unit tests for MIME checks on multisite. A few of the multisite tests were failing after [40124] because multisite filters `upload_mimes` with the `check_upload_mimes()` function to reduce the set of allowed MIME types. This fixes those errors by skipping the tests for adding additional MIME types and only tests file types assumed to be allowed. See #39550. git-svn-id: https://develop.svn.wordpress.org/trunk@40125 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/functions.php | 66 +++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index e22eb7ed27..a3aba79c44 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -931,6 +931,14 @@ class Tests_Functions extends WP_UnitTestCase { * @ticket 39550 */ function test_wp_check_filetype_and_ext_with_filtered_svg() { + if ( ! extension_loaded( 'fileinfo' ) ) { + $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' ); + } + + if ( is_multisite() ) { + $this->markTestSkipped( 'Test does not run in multisite' ); + } + $file = DIR_TESTDATA . '/uploads/video-play.svg'; $filename = 'video-play.svg'; @@ -951,6 +959,14 @@ class Tests_Functions extends WP_UnitTestCase { * @ticket 39550 */ function test_wp_check_filetype_and_ext_with_filtered_woff() { + if ( ! extension_loaded( 'fileinfo' ) ) { + $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' ); + } + + if ( is_multisite() ) { + $this->markTestSkipped( 'Test does not run in multisite' ); + } + $file = DIR_TESTDATA . '/uploads/dashicons.woff'; $filename = 'dashicons.woff'; @@ -978,7 +994,7 @@ class Tests_Functions extends WP_UnitTestCase { } public function _wp_check_filetype_and_ext_data() { - return array( + $data = array( // Standard image. array( DIR_TESTDATA . '/images/canola.jpg', @@ -1019,26 +1035,6 @@ class Tests_Functions extends WP_UnitTestCase { 'proper_filename' => false, ), ), - // Standard non-image file. - array( - DIR_TESTDATA . '/formatting/big5.txt', - 'big5.txt', - array( - 'ext' => 'txt', - 'type' => 'text/plain', - 'proper_filename' => false, - ), - ), - // Non-image file with wrong sub-type. - array( - DIR_TESTDATA . '/uploads/pages-to-word.docx', - 'pages-to-word.docx', - array( - 'ext' => 'docx', - 'type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'proper_filename' => false, - ), - ), // Non-image file not allowed. array( DIR_TESTDATA . '/export/crazy-cdata.xml', @@ -1050,5 +1046,33 @@ class Tests_Functions extends WP_UnitTestCase { ), ), ); + + // Test a few additional file types on single sites. + if ( ! is_multisite() ) { + $data = array_merge( $data, array( + // Standard non-image file. + array( + DIR_TESTDATA . '/formatting/big5.txt', + 'big5.txt', + array( + 'ext' => 'txt', + 'type' => 'text/plain', + 'proper_filename' => false, + ), + ), + // Non-image file with wrong sub-type. + array( + DIR_TESTDATA . '/uploads/pages-to-word.docx', + 'pages-to-word.docx', + array( + 'ext' => 'docx', + 'type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'proper_filename' => false, + ), + ), + ) ); + } + + return $data; } }