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