Annotation of embedaddon/php/ext/standard/tests/file/006_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test fileperms() & chmod() functions: usage variation - misc. perms
3: --SKIPIF--
4: <?php
5: if (substr(PHP_OS, 0, 3) == 'WIN') {
6: die('skip Not on Windows');
7: }
8: // Skip if being run by root
9: $filename = dirname(__FILE__)."/006_root_check.tmp";
10: $fp = fopen($filename, 'w');
11: fclose($fp);
12: if(fileowner($filename) == 0) {
13: unlink ($filename);
14: die('skip cannot be run as root');
15: }
16:
17: unlink($filename);
18:
19: ?>
20: --FILE--
21: <?php
22: /*
23: Prototype: int fileperms ( string $filename );
24: Description: Returns the permissions on the file, or FALSE in case of an error
25:
26: Prototype: bool chmod ( string $filename, int $mode );
27: Description: Attempts to change the mode of the file specified by
28: filename to that given in mode
29: */
30:
31: /* Testing with miscellaneous Permission */
32:
33: echo "*** Testing fileperms() & chmod() : usage variations ***\n";
34:
35: $file_name = dirname(__FILE__)."/006_variation2.tmp";
36: $file_handle = fopen($file_name, "w");
37: fclose($file_handle);
38: $dir_name = dirname(__FILE__)."/006_variation2";
39: mkdir($dir_name);
40:
41: echo "\n*** Testing fileperms(), chmod() with miscellaneous permissions ***\n";
42: $perms_array = array(
43: /* testing sticky bit */
44: 07777,
45: 00000,
46: 01000,
47: 011111,
48: /* negative values as permission */
49: -0777, // permissions will be given as 2's complement form of -0777
50: -07777, // permissions will be given as 2's complement form of -07777
51:
52: /* decimal values as permission */
53: 777, // permissions will be given as octal equivalent value of 777
54: 7777, // permissions will be given as octal equivalent value of 7777
55: -7777, // permissions are given as 2's complement of octal equivalent of 7777
56:
57: /* hex value as permission */
58: 0x777, // permissions will be given as ocatal equivalent value of 0x777
59: 0x7777,
60:
61: /* strings notation of permission, wont work properly */
62: "r+w",
63: "r+w+x",
64: "u+rwx",
65: "u+rwx, g+rw, o+wx"
66: );
67:
68: $count = 1;
69: foreach($perms_array as $permission) {
70: echo "-- Iteration $count --\n";
71: var_dump( chmod($file_name, $permission) );
72: printf("%o", fileperms($file_name) );
73: echo "\n";
74: clearstatcache();
75:
76: var_dump( chmod($dir_name, $permission) );
77: printf("%o", fileperms($dir_name) );
78: echo "\n";
79: clearstatcache();
80: $count++;
81: }
82: echo "*** Done ***\n";
83: ?>
84: --CLEAN--
85: <?php
86: chmod(dirname(__FILE__)."/006_variation2.tmp", 0777);
87: chmod(dirname(__FILE__)."/006_variation2", 0777);
88: unlink(dirname(__FILE__)."/006_variation2.tmp");
89: rmdir(dirname(__FILE__)."/006_variation2");
90: ?>
91: --EXPECTF--
92: *** Testing fileperms() & chmod() : usage variations ***
93:
94: *** Testing fileperms(), chmod() with miscellaneous permissions ***
95: -- Iteration 1 --
96: bool(true)
97: 107777
98: bool(true)
99: 47777
100: -- Iteration 2 --
101: bool(true)
102: 100000
103: bool(true)
104: 40000
105: -- Iteration 3 --
106: bool(true)
107: 101000
108: bool(true)
109: 41000
110: -- Iteration 4 --
111: bool(true)
112: 101111
113: bool(true)
114: 41111
115: -- Iteration 5 --
116: bool(true)
117: 107001
118: bool(true)
119: 47001
120: -- Iteration 6 --
121: bool(true)
122: 100001
123: bool(true)
124: 40001
125: -- Iteration 7 --
126: bool(true)
127: 101411
128: bool(true)
129: 41411
130: -- Iteration 8 --
131: bool(true)
132: 107141
133: bool(true)
134: 47141
135: -- Iteration 9 --
136: bool(true)
137: 100637
138: bool(true)
139: 40637
140: -- Iteration 10 --
141: bool(true)
142: 103567
143: bool(true)
144: 43567
145: -- Iteration 11 --
146: bool(true)
147: 103567
148: bool(true)
149: 43567
150: -- Iteration 12 --
151:
152: Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
153: NULL
154: 103567
155:
156: Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
157: NULL
158: 43567
159: -- Iteration 13 --
160:
161: Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
162: NULL
163: 103567
164:
165: Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
166: NULL
167: 43567
168: -- Iteration 14 --
169:
170: Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
171: NULL
172: 103567
173:
174: Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
175: NULL
176: 43567
177: -- Iteration 15 --
178:
179: Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
180: NULL
181: 103567
182:
183: Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
184: NULL
185: 43567
186: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>