1--TEST--
2Test is_writable() and its alias is_writeable() function: usage variations - file/dir with diff. perms
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip.. only on LINUX');
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}
16
17unlink ($filename);
18?>
19--FILE--
20<?php
21/* Prototype: bool is_writable ( string $filename );
22   Description: Tells whether the filename is writable.
23
24   is_writeable() is an alias of is_writable()
25*/
26
27/* test is_executable() with file/dir having different permissions */
28
29require dirname(__FILE__).'/file.inc';
30echo "*** Testing is_writable(): usage variations ***\n";
31
32$file_path = dirname(__FILE__);
33mkdir("$file_path/is_writable_variation2");
34
35echo "\n*** Testing is_writable() on directory without write permission ***\n";
36chmod("$file_path/is_writable_variation2", 0004);
37var_dump( is_writable("$file_path/is_writable_variation2") );  // exp: bool(false)
38var_dump( is_writeable("$file_path/is_writable_variation2") );  // exp: bool(false)
39chmod("$file_path/is_writable_variation2", 0777);  // chmod to enable deletion of directory
40
41echo "\n*** Testing miscelleneous input for is_writable() function ***\n";
42$name_prefix = "is_writable_variation2";
43create_files(dirname(__FILE__), 1, "numeric", 0755, 1, "w", $name_prefix, 1);
44create_files(dirname(__FILE__), 1, "text", 0755, 1, "w", $name_prefix, 2);
45create_files(dirname(__FILE__), 1, "empty", 0755, 1, "w", $name_prefix, 3);
46create_files(dirname(__FILE__), 1, "numeric", 0555, 1, "w", $name_prefix, 4);
47create_files(dirname(__FILE__), 1, "text", 0222, 1, "w", $name_prefix, 5);
48create_files(dirname(__FILE__), 1, "numeric", 0711, 1, "w", $name_prefix, 6);
49create_files(dirname(__FILE__), 1, "text", 0114, 1, "w", $name_prefix, 7);
50create_files(dirname(__FILE__), 1, "numeric", 0244, 1, "w", $name_prefix, 8);
51create_files(dirname(__FILE__), 1, "text", 0421, 1, "w", $name_prefix, 9);
52create_files(dirname(__FILE__), 1, "text", 0422, 1, "w", $name_prefix, 10);
53
54$misc_files = array (
55  "$file_path/is_writable_variation21.tmp",
56  "$file_path/is_writable_variation22.tmp",
57  "$file_path/is_writable_variation23.tmp",
58  "$file_path/is_writable_variation24.tmp",
59  "$file_path/is_writable_variation25.tmp",
60  "$file_path/is_writable_variation26.tmp",
61  "$file_path/is_writable_variation27.tmp",
62  "$file_path/is_writable_variation28.tmp",
63  "$file_path/is_writable_variation29.tmp",
64  "$file_path/is_writable_variation210.tmp"
65);
66
67$counter = 1;
68/* loop through to test each element in the above array
69   is a writable file */
70foreach($misc_files as $misc_file) {
71  echo "-- Iteration $counter --\n";
72  var_dump( is_writable($misc_file) );
73  var_dump( is_writeable($misc_file) );
74  $counter++;
75  clearstatcache();
76}
77
78// change all file's permissions to 777 before deleting
79change_file_perms($file_path, 10, 0777, $name_prefix);
80delete_files($file_path, 10, $name_prefix);
81
82echo "Done\n";
83?>
84--CLEAN--
85<?php
86rmdir(dirname(__FILE__)."/is_writable_variation2/");
87?>
88--EXPECTF--
89*** Testing is_writable(): usage variations ***
90
91*** Testing is_writable() on directory without write permission ***
92bool(false)
93bool(false)
94
95*** Testing miscelleneous input for is_writable() function ***
96-- Iteration 1 --
97bool(true)
98bool(true)
99-- Iteration 2 --
100bool(true)
101bool(true)
102-- Iteration 3 --
103bool(true)
104bool(true)
105-- Iteration 4 --
106bool(false)
107bool(false)
108-- Iteration 5 --
109bool(true)
110bool(true)
111-- Iteration 6 --
112bool(true)
113bool(true)
114-- Iteration 7 --
115bool(false)
116bool(false)
117-- Iteration 8 --
118bool(true)
119bool(true)
120-- Iteration 9 --
121bool(false)
122bool(false)
123-- Iteration 10 --
124bool(false)
125bool(false)
126Done
127