diff --git a/tests/phpunit/tests/functions/wpCheckFiletype.php b/tests/phpunit/tests/functions/wpCheckFiletype.php new file mode 100644 index 0000000000..ad947c628b --- /dev/null +++ b/tests/phpunit/tests/functions/wpCheckFiletype.php @@ -0,0 +1,111 @@ +assertSame( $expected, wp_check_filetype( $filename, $mimes ) ); + } + + /** + * Data provider. + * + * @return[] + */ + public function data_wp_check_filetype() { + return array( + '.jpg filename and default allowed' => array( + 'filename' => 'canola.jpg', + 'mimes' => null, + 'expected' => array( + 'ext' => 'jpg', + 'type' => 'image/jpeg', + ), + ), + '.jpg filename and jpg|jpeg|jpe' => array( + 'filename' => 'canola.jpg', + 'mimes' => array( + 'jpg|jpeg|jpe' => 'image/jpeg', + 'gif' => 'image/gif', + ), + 'expected' => array( + 'ext' => 'jpg', + 'type' => 'image/jpeg', + ), + ), + '.jpeg filename and jpg|jpeg|jpe' => array( + 'filename' => 'canola.jpeg', + 'mimes' => array( + 'jpg|jpeg|jpe' => 'image/jpeg', + 'gif' => 'image/gif', + ), + 'expected' => array( + 'ext' => 'jpeg', + 'type' => 'image/jpeg', + ), + ), + '.jpe filename and jpg|jpeg|jpe' => array( + 'filename' => 'canola.jpe', + 'mimes' => array( + 'jpg|jpeg|jpe' => 'image/jpeg', + 'gif' => 'image/gif', + ), + 'expected' => array( + 'ext' => 'jpe', + 'type' => 'image/jpeg', + ), + ), + 'uppercase filename and jpg|jpeg|jpe' => array( + 'filename' => 'canola.JPG', + 'mimes' => array( + 'jpg|jpeg|jpe' => 'image/jpeg', + 'gif' => 'image/gif', + ), + 'expected' => array( + 'ext' => 'JPG', + 'type' => 'image/jpeg', + ), + ), + '.XXX filename and no matching MIME type' => array( + 'filename' => 'canola.XXX', + 'mimes' => array( + 'jpg|jpeg|jpe' => 'image/jpeg', + 'gif' => 'image/gif', + ), + 'expected' => array( + 'ext' => false, + 'type' => false, + ), + ), + '.jpg filename but only gif allowed' => array( + 'filename' => 'canola.jpg', + 'mimes' => array( + 'gif' => 'image/gif', + ), + 'expected' => array( + 'ext' => false, + 'type' => false, + ), + ), + + ); + } +}