From 6a574d76763e9e772c93d5114de95196b7e809e1 Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Thu, 2 Mar 2023 21:03:15 +0000 Subject: [PATCH] Build/Test Tools: Add wp_check_filetype() unit tests. Adds a test class and data set for unit testing `wp_check_filetype()`. Props pbearne, costdev. Fixes #57151. git-svn-id: https://develop.svn.wordpress.org/trunk@55456 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tests/functions/wpCheckFiletype.php | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 tests/phpunit/tests/functions/wpCheckFiletype.php 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, + ), + ), + + ); + } +}