Return to tempnam_variation3.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: Test tempnam() function: usage variations - obscure prefixes 3: --SKIPIF-- 4: <?php 5: if(substr(PHP_OS, 0, 3) == "WIN") 6: die("skip Do not run on Windows"); 7: ?> 8: --FILE-- 9: <?php 10: /* Prototype: string tempnam ( string $dir, string $prefix ); 11: Description: Create file with unique file name. 12: */ 13: 14: /* Passing invalid/non-existing args for $prefix */ 15: 16: echo "*** Testing tempnam() with obscure prefixes ***\n"; 17: $file_path = dirname(__FILE__)."/tempnamVar3"; 18: mkdir($file_path); 19: 20: /* An array of prefixes */ 21: $names_arr = array( 22: /* Invalid args */ 23: -1, 24: TRUE, 25: FALSE, 26: NULL, 27: "", 28: " ", 29: "\0", 30: array(), 31: 32: /* prefix with path separator of a non existing directory*/ 33: "/no/such/file/dir", 34: "php/php" 35: 36: ); 37: 38: for( $i=0; $i<count($names_arr); $i++ ) { 39: echo "-- Iteration $i --\n"; 40: $file_name = tempnam("$file_path", $names_arr[$i]); 41: 42: /* creating the files in existing dir */ 43: if( file_exists($file_name) ) { 44: echo "File name is => "; 45: print($file_name); 46: echo "\n"; 47: 48: echo "File permissions are => "; 49: printf("%o", fileperms($file_name) ); 50: echo "\n"; 51: 52: echo "File created in => "; 53: $file_dir = dirname($file_name); 54: 55: if ($file_dir == sys_get_temp_dir()) { 56: echo "temp dir\n"; 57: } 58: else if ($file_dir == $file_path) { 59: echo "directory specified\n"; 60: } 61: else { 62: echo "unknown location\n"; 63: } 64: 65: } 66: else { 67: echo "-- File is not created --\n"; 68: } 69: 70: unlink($file_name); 71: } 72: 73: rmdir($file_path); 74: echo "\n*** Done ***\n"; 75: ?> 76: --EXPECTF-- 77: *** Testing tempnam() with obscure prefixes *** 78: -- Iteration 0 -- 79: File name is => %s/%s 80: File permissions are => 100600 81: File created in => directory specified 82: -- Iteration 1 -- 83: File name is => %s/%s 84: File permissions are => 100600 85: File created in => directory specified 86: -- Iteration 2 -- 87: File name is => %s/%s 88: File permissions are => 100600 89: File created in => directory specified 90: -- Iteration 3 -- 91: File name is => %s/%s 92: File permissions are => 100600 93: File created in => directory specified 94: -- Iteration 4 -- 95: File name is => %s/%s 96: File permissions are => 100600 97: File created in => directory specified 98: -- Iteration 5 -- 99: File name is => %s/%s 100: File permissions are => 100600 101: File created in => directory specified 102: -- Iteration 6 -- 1.1.1.2 ! misho 103: File name is => %s/%s ! 104: File permissions are => 100600 ! 105: File created in => directory specified 1.1 misho 106: -- Iteration 7 -- 107: 108: Warning: tempnam() expects parameter 2 to be string, array given in %s on line %d 109: -- File is not created -- 110: 111: Warning: unlink(): %s in %s on line %d 112: -- Iteration 8 -- 113: File name is => %s/dir%s 114: File permissions are => 100600 115: File created in => directory specified 116: -- Iteration 9 -- 117: File name is => %s/php%s 118: File permissions are => 100600 119: File created in => directory specified 120: 121: *** Done *** 122: