1--TEST--
2Test fileperms() & chmod() functions: usage variation - misc. perms
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip Not on Windows');
7}
8require __DIR__ . '/../skipif_root.inc';
9?>
10--FILE--
11<?php
12/* Testing with miscellaneous Permission */
13
14echo "*** Testing fileperms() & chmod() : usage variations ***\n";
15
16$file_name = __DIR__."/006_variation2.tmp";
17$file_handle = fopen($file_name, "w");
18fclose($file_handle);
19$dir_name = __DIR__."/006_variation2";
20mkdir($dir_name);
21
22echo "\n*** Testing fileperms(), chmod() with miscellaneous permissions ***\n";
23$perms_array = array(
24  /* testing sticky bit */
25  07777,
26  00000,
27  01000,
28  011111,
29  /* negative  values as permission */
30  -0777, // permissions will be given as 2's complement form of -0777
31  -07777, // permissions will be given as 2's complement form of -07777
32
33  /* decimal values as permission  */
34  777, // permissions will be given as octal equivalent value of 777
35  7777, // permissions will be given as octal equivalent value of 7777
36  -7777, // permissions are given as 2's complement of octal equivalent of 7777
37
38  /* hex value as permission */
39  0x777, // permissions will be given as ocatal equivalent value of 0x777
40  0x7777,
41
42  /* strings notation of permission,  wont work properly */
43  "r+w",
44  "r+w+x",
45  "u+rwx",
46  "u+rwx, g+rw, o+wx"
47);
48
49$count = 1;
50foreach($perms_array as $permission) {
51  echo "-- Iteration $count --\n";
52  try {
53    var_dump( chmod($file_name, $permission) );
54    printf("%o", fileperms($file_name) );
55    echo "\n";
56    clearstatcache();
57  } catch (TypeError $e) {
58    echo $e->getMessage(), "\n";
59  }
60
61  try {
62    var_dump( chmod($dir_name, $permission) );
63    printf("%o", fileperms($dir_name) );
64    echo "\n";
65    clearstatcache();
66  } catch (TypeError $e) {
67    echo $e->getMessage(), "\n";
68  }
69  $count++;
70}
71echo "*** Done ***\n";
72?>
73--CLEAN--
74<?php
75chmod(__DIR__."/006_variation2.tmp", 0777);
76chmod(__DIR__."/006_variation2", 0777);
77unlink(__DIR__."/006_variation2.tmp");
78rmdir(__DIR__."/006_variation2");
79?>
80--EXPECT--
81*** Testing fileperms() & chmod() : usage variations ***
82
83*** Testing fileperms(), chmod() with miscellaneous permissions ***
84-- Iteration 1 --
85bool(true)
86107777
87bool(true)
8847777
89-- Iteration 2 --
90bool(true)
91100000
92bool(true)
9340000
94-- Iteration 3 --
95bool(true)
96101000
97bool(true)
9841000
99-- Iteration 4 --
100bool(true)
101101111
102bool(true)
10341111
104-- Iteration 5 --
105bool(true)
106107001
107bool(true)
10847001
109-- Iteration 6 --
110bool(true)
111100001
112bool(true)
11340001
114-- Iteration 7 --
115bool(true)
116101411
117bool(true)
11841411
119-- Iteration 8 --
120bool(true)
121107141
122bool(true)
12347141
124-- Iteration 9 --
125bool(true)
126100637
127bool(true)
12840637
129-- Iteration 10 --
130bool(true)
131103567
132bool(true)
13343567
134-- Iteration 11 --
135bool(true)
136103567
137bool(true)
13843567
139-- Iteration 12 --
140chmod(): Argument #2 ($permissions) must be of type int, string given
141chmod(): Argument #2 ($permissions) must be of type int, string given
142-- Iteration 13 --
143chmod(): Argument #2 ($permissions) must be of type int, string given
144chmod(): Argument #2 ($permissions) must be of type int, string given
145-- Iteration 14 --
146chmod(): Argument #2 ($permissions) must be of type int, string given
147chmod(): Argument #2 ($permissions) must be of type int, string given
148-- Iteration 15 --
149chmod(): Argument #2 ($permissions) must be of type int, string given
150chmod(): Argument #2 ($permissions) must be of type int, string given
151*** Done ***
152