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