Make WordPress Core

Changeset 40125


Ignore:
Timestamp:
02/26/2017 04:05:25 PM (10 years ago)
Author:
joemcgill
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions.php

    r40124 r40125  
    932932         */
    933933        function test_wp_check_filetype_and_ext_with_filtered_svg() {
     934                if ( ! extension_loaded( 'fileinfo' ) ) {
     935                        $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
     936                }
     937
     938                if ( is_multisite() ) {
     939                        $this->markTestSkipped( 'Test does not run in multisite' );
     940                }
     941
    934942                $file = DIR_TESTDATA . '/uploads/video-play.svg';
    935943                $filename = 'video-play.svg';
    … …  
    952960         */
    953961        function test_wp_check_filetype_and_ext_with_filtered_woff() {
     962                if ( ! extension_loaded( 'fileinfo' ) ) {
     963                        $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
     964                }
     965
     966                if ( is_multisite() ) {
     967                        $this->markTestSkipped( 'Test does not run in multisite' );
     968                }
     969
    954970                $file = DIR_TESTDATA . '/uploads/dashicons.woff';
    955971                $filename = 'dashicons.woff';
    … …  
    979995
    980996        public function _wp_check_filetype_and_ext_data() {
    981                 return array(
     997                $data = array(
    982998                        // Standard image.
    983999                        array(
    … …  
    10201036                                ),
    10211037                        ),
    1022                         // Standard non-image file.
    1023                         array(
    1024                                 DIR_TESTDATA . '/formatting/big5.txt',
    1025                                 'big5.txt',
    1026                                 array(
    1027                                         'ext' => 'txt',
    1028                                         'type' => 'text/plain',
    1029                                         'proper_filename' => false,
    1030                                 ),
    1031                         ),
    1032                         // Non-image file with wrong sub-type.
    1033                         array(
    1034                                 DIR_TESTDATA . '/uploads/pages-to-word.docx',
    1035                                 'pages-to-word.docx',
    1036                                 array(
    1037                                         'ext' => 'docx',
    1038                                         'type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
    1039                                         'proper_filename' => false,
    1040                                 ),
    1041                         ),
    10421038                        // Non-image file not allowed.
    10431039                        array(
    … …  
    10511047                        ),
    10521048                );
     1049
     1050                // Test a few additional file types on single sites.
     1051                if ( ! is_multisite() ) {
     1052                        $data = array_merge( $data, array(
     1053                                // Standard non-image file.
     1054                                array(
     1055                                        DIR_TESTDATA . '/formatting/big5.txt',
     1056                                        'big5.txt',
     1057                                        array(
     1058                                                'ext' => 'txt',
     1059                                                'type' => 'text/plain',
     1060                                                'proper_filename' => false,
     1061                                        ),
     1062                                ),
     1063                                // Non-image file with wrong sub-type.
     1064                                array(
     1065                                        DIR_TESTDATA . '/uploads/pages-to-word.docx',
     1066                                        'pages-to-word.docx',
     1067                                        array(
     1068                                                'ext' => 'docx',
     1069                                                'type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
     1070                                                'proper_filename' => false,
     1071                                        ),
     1072                                ),
     1073                        ) );
     1074                }
     1075
     1076                return $data;
    10531077        }
    10541078}
Note: See TracChangeset for help on using the changeset viewer.