mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Filesystem API: Allow optional inclusion of hidden files in list_files().
Adds a new optional `$include_hidden` parameter to allow the inclusion of hidden (`.` prefixed) files. Defaults to false for backward compatibility. Props yani.iliev, sabernhardt, costdev, rutviksavsani, zunaid321, azaozz. Fixes #53659. git-svn-id: https://develop.svn.wordpress.org/trunk@56069 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -19,4 +19,63 @@ class Tests_Functions_ListFiles extends WP_UnitTestCase {
|
||||
$admin_files = list_files( ABSPATH . 'wp-admin/', 100, array( 'index.php' ) );
|
||||
$this->assertNotContains( ABSPATH . 'wp-admin/index.php', $admin_files );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that list_files() optionally includes hidden files.
|
||||
*
|
||||
* @ticket 53659
|
||||
*
|
||||
* @dataProvider data_list_files_should_optionally_include_hidden_files
|
||||
*
|
||||
* @param string $filename The name of the hidden file.
|
||||
* @param bool $include_hidden Whether to include hidden ("." prefixed) files.
|
||||
* @param string[] $exclusions List of folders and files to skip.
|
||||
* @param bool $expected Whether the file should be included in the results.
|
||||
*/
|
||||
public function test_list_files_should_optionally_include_hidden_files( $filename, $include_hidden, $exclusions, $expected ) {
|
||||
$test_dir = get_temp_dir() . 'test-list-files/';
|
||||
$hidden_file = $test_dir . $filename;
|
||||
|
||||
mkdir( $test_dir );
|
||||
touch( $hidden_file );
|
||||
|
||||
$actual = list_files( $test_dir, 100, $exclusions, $include_hidden );
|
||||
|
||||
unlink( $hidden_file );
|
||||
rmdir( $test_dir );
|
||||
|
||||
if ( $expected ) {
|
||||
$this->assertContains( $hidden_file, $actual, 'The file was not included.' );
|
||||
} else {
|
||||
$this->assertNotContains( $hidden_file, $actual, 'The file was included.' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function data_list_files_should_optionally_include_hidden_files() {
|
||||
return array(
|
||||
'$include_hidden = false and no exclusions' => array(
|
||||
'filename' => '.hidden_file',
|
||||
'include_hidden' => false,
|
||||
'exclusions' => array(),
|
||||
'expected' => false,
|
||||
),
|
||||
'$include_hidden = true and no exclusions' => array(
|
||||
'filename' => '.hidden_file',
|
||||
'include_hidden' => true,
|
||||
'exclusions' => array(),
|
||||
'expected' => true,
|
||||
),
|
||||
'$include_hidden = true and an excluded filename' => array(
|
||||
'filename' => '.hidden_file',
|
||||
'include_hidden' => true,
|
||||
'exclusions' => array( '.hidden_file' ),
|
||||
'expected' => false,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user