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
This commit is contained in:
parent
8c22c526bd
commit
447550ec7b
@ -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 ) {
|
public function whitelist_psd_mime_type( $mimes ) {
|
||||||
$mimes['psd'] = 'application/octet-stream';
|
$mimes['psd'] = 'application/octet-stream';
|
||||||
return $mimes;
|
return $mimes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function blacklist_jpg_mime_type( $mimes ) {
|
||||||
|
unset( $mimes['jpg|jpeg|jpe'] );
|
||||||
|
return $mimes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user