From ec7a7c3f1672aa4474f7987e166be2eec98f1022 Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Sat, 8 Oct 2022 09:16:35 +0000 Subject: [PATCH] Build/Test Tools: Add tests coverage for `_wp_check_alternate_file_names()`. This changeset adds missing unit tests for this function. Props pbearne, costdev, peterwilsoncc. Fixes #55199. git-svn-id: https://develop.svn.wordpress.org/trunk@54422 602fd350-edb4-49c9-b593-d223f7449a82 --- .../functions/wpCheckAlternateFileNames.php | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/phpunit/tests/functions/wpCheckAlternateFileNames.php diff --git a/tests/phpunit/tests/functions/wpCheckAlternateFileNames.php b/tests/phpunit/tests/functions/wpCheckAlternateFileNames.php new file mode 100644 index 0000000000..c21ae3374d --- /dev/null +++ b/tests/phpunit/tests/functions/wpCheckAlternateFileNames.php @@ -0,0 +1,68 @@ +assertSame( $expected, _wp_check_alternate_file_names( $filenames, $dir, $files ) ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_wp_check_alternate_file_names() { + return array( + 'an existing file' => array( + 'filenames' => array( 'canola.jpg' ), + 'dir' => DIR_TESTDATA . '/images/', + 'files' => array(), + 'expected' => true, + ), + 'multiple existing files' => array( + 'filenames' => array( 'canola.jpg', 'codeispoetry.png' ), + 'dir' => DIR_TESTDATA . '/images/', + 'files' => array(), + 'expected' => true, + ), + 'a non-existent file and an existing file' => array( + 'filenames' => array( 'an-image.jpg', 'codeispoetry.png' ), + 'dir' => DIR_TESTDATA . '/images/', + 'files' => array(), + 'expected' => true, + ), + 'a non-existent file and an existing image sub-size file' => array( + 'filenames' => array( 'one-blue-pixel.png' ), + 'dir' => DIR_TESTDATA . '/images/', + 'files' => array( 'one-blue-pixel-100x100.png' ), + 'expected' => true, + ), + 'a non-existent file and no other existing files' => array( + 'filenames' => array( 'filename.php' ), + 'dir' => DIR_TESTDATA . '/images/', + 'files' => array(), + 'expected' => false, + ), + 'multiple non-existent files and no existing image sub-size files' => array( + 'filenames' => array( 'canola.jpg', 'codeispoetry.png' ), + 'dir' => DIR_TESTDATA . '/functions/', + 'files' => array( 'an-image-100x100.jpg', 'another-image-100x100.png' ), + 'expected' => false, + ), + ); + } +}