@@ -100,12 +100,29 @@ public function test_run_without_any_file_type_errors() {
100
100
}
101
101
102
102
public function test_run_with_badly_named_errors () {
103
- // Test plugin without any forbidden file types.
104
- $ check_context = new Check_Context ( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-errors/load.php ' );
105
- $ check_result = new Check_Result ( $ check_context );
103
+ // Initialize the Check_Context with a plugin path that mimics the directory structure.
104
+ $ check_context = new Check_Context ( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-folders-errors/load.php ' );
105
+
106
+ // Create an empty Check_Result instance for this context.
107
+ $ check_result = new Check_Result ( $ check_context );
106
108
109
+ // Initialize the File_Type_Check instance.
107
110
$ check = new File_Type_Check ( File_Type_Check::TYPE_BADLY_NAMED );
108
- $ check ->run ( $ check_result );
111
+
112
+ // Use reflection to make protected method accessible.
113
+ $ reflection = new ReflectionClass ( $ check );
114
+ $ check_files_method = $ reflection ->getMethod ( 'look_for_badly_named_files ' );
115
+ $ check_files_method ->setAccessible ( true );
116
+
117
+ // Define the custom file list with badly named files and folders.
118
+ $ custom_files = array (
119
+ UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-folders-errors/plugin name.php ' ,
120
+ UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-folders-errors/badly directory/file.php ' ,
121
+ UNIT_TESTS_PLUGIN_DIR . "test-plugin-file-type-badly-named-files-folders-errors/badly|file%name!@#$%^&*()+=[]{};:'<>,?|`~.php " ,
122
+ );
123
+
124
+ // Invoke method with the Check_Result instance and custom file list.
125
+ $ check_files_method ->invoke ( $ check , $ check_result , $ custom_files );
109
126
110
127
$ errors = $ check_result ->get_errors ();
111
128
@@ -123,9 +140,9 @@ public function test_run_with_badly_named_errors() {
123
140
$ this ->assertCount ( 1 , wp_list_filter ( $ errors ['badly directory/file.php ' ][0 ][0 ], array ( 'code ' => 'badly_named_files ' ) ) );
124
141
125
142
// Badly named file with special chars.
126
- $ this ->assertArrayHasKey ( 0 , $ errors [' badly|file%name!@#$%^&*()+=[]{};:" \ '<>,?|`~.php ' ] );
127
- $ this ->assertArrayHasKey ( 0 , $ errors [' badly|file%name!@#$%^&*()+=[]{};:" \ '<>,?|`~.php ' ][0 ] );
128
- $ this ->assertCount ( 1 , wp_list_filter ( $ errors [' badly|file%name!@#$%^&*()+=[]{};:" \ '<>,?|`~.php ' ][0 ][0 ], array ( 'code ' => 'badly_named_files ' ) ) );
143
+ $ this ->assertArrayHasKey ( 0 , $ errors [" badly|file%name!@#$%^&*()+=[]{};:'<>,?|`~.php " ] );
144
+ $ this ->assertArrayHasKey ( 0 , $ errors [" badly|file%name!@#$%^&*()+=[]{};:'<>,?|`~.php " ][0 ] );
145
+ $ this ->assertCount ( 1 , wp_list_filter ( $ errors [" badly|file%name!@#$%^&*()+=[]{};:'<>,?|`~.php " ][0 ][0 ], array ( 'code ' => 'badly_named_files ' ) ) );
129
146
}
130
147
131
148
public function test_run_with_case_sensitive_named_errors () {
0 commit comments