Return to 006_error.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: Test fileperms(), chmod() functions: error conditions 3: --SKIPIF-- 4: <?php 5: if (substr(PHP_OS, 0, 3) == 'WIN') { 6: die('skip Not on Windows'); 7: } 8: // Skip if being run by root 9: $filename = dirname(__FILE__)."/006_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: ?> 20: --FILE-- 21: <?php 22: /* 23: Prototype: int fileperms ( string $filename ) 24: Description: Returns the permissions on the file, or FALSE in case of an error 25: 26: Prototype: bool chmod ( string $filename, int $mode ) 27: Description: Attempts to change the mode of the file specified by 28: filename to that given in mode 29: */ 30: 31: echo "*** Testing error conditions for fileperms(), chmod() ***\n"; 32: 33: /* With standard files and dirs */ 34: var_dump( chmod("/etc/passwd", 0777) ); 35: printf("%o", fileperms("/etc/passwd") ); 36: echo "\n"; 37: clearstatcache(); 38: 39: var_dump( chmod("/etc", 0777) ); 40: printf("%o", fileperms("/etc") ); 41: echo "\n"; 42: clearstatcache(); 43: 44: /* With non-existing file or dir */ 45: var_dump( chmod("/no/such/file/dir", 0777) ); 46: var_dump( fileperms("/no/such/file/dir") ); 47: echo "\n"; 48: 49: /* With args less than expected */ 50: $fp = fopen(dirname(__FILE__)."/006_error.tmp", "w"); 51: fclose($fp); 52: var_dump( chmod(dirname(__FILE__)."/006_error.tmp") ); 53: var_dump( chmod("nofile") ); 54: var_dump( chmod() ); 55: var_dump( fileperms() ); 56: 57: /* With args greater than expected */ 58: var_dump( chmod(dirname(__FILE__)."/006_error.tmp", 0755, TRUE) ); 59: var_dump( fileperms(dirname(__FILE__)."/006_error.tmp", 0777) ); 60: var_dump( fileperms("nofile", 0777) ); 61: 62: echo "\n*** Done ***\n"; 63: ?> 64: --CLEAN-- 65: <?php 66: unlink( dirname(__FILE__)."/006_error.tmp"); 67: ?> 68: --EXPECTF-- 69: *** Testing error conditions for fileperms(), chmod() *** 70: 71: Warning: chmod(): %s in %s on line %d 72: bool(false) 73: 100%d44 74: 75: Warning: chmod(): %s in %s on line %d 76: bool(false) 77: 40755 78: 79: Warning: chmod(): No such file or directory in %s on line %d 80: bool(false) 81: 82: Warning: fileperms(): stat failed for /no/such/file/dir in %s on line %d 83: bool(false) 84: 85: 86: Warning: chmod() expects exactly 2 parameters, 1 given in %s on line %d 87: NULL 88: 89: Warning: chmod() expects exactly 2 parameters, 1 given in %s on line %d 90: NULL 91: 92: Warning: chmod() expects exactly 2 parameters, 0 given in %s on line %d 93: NULL 94: 95: Warning: fileperms() expects exactly 1 parameter, 0 given in %s on line %d 96: NULL 97: 98: Warning: chmod() expects exactly 2 parameters, 3 given in %s on line %d 99: NULL 100: 101: Warning: fileperms() expects exactly 1 parameter, 2 given in %s on line %d 102: NULL 103: 104: Warning: fileperms() expects exactly 1 parameter, 2 given in %s on line %d 105: NULL 106: 107: *** Done ***