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