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