1--TEST--
2Test scandir() function : usage variations - different directory permissions
3--SKIPIF--
4<?php
5if( substr(PHP_OS, 0, 3) == 'WIN') {
6  die('skip Not for Windows');
7}
8require __DIR__ . '/../skipif_root.inc';
9?>
10--FILE--
11<?php
12/*
13 * Create directories with different permissions to test whether scandir() can access them
14 */
15
16echo "*** Testing scandir() : usage variations ***\n";
17
18// create the temporary directory
19$dir_path = __DIR__ . "/scandir_variation7";
20mkdir($dir_path);
21
22// different values for directory permissions
23$permission_values = array(
24/*1*/  0477,  // owner has read only, other and group has rwx
25       0677,  // owner has rw only, other and group has rwx
26
27/*3*/  0444,  // all have read only
28       0666,  // all have rw only
29
30/*5*/  0400,  // owner has read only, group and others have no permission
31       0600,   // owner has rw only, group and others have no permission
32
33/*7*/  0470,  // owner has read only, group has rwx & others have no permission
34       0407,  // owner has read only, other has rwx & group has no permission
35
36/*9*/  0670,  // owner has rw only, group has rwx & others have no permission
37/*10*/ 0607   // owner has rw only, group has no permission and others have rwx
38);
39
40$iterator = 1;
41foreach ($permission_values as $perm) {
42    echo "\n-- Iteration $iterator --\n";
43
44    // Remove the directory if already exists
45    if (is_dir($dir_path)){
46        chmod ($dir_path, 0777); // change dir permission to allow all operation
47        rmdir ($dir_path);
48    }
49    mkdir($dir_path);
50
51    // change the dir permission to test dir on it
52    var_dump( chmod($dir_path, $perm) );
53
54    var_dump(scandir($dir_path));
55    $iterator++;
56}
57?>
58--CLEAN--
59<?php
60$dir_path = __DIR__ . "/scandir_variation7";
61rmdir($dir_path);
62?>
63--EXPECT--
64*** Testing scandir() : usage variations ***
65
66-- Iteration 1 --
67bool(true)
68array(2) {
69  [0]=>
70  string(1) "."
71  [1]=>
72  string(2) ".."
73}
74
75-- Iteration 2 --
76bool(true)
77array(2) {
78  [0]=>
79  string(1) "."
80  [1]=>
81  string(2) ".."
82}
83
84-- Iteration 3 --
85bool(true)
86array(2) {
87  [0]=>
88  string(1) "."
89  [1]=>
90  string(2) ".."
91}
92
93-- Iteration 4 --
94bool(true)
95array(2) {
96  [0]=>
97  string(1) "."
98  [1]=>
99  string(2) ".."
100}
101
102-- Iteration 5 --
103bool(true)
104array(2) {
105  [0]=>
106  string(1) "."
107  [1]=>
108  string(2) ".."
109}
110
111-- Iteration 6 --
112bool(true)
113array(2) {
114  [0]=>
115  string(1) "."
116  [1]=>
117  string(2) ".."
118}
119
120-- Iteration 7 --
121bool(true)
122array(2) {
123  [0]=>
124  string(1) "."
125  [1]=>
126  string(2) ".."
127}
128
129-- Iteration 8 --
130bool(true)
131array(2) {
132  [0]=>
133  string(1) "."
134  [1]=>
135  string(2) ".."
136}
137
138-- Iteration 9 --
139bool(true)
140array(2) {
141  [0]=>
142  string(1) "."
143  [1]=>
144  string(2) ".."
145}
146
147-- Iteration 10 --
148bool(true)
149array(2) {
150  [0]=>
151  string(1) "."
152  [1]=>
153  string(2) ".."
154}
155