From 13bf0bc26506f2d3f862c8d38d30bde3d850c29c Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Thu, 3 Jul 2025 16:16:35 +0545 Subject: [PATCH] Fix test for special chars in file names --- .../badly directory/file.php | 2 -- ...file%name!@#$%^&*()+=[]{};:\"'<>,?|`~.php" | 3 -- .../load.php | 17 ---------- .../plugin name.php | 3 -- .../Checker/Checks/File_Type_Check_Tests.php | 31 ++++++++++++++----- 5 files changed, 24 insertions(+), 32 deletions(-) delete mode 100644 tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/badly directory/file.php delete mode 100644 "tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/badly|file%name!@#$%^&*()+=[]{};:\"'<>,?|`~.php" delete mode 100644 tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/load.php delete mode 100644 tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/plugin name.php diff --git a/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/badly directory/file.php b/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/badly directory/file.php deleted file mode 100644 index 5ebd0556e..000000000 --- a/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/badly directory/file.php +++ /dev/null @@ -1,2 +0,0 @@ -,?|`~.php" "b/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/badly|file%name!@#$%^&*()+=[]{};:\"'<>,?|`~.php" deleted file mode 100644 index 92bee4abf..000000000 --- "a/tests/phpunit/testdata/plugins/test-plugin-file-type-badly-named-files-errors/badly|file%name!@#$%^&*()+=[]{};:\"'<>,?|`~.php" +++ /dev/null @@ -1,3 +0,0 @@ -run( $check_result ); + + // Use reflection to make protected method accessible. + $reflection = new ReflectionClass( $check ); + $check_files_method = $reflection->getMethod( 'look_for_badly_named_files' ); + $check_files_method->setAccessible( true ); + + // Define the custom file list with badly named files and folders. + $custom_files = array( + UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-folders-errors/plugin name.php', + UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-folders-errors/badly directory/file.php', + UNIT_TESTS_PLUGIN_DIR . "test-plugin-file-type-badly-named-files-folders-errors/badly|file%name!@#$%^&*()+=[]{};:'<>,?|`~.php", + ); + + // Invoke method with the Check_Result instance and custom file list. + $check_files_method->invoke( $check, $check_result, $custom_files ); $errors = $check_result->get_errors(); @@ -123,9 +140,9 @@ public function test_run_with_badly_named_errors() { $this->assertCount( 1, wp_list_filter( $errors['badly directory/file.php'][0][0], array( 'code' => 'badly_named_files' ) ) ); // Badly named file with special chars. - $this->assertArrayHasKey( 0, $errors['badly|file%name!@#$%^&*()+=[]{};:"\'<>,?|`~.php'] ); - $this->assertArrayHasKey( 0, $errors['badly|file%name!@#$%^&*()+=[]{};:"\'<>,?|`~.php'][0] ); - $this->assertCount( 1, wp_list_filter( $errors['badly|file%name!@#$%^&*()+=[]{};:"\'<>,?|`~.php'][0][0], array( 'code' => 'badly_named_files' ) ) ); + $this->assertArrayHasKey( 0, $errors["badly|file%name!@#$%^&*()+=[]{};:'<>,?|`~.php"] ); + $this->assertArrayHasKey( 0, $errors["badly|file%name!@#$%^&*()+=[]{};:'<>,?|`~.php"][0] ); + $this->assertCount( 1, wp_list_filter( $errors["badly|file%name!@#$%^&*()+=[]{};:'<>,?|`~.php"][0][0], array( 'code' => 'badly_named_files' ) ) ); } public function test_run_with_case_sensitive_named_errors() {