1--TEST--
2Test is_writable() and its alias is_writeable() function: usage variations - diff. path notations
3--SKIPIF--
4<?php
5require __DIR__ . '/../skipif_root.inc';
6?>
7--FILE--
8<?php
9/* test is_writable() & is_writeable() with file having different filepath notation */
10require __DIR__.'/file.inc';
11echo "*** Testing is_writable(): usage variations ***\n";
12
13$file_path = __DIR__;
14mkdir("$file_path/is_writable_variation1");
15
16// create a new temporary file
17$fp = fopen("$file_path/is_writable_variation1/bar.tmp", "w");
18fclose($fp);
19
20/* array of files to be tested to check if they are writable
21   using is_writable() function */
22$files_arr = array(
23  "$file_path/is_writable_variation1/bar.tmp",
24
25  /* Testing a file trailing slash */
26  "$file_path/is_writable_variation1/bar.tmp/",
27
28  /* Testing file with double slashes */
29  "$file_path/is_writable_variation1//bar.tmp",
30  "$file_path//is_writable_variation1//bar.tmp",
31  "$file_path/is_writable_variation1/*.tmp",
32  "$file_path/is_writable_variation1/b*.tmp",
33
34  /* Testing Binary safe */
35  "$file_path/is_writable_variation1".chr(0)."bar.tmp",
36  "$file_path".chr(0)."is_writable_variation1/bar.tmp",
37  "$file_path".chr(0)."is_writable_variation1/bar.tmp",
38
39  /* Testing directories */
40  ".",  // current directory, exp: bool(true)
41  "$file_path/is_writable_variation1"  // temp directory, exp: bool(true)
42);
43$counter = 1;
44/* loop through to test each element in the above array
45   is a writable file */
46foreach($files_arr as $file) {
47  echo "-- Iteration $counter --\n";
48  try {
49    var_dump( is_writable($file) );
50  } catch (Error $e) {
51    echo $e->getMessage(), "\n";
52  }
53  try {
54    var_dump( is_writeable($file) );
55  } catch (Error $e) {
56    echo $e->getMessage(), "\n";
57  }
58  $counter++;
59  clearstatcache();
60}
61
62echo "Done\n";
63?>
64--CLEAN--
65<?php
66unlink(__DIR__."/is_writable_variation1/bar.tmp");
67rmdir(__DIR__."/is_writable_variation1/");
68?>
69--EXPECTF--
70*** Testing is_writable(): usage variations ***
71-- Iteration 1 --
72bool(true)
73bool(true)
74-- Iteration 2 --
75bool(%s)
76bool(%s)
77-- Iteration 3 --
78bool(true)
79bool(true)
80-- Iteration 4 --
81bool(true)
82bool(true)
83-- Iteration 5 --
84bool(false)
85bool(false)
86-- Iteration 6 --
87bool(false)
88bool(false)
89-- Iteration 7 --
90bool(false)
91bool(false)
92-- Iteration 8 --
93bool(false)
94bool(false)
95-- Iteration 9 --
96bool(false)
97bool(false)
98-- Iteration 10 --
99bool(true)
100bool(true)
101-- Iteration 11 --
102bool(true)
103bool(true)
104Done
105