forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistFiles.php
More file actions
82 lines (73 loc) · 2.42 KB
/
listFiles.php
File metadata and controls
82 lines (73 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* Test list_files().
*
* @group functions
*
* @covers ::list_files
*/
class Tests_Functions_ListFiles extends WP_UnitTestCase {
public function test_list_files_returns_a_list_of_files() {
$admin_files = list_files( ABSPATH . 'wp-admin/' );
$this->assertIsArray( $admin_files );
$this->assertNotEmpty( $admin_files );
$this->assertContains( ABSPATH . 'wp-admin/index.php', $admin_files );
}
public function test_list_files_can_exclude_files() {
$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,
),
);
}
}