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}
8// Skip if being run by root
9$filename = dirname(__FILE__)."/is_readable_root_check.tmp";
10$fp = fopen($filename, 'w');
11fclose($fp);
12if(fileowner($filename) == 0) {
13        unlink ($filename);
14        die('skip cannot be run as root');
15}
16unlink($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
26require dirname(__FILE__).'/file.inc';
27echo "*** Testing is_readable(): usage variations ***\n";
28
29$file_path = dirname(__FILE__);
30mkdir("$file_path/is_readable_variation2");
31
32echo "\n*** Testing is_readable() on directory without read permission ***\n";
33chmod("$file_path/is_readable_variation2", 0001);
34var_dump( is_readable("$file_path/is_readable_variation2") );  // exp: bool(false)
35chmod("$file_path/is_readable_variation2", 0777);  // chmod to enable deletion of directory
36
37echo "\n*** Testing miscelleneous input for is_readable() function ***\n";
38$name_prefix = "is_readable_variation2";
39create_files(dirname(__FILE__), 1, "numeric", 0755, 1, "w", $name_prefix, 1);
40create_files(dirname(__FILE__), 1, "text", 0755, 1, "w", $name_prefix, 2);
41create_files(dirname(__FILE__), 1, "empty", 0755, 1, "w", $name_prefix, 3);
42create_files(dirname(__FILE__), 1, "numeric", 0555, 1, "w", $name_prefix, 4);
43create_files(dirname(__FILE__), 1, "text", 0222, 1, "w", $name_prefix, 5);
44create_files(dirname(__FILE__), 1, "numeric", 0711, 1, "w", $name_prefix, 6);
45create_files(dirname(__FILE__), 1, "text", 0411, 1, "w", $name_prefix, 7);
46create_files(dirname(__FILE__), 1, "numeric", 0444, 1, "w", $name_prefix, 8);
47create_files(dirname(__FILE__), 1, "text", 0421, 1, "w", $name_prefix, 9);
48create_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 */
65foreach($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
73change_file_perms($file_path, 10, 0777, $name_prefix);
74delete_files($file_path, 10, $name_prefix);
75
76echo "Done\n";
77?>
78--CLEAN--
79<?php
80rmdir(dirname(__FILE__)."/is_readable_variation2/");
81?>
82--EXPECTF--
83*** Testing is_readable(): usage variations ***
84
85*** Testing is_readable() on directory without read permission ***
86bool(false)
87
88*** Testing miscelleneous input for is_readable() function ***
89-- Iteration 1 --
90bool(true)
91-- Iteration 2 --
92bool(true)
93-- Iteration 3 --
94bool(true)
95-- Iteration 4 --
96bool(true)
97-- Iteration 5 --
98bool(false)
99-- Iteration 6 --
100bool(true)
101-- Iteration 7 --
102bool(true)
103-- Iteration 8 --
104bool(true)
105-- Iteration 9 --
106bool(true)
107-- Iteration 10 --
108bool(true)
109Done
110