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