1--TEST--
2Test opendir() 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 * Open a directory using opendir() with different directory permissions
14 */
15
16echo "*** Testing opendir() : usage variations ***\n";
17
18// create the temporary directory
19$file_path = __DIR__;
20$dir_path = $file_path . "/opendir_variation7";
21mkdir($dir_path);
22
23/* different values for directory permissions */
24$permission_values = array(
25/*1*/  0477,  // owner has read only, other and group has rwx
26       0677,  // owner has rw only, other and group has rwx
27
28/*3*/  0444,  // all have read only
29       0666,  // all have rw only
30
31/*5*/  0400,  // owner has read only, group and others have no permission
32       0600,   // owner has rw only, group and others have no permission
33
34/*7*/  0470,  // owner has read only, group has rwx & others have no permission
35       0407,  // owner has read only, other has rwx & group has no permission
36
37/*9*/  0670,  // owner has rw only, group has rwx & others have no permission
38/*10*/ 0607   // owner has rw only, group has no permission and others have rwx
39);
40
41// Open directory with different permission values, read and close, expected: none of them to succeed.
42
43$iterator = 1;
44foreach ($permission_values as $perm) {
45
46    echo "\n-- Iteration $iterator --\n";
47    // try to remove the dir if exists  & create
48    if (is_dir($dir_path)){
49        chmod ($dir_path, 0777); // change dir permission to allow all operation
50        rmdir ($dir_path);
51    }
52    mkdir($dir_path);
53
54    // change the dir permission to test dir on it
55    var_dump( chmod($dir_path, $perm) );
56
57    var_dump($dh = opendir($dir_path));
58
59    if (is_resource($dh)) {
60        closedir($dh);
61    }
62    $iterator++;
63}
64?>
65--CLEAN--
66<?php
67// deleting temporary directory
68$dir_path = __DIR__ . "/opendir_variation7";
69rmdir($dir_path);
70?>
71--EXPECTF--
72*** Testing opendir() : usage variations ***
73
74-- Iteration 1 --
75bool(true)
76resource(%d) of type (stream)
77
78-- Iteration 2 --
79bool(true)
80resource(%d) of type (stream)
81
82-- Iteration 3 --
83bool(true)
84resource(%d) of type (stream)
85
86-- Iteration 4 --
87bool(true)
88resource(%d) of type (stream)
89
90-- Iteration 5 --
91bool(true)
92resource(%d) of type (stream)
93
94-- Iteration 6 --
95bool(true)
96resource(%d) of type (stream)
97
98-- Iteration 7 --
99bool(true)
100resource(%d) of type (stream)
101
102-- Iteration 8 --
103bool(true)
104resource(%d) of type (stream)
105
106-- Iteration 9 --
107bool(true)
108resource(%d) of type (stream)
109
110-- Iteration 10 --
111bool(true)
112resource(%d) of type (stream)
113