Make WordPress Core

Changeset 32919


Ignore:
Timestamp:
06/24/2015 12:42:33 AM (11 years ago)
Author:
johnbillion
Message:

Implement tests for the upload_mimes filter to ensure it prevents the upload of disallowed file types.

See #32693

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/attachments.php

    r32342 r32919  
    501501        }
    502502
     503        public function test_upload_mimes_filter_is_applied() {
     504                $filename = DIR_TESTDATA . '/images/test-image.jpg';
     505                $contents = file_get_contents( $filename );
     506
     507                $upload = wp_upload_bits( basename( $filename ), null, $contents );
     508
     509                $this->assertFalse( $upload['error'] );
     510
     511                add_filter( 'upload_mimes', array( $this, 'blacklist_jpg_mime_type' ) );
     512
     513                $upload = wp_upload_bits( basename( $filename ), null, $contents );
     514
     515                $this->assertNotEmpty( $upload['error'] );
     516
     517                remove_filter( 'upload_mimes', array( $this, 'blacklist_jpg_mime_type' ) );
     518        }
     519
    503520        public function whitelist_psd_mime_type( $mimes ) {
    504521                $mimes['psd'] = 'application/octet-stream';
    505522                return $mimes;
    506523        }
     524
     525        public function blacklist_jpg_mime_type( $mimes ) {
     526                unset( $mimes['jpg|jpeg|jpe'] );
     527                return $mimes;
     528        }
    507529}
Note: See TracChangeset for help on using the changeset viewer.