1--TEST--
2Test dir() 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 * Providing various permissions to the directory to be opened and checking
14 * to see if dir() function opens the directory successfully.
15 */
16
17echo "*** Testing dir() : different directory permissions ***";
18
19// create the temporary directory
20$file_path = __DIR__;
21$dir_path = $file_path."/dir_variation3";
22@mkdir($dir_path);
23
24/* different values for directory permissions */
25$permission_values = array(
26/*1*/  0477,  // owner has read only, other and group has rwx
27       0677,  // owner has rw only, other and group has rwx
28
29/*3*/  0444,  // all have read only
30       0666,  // all have rw only
31
32/*5*/  0400,  // owner has read only, group and others have no permission
33       0600,   // owner has rw only, group and others have no permission
34
35/*7*/  0470,  // owner has read only, group has rwx & others have no permission
36       0407,  // owner has read only, other has rwx & group has no permission
37
38/*9*/  0670,  // owner has rw only, group has rwx & others have no permission
39/*10*/ 0607   // owner has rw only, group has no permission and others have rwx
40);
41
42// Open directory with different permission values, read and close, expected: none of them to succeed.
43for($count = 0; $count < count($permission_values); $count++) {
44  echo "\n-- Iteration ".($count + 1)." --\n";
45
46  // try to remove the dir if exists  & create
47  $file_path = __DIR__;
48  $dir_path = $file_path."/dir_variation3";
49  @chmod ($dir_path, 0777); // change dir permission to allow all operation
50  @rmdir ($dir_path);  // try n delete the dir
51
52  // create the dir now
53  @mkdir($dir_path);
54
55  // change the dir permission to test dir on it
56  var_dump( chmod($dir_path, $permission_values[$count]) );
57
58  // try to get dir handle
59  $d = dir($dir_path);
60  var_dump($d);   // dump the handle
61
62  // try read directory, expected : false
63  echo "-- reading contents --\n";
64  var_dump($d->read());
65
66  // close directory
67  $d->close();
68}
69
70echo "Done";
71?>
72--CLEAN--
73<?php
74// deleting temporary directory
75$file_path = __DIR__;
76$dir_path = $file_path."/dir_variation3";
77rmdir($dir_path);
78?>
79--EXPECTF--
80*** Testing dir() : different directory permissions ***
81-- Iteration 1 --
82bool(true)
83object(Directory)#%d (2) {
84  ["path"]=>
85  string(%d) "%s/dir_variation3"
86  ["handle"]=>
87  resource(%d) of type (stream)
88}
89-- reading contents --
90string(%d) "%s"
91
92-- Iteration 2 --
93bool(true)
94object(Directory)#%d (2) {
95  ["path"]=>
96  string(%d) "%s/dir_variation3"
97  ["handle"]=>
98  resource(%d) of type (stream)
99}
100-- reading contents --
101string(%d) "%s"
102
103-- Iteration 3 --
104bool(true)
105object(Directory)#%d (2) {
106  ["path"]=>
107  string(%d) "%s/dir_variation3"
108  ["handle"]=>
109  resource(%d) of type (stream)
110}
111-- reading contents --
112string(%d) "%s"
113
114-- Iteration 4 --
115bool(true)
116object(Directory)#%d (2) {
117  ["path"]=>
118  string(%d) "%s/dir_variation3"
119  ["handle"]=>
120  resource(%d) of type (stream)
121}
122-- reading contents --
123string(%d) "%s"
124
125-- Iteration 5 --
126bool(true)
127object(Directory)#%d (2) {
128  ["path"]=>
129  string(%d) "%s/dir_variation3"
130  ["handle"]=>
131  resource(%d) of type (stream)
132}
133-- reading contents --
134string(%d) "%s"
135
136-- Iteration 6 --
137bool(true)
138object(Directory)#%d (2) {
139  ["path"]=>
140  string(%d) "%s/dir_variation3"
141  ["handle"]=>
142  resource(%d) of type (stream)
143}
144-- reading contents --
145string(%d) "%s"
146
147-- Iteration 7 --
148bool(true)
149object(Directory)#%d (2) {
150  ["path"]=>
151  string(%d) "%s/dir_variation3"
152  ["handle"]=>
153  resource(%d) of type (stream)
154}
155-- reading contents --
156string(%d) "%s"
157
158-- Iteration 8 --
159bool(true)
160object(Directory)#%d (2) {
161  ["path"]=>
162  string(%d) "%s/dir_variation3"
163  ["handle"]=>
164  resource(%d) of type (stream)
165}
166-- reading contents --
167string(%d) "%s"
168
169-- Iteration 9 --
170bool(true)
171object(Directory)#%d (2) {
172  ["path"]=>
173  string(%d) "%s/dir_variation3"
174  ["handle"]=>
175  resource(%d) of type (stream)
176}
177-- reading contents --
178string(%d) "%s"
179
180-- Iteration 10 --
181bool(true)
182object(Directory)#%d (2) {
183  ["path"]=>
184  string(%d) "%s/dir_variation3"
185  ["handle"]=>
186  resource(%d) of type (stream)
187}
188-- reading contents --
189string(%d) "%s"
190Done
191