Annotation of embedaddon/php/ext/standard/tests/file/is_readable_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test is_readable() function: usage variations - file/dir with diff. perms
3: --SKIPIF--
4: <?php
5: if (substr(PHP_OS, 0, 3) == 'WIN') {
6: die('skip not for windows');
7: }
8: // Skip if being run by root
9: $filename = dirname(__FILE__)."/is_readable_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: unlink($filename);
17: ?>
18: --FILE--
19: <?php
20: /* Prototype: bool is_readable ( string $filename );
21: Description: Tells whether the filename is readable.
22: */
23:
24: /* test is_executable() with file/dir having different permissions */
25:
26: require dirname(__FILE__).'/file.inc';
27: echo "*** Testing is_readable(): usage variations ***\n";
28:
29: $file_path = dirname(__FILE__);
30: mkdir("$file_path/is_readable_variation2");
31:
32: echo "\n*** Testing is_readable() on directory without read permission ***\n";
33: chmod("$file_path/is_readable_variation2", 0001);
34: var_dump( is_readable("$file_path/is_readable_variation2") ); // exp: bool(false)
35: chmod("$file_path/is_readable_variation2", 0777); // chmod to enable deletion of directory
36:
37: echo "\n*** Testing miscelleneous input for is_readable() function ***\n";
38: $name_prefix = "is_readable_variation2";
39: create_files(dirname(__FILE__), 1, "numeric", 0755, 1, "w", $name_prefix, 1);
40: create_files(dirname(__FILE__), 1, "text", 0755, 1, "w", $name_prefix, 2);
41: create_files(dirname(__FILE__), 1, "empty", 0755, 1, "w", $name_prefix, 3);
42: create_files(dirname(__FILE__), 1, "numeric", 0555, 1, "w", $name_prefix, 4);
43: create_files(dirname(__FILE__), 1, "text", 0222, 1, "w", $name_prefix, 5);
44: create_files(dirname(__FILE__), 1, "numeric", 0711, 1, "w", $name_prefix, 6);
45: create_files(dirname(__FILE__), 1, "text", 0411, 1, "w", $name_prefix, 7);
46: create_files(dirname(__FILE__), 1, "numeric", 0444, 1, "w", $name_prefix, 8);
47: create_files(dirname(__FILE__), 1, "text", 0421, 1, "w", $name_prefix, 9);
48: create_files(dirname(__FILE__), 1, "text", 0422, 1, "w", $name_prefix, 10);
49:
50: $files = array (
51: "$file_path/is_readable_variation21.tmp",
52: "$file_path/is_readable_variation22.tmp",
53: "$file_path/is_readable_variation23.tmp",
54: "$file_path/is_readable_variation24.tmp",
55: "$file_path/is_readable_variation25.tmp",
56: "$file_path/is_readable_variation26.tmp",
57: "$file_path/is_readable_variation27.tmp",
58: "$file_path/is_readable_variation28.tmp",
59: "$file_path/is_readable_variation29.tmp",
60: "$file_path/is_readable_variation210.tmp"
61: );
62: $counter = 1;
63: /* loop through to test each element in the above array
64: is a readable file */
65: foreach($files as $file) {
66: echo "-- Iteration $counter --\n";
67: var_dump( is_readable($file) );
68: $counter++;
69: clearstatcache();
70: }
71:
72: // change all file's permissions to 777 before deleting
73: change_file_perms($file_path, 10, 0777, $name_prefix);
74: delete_files($file_path, 10, $name_prefix);
75:
76: echo "Done\n";
77: ?>
78: --CLEAN--
79: <?php
80: rmdir(dirname(__FILE__)."/is_readable_variation2/");
81: ?>
82: --EXPECTF--
83: *** Testing is_readable(): usage variations ***
84:
85: *** Testing is_readable() on directory without read permission ***
86: bool(false)
87:
88: *** Testing miscelleneous input for is_readable() function ***
89: -- Iteration 1 --
90: bool(true)
91: -- Iteration 2 --
92: bool(true)
93: -- Iteration 3 --
94: bool(true)
95: -- Iteration 4 --
96: bool(true)
97: -- Iteration 5 --
98: bool(false)
99: -- Iteration 6 --
100: bool(true)
101: -- Iteration 7 --
102: bool(true)
103: -- Iteration 8 --
104: bool(true)
105: -- Iteration 9 --
106: bool(true)
107: -- Iteration 10 --
108: bool(true)
109: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>