Return to is_writable_variation2.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: Test is_writable() and its alias is_writeable() function: usage variations - file/dir with diff. perms 3: --SKIPIF-- 4: <?php 5: if (substr(PHP_OS, 0, 3) == 'WIN') { 6: die('skip.. only on LINUX'); 7: } 8: // Skip if being run by root 9: $filename = dirname(__FILE__)."/is_readable_root_check.tmp"; 10: $fp = fopen($filename, 'w'); 11: fclose($fp); 12: if(fileowner($filename) == 0) { 13: unlink ($filename); 14: die('skip cannot be run as root'); 15: } 16: 17: unlink ($filename); 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: 27: /* test is_executable() with file/dir having different permissions */ 28: 29: require dirname(__FILE__).'/file.inc'; 30: echo "*** Testing is_writable(): usage variations ***\n"; 31: 32: $file_path = dirname(__FILE__); 33: mkdir("$file_path/is_writable_variation2"); 34: 35: echo "\n*** Testing is_writable() on directory without write permission ***\n"; 36: chmod("$file_path/is_writable_variation2", 0004); 37: var_dump( is_writable("$file_path/is_writable_variation2") ); // exp: bool(false) 38: var_dump( is_writeable("$file_path/is_writable_variation2") ); // exp: bool(false) 39: chmod("$file_path/is_writable_variation2", 0777); // chmod to enable deletion of directory 40: 41: echo "\n*** Testing miscelleneous input for is_writable() function ***\n"; 42: $name_prefix = "is_writable_variation2"; 43: create_files(dirname(__FILE__), 1, "numeric", 0755, 1, "w", $name_prefix, 1); 44: create_files(dirname(__FILE__), 1, "text", 0755, 1, "w", $name_prefix, 2); 45: create_files(dirname(__FILE__), 1, "empty", 0755, 1, "w", $name_prefix, 3); 46: create_files(dirname(__FILE__), 1, "numeric", 0555, 1, "w", $name_prefix, 4); 47: create_files(dirname(__FILE__), 1, "text", 0222, 1, "w", $name_prefix, 5); 48: create_files(dirname(__FILE__), 1, "numeric", 0711, 1, "w", $name_prefix, 6); 49: create_files(dirname(__FILE__), 1, "text", 0114, 1, "w", $name_prefix, 7); 50: create_files(dirname(__FILE__), 1, "numeric", 0244, 1, "w", $name_prefix, 8); 51: create_files(dirname(__FILE__), 1, "text", 0421, 1, "w", $name_prefix, 9); 52: create_files(dirname(__FILE__), 1, "text", 0422, 1, "w", $name_prefix, 10); 53: 54: $misc_files = array ( 55: "$file_path/is_writable_variation21.tmp", 56: "$file_path/is_writable_variation22.tmp", 57: "$file_path/is_writable_variation23.tmp", 58: "$file_path/is_writable_variation24.tmp", 59: "$file_path/is_writable_variation25.tmp", 60: "$file_path/is_writable_variation26.tmp", 61: "$file_path/is_writable_variation27.tmp", 62: "$file_path/is_writable_variation28.tmp", 63: "$file_path/is_writable_variation29.tmp", 64: "$file_path/is_writable_variation210.tmp" 65: ); 66: 67: $counter = 1; 68: /* loop through to test each element in the above array 69: is a writable file */ 70: foreach($misc_files as $misc_file) { 71: echo "-- Iteration $counter --\n"; 72: var_dump( is_writable($misc_file) ); 73: var_dump( is_writeable($misc_file) ); 74: $counter++; 75: clearstatcache(); 76: } 77: 78: // change all file's permissions to 777 before deleting 79: change_file_perms($file_path, 10, 0777, $name_prefix); 80: delete_files($file_path, 10, $name_prefix); 81: 82: echo "Done\n"; 83: ?> 84: --CLEAN-- 85: <?php 86: rmdir(dirname(__FILE__)."/is_writable_variation2/"); 87: ?> 88: --EXPECTF-- 89: *** Testing is_writable(): usage variations *** 90: 91: *** Testing is_writable() on directory without write permission *** 92: bool(false) 93: bool(false) 94: 95: *** Testing miscelleneous input for is_writable() function *** 96: -- Iteration 1 -- 97: bool(true) 98: bool(true) 99: -- Iteration 2 -- 100: bool(true) 101: bool(true) 102: -- Iteration 3 -- 103: bool(true) 104: bool(true) 105: -- Iteration 4 -- 106: bool(false) 107: bool(false) 108: -- Iteration 5 -- 109: bool(true) 110: bool(true) 111: -- Iteration 6 -- 112: bool(true) 113: bool(true) 114: -- Iteration 7 -- 115: bool(false) 116: bool(false) 117: -- Iteration 8 -- 118: bool(true) 119: bool(true) 120: -- Iteration 9 -- 121: bool(false) 122: bool(false) 123: -- Iteration 10 -- 124: bool(false) 125: bool(false) 126: Done