Skip to content

Fix test for special chars in file names #996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

31 changes: 24 additions & 7 deletions tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,29 @@ public function test_run_without_any_file_type_errors() {
}

public function test_run_with_badly_named_errors() {
// Test plugin without any forbidden file types.
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-errors/load.php' );
$check_result = new Check_Result( $check_context );
// Initialize the Check_Context with a plugin path that mimics the directory structure.
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-folders-errors/load.php' );

// Create an empty Check_Result instance for this context.
$check_result = new Check_Result( $check_context );

// Initialize the File_Type_Check instance.
$check = new File_Type_Check( File_Type_Check::TYPE_BADLY_NAMED );
$check->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();

Expand All @@ -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() {
Expand Down
Loading