From 447550ec7b3c9dbe5d27c617f4666fe27f2bf5c6 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 24 Jun 2015 00:42:33 +0000 Subject: [PATCH] Implement tests for the `upload_mimes` filter to ensure it prevents the upload of disallowed file types. See #32693 git-svn-id: https://develop.svn.wordpress.org/trunk@32919 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/post/attachments.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/phpunit/tests/post/attachments.php b/tests/phpunit/tests/post/attachments.php index 6c922b9747..f33e7cd816 100644 --- a/tests/phpunit/tests/post/attachments.php +++ b/tests/phpunit/tests/post/attachments.php @@ -500,8 +500,30 @@ class Tests_Post_Attachments extends WP_UnitTestCase { } } + public function test_upload_mimes_filter_is_applied() { + $filename = DIR_TESTDATA . '/images/test-image.jpg'; + $contents = file_get_contents( $filename ); + + $upload = wp_upload_bits( basename( $filename ), null, $contents ); + + $this->assertFalse( $upload['error'] ); + + add_filter( 'upload_mimes', array( $this, 'blacklist_jpg_mime_type' ) ); + + $upload = wp_upload_bits( basename( $filename ), null, $contents ); + + $this->assertNotEmpty( $upload['error'] ); + + remove_filter( 'upload_mimes', array( $this, 'blacklist_jpg_mime_type' ) ); + } + public function whitelist_psd_mime_type( $mimes ) { $mimes['psd'] = 'application/octet-stream'; return $mimes; } + + public function blacklist_jpg_mime_type( $mimes ) { + unset( $mimes['jpg|jpeg|jpe'] ); + return $mimes; + } }