1--TEST--
2Test is_writable() and its alias is_writeable() function: usage variations - diff. path notations
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6
7  // Skip if being run by root (files are always readable, writeable and executable)
8  $filename = dirname(__FILE__)."/is_writable_root_check.tmp";
9  $fp = fopen($filename, 'w');
10  fclose($fp);
11  if(fileowner($filename) == 0) {
12        unlink ($filename);
13        die('skip cannot be run as root');
14  }
15
16  unlink($filename);
17}
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/* test is_writable() & is_writeable() with file having different filepath notation */
27require dirname(__FILE__).'/file.inc';
28echo "*** Testing is_writable(): usage variations ***\n";
29
30$file_path = dirname(__FILE__);
31mkdir("$file_path/is_writable_variation1");
32
33// create a new temporary file
34$fp = fopen("$file_path/is_writable_variation1/bar.tmp", "w");
35fclose($fp);
36
37/* array of files to be tested to check if they are writable
38   using is_writable() function */
39$files_arr = array(
40  "$file_path/is_writable_variation1/bar.tmp",
41
42  /* Testing a file trailing slash */
43  "$file_path/is_writable_variation1/bar.tmp/",
44
45  /* Testing file with double slashes */
46  "$file_path/is_writable_variation1//bar.tmp",
47  "$file_path//is_writable_variation1//bar.tmp",
48  "$file_path/is_writable_variation1/*.tmp",
49  "$file_path/is_writable_variation1/b*.tmp",
50
51  /* Testing Binary safe */
52  "$file_path/is_writable_variation1".chr(0)."bar.tmp",
53  "$file_path".chr(0)."is_writable_variation1/bar.tmp",
54  "$file_path".chr(0)."is_writable_variation1/bar.tmp",
55
56  /* Testing directories */
57  ".",  // current directory, exp: bool(true)
58  "$file_path/is_writable_variation1"  // temp directory, exp: bool(true)
59);
60$counter = 1;
61/* loop through to test each element in the above array
62   is a writable file */
63foreach($files_arr as $file) {
64  echo "-- Iteration $counter --\n";
65  var_dump( is_writable($file) );
66  var_dump( is_writeable($file) );
67  $counter++;
68  clearstatcache();
69}
70
71echo "Done\n";
72?>
73--CLEAN--
74<?php
75unlink(dirname(__FILE__)."/is_writable_variation1/bar.tmp");
76rmdir(dirname(__FILE__)."/is_writable_variation1/");
77?>
78--EXPECTF--
79*** Testing is_writable(): usage variations ***
80-- Iteration 1 --
81bool(true)
82bool(true)
83-- Iteration 2 --
84bool(%s)
85bool(%s)
86-- Iteration 3 --
87bool(true)
88bool(true)
89-- Iteration 4 --
90bool(true)
91bool(true)
92-- Iteration 5 --
93bool(false)
94bool(false)
95-- Iteration 6 --
96bool(false)
97bool(false)
98-- Iteration 7 --
99
100Warning: is_writable() expects parameter 1 to be a valid path, string given in %s on line %d
101NULL
102
103Warning: is_writeable() expects parameter 1 to be a valid path, string given in %s on line %d
104NULL
105-- Iteration 8 --
106
107Warning: is_writable() expects parameter 1 to be a valid path, string given in %s on line %d
108NULL
109
110Warning: is_writeable() expects parameter 1 to be a valid path, string given in %s on line %d
111NULL
112-- Iteration 9 --
113
114Warning: is_writable() expects parameter 1 to be a valid path, string given in %s on line %d
115NULL
116
117Warning: is_writeable() expects parameter 1 to be a valid path, string given in %s on line %d
118NULL
119-- Iteration 10 --
120bool(true)
121bool(true)
122-- Iteration 11 --
123bool(true)
124bool(true)
125Done
126