1--TEST-- 2Test rename() function : variation - various invalid paths 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--SKIPIF-- 6<?php 7if(substr(PHP_OS, 0, 3) != "WIN") 8 die("skip run only on Windows"); 9?> 10--FILE-- 11<?php 12/* Prototype : bool rename(string old_name, string new_name[, resource context]) 13 * Description: Rename a file 14 * Source code: ext/standard/file.c 15 * Alias to functions: 16 */ 17/* An array of files */ 18$names_arr = array( 19 /* Invalid args */ 20 -1, /* -1 is just a valid filename on windows */ 21 TRUE, /* 1 as well, (string)TRUE > "1" */ 22 FALSE, 23 NULL, 24 "", // I think both p8 and php are wrong on the messages here 25 //p8 generates different messages to php, php is probably wrong 26 //php has either "File Exists" or "Permission Denied". 27 " ", 28 "\0", 29 30 // as before 31 array(), 32 33 /* prefix with path separator of a non existing directory*/ 34 "/no/such/file/dir", 35 "php/php" 36 37); 38 39/* disable notice so we don't get the array to string conversion notice for "$name" where $name = array() */ 40error_reporting(E_ALL ^ E_NOTICE); 41 42echo "*** Testing rename() with obscure files ***\n"; 43$file_path = dirname(__FILE__)."/renameVar13"; 44$aFile = $file_path.'/afile.tmp'; 45 46if (!mkdir($file_path)) { 47 die("fail to create $file_path tmp dir"); 48} 49 50for( $i=0; $i < count($names_arr); $i++ ) { 51 $name = $names_arr[$i]; 52 echo "-- $i testing '$name' " . gettype($name) . " --\n"; 53 54 touch($aFile); 55 var_dump(rename($aFile, $name)); 56 if (file_exists($name)) { 57 @unlink($name); 58 } 59 60 if (file_exists($aFile)) { 61 @unlink($aFile); 62 } 63 var_dump(rename($name, $aFile)); 64 if (file_exists($aFile)) { 65 @unlink($aFile); 66 } 67} 68 69rmdir($file_path); 70echo "\n*** Done ***\n"; 71?> 72--EXPECTF-- 73*** Testing rename() with obscure files *** 74-- 0 testing '-1' integer -- 75bool(true) 76 77Warning: rename(-1,%s/renameVar13/afile.tmp): The system cannot find the file specified. (code: 2) in %s on line %d 78bool(false) 79-- 1 testing '1' boolean -- 80bool(true) 81 82Warning: rename(1,%s/renameVar13/afile.tmp): The system cannot find the file specified. (code: 2) in %s on line %d 83bool(false) 84-- 2 testing '' boolean -- 85 86Warning: rename(%s/renameVar13/afile.tmp,): %s in %s on line %d 87bool(false) 88 89Warning: rename(,%s/renameVar13/afile.tmp): %s in %s on line %d 90bool(false) 91-- 3 testing '' NULL -- 92 93Warning: rename(%s/renameVar13/afile.tmp,): %s in %s on line %d 94bool(false) 95 96Warning: rename(,%s/renameVar13/afile.tmp): %s in %s on line %d 97bool(false) 98-- 4 testing '' string -- 99 100Warning: rename(%s/renameVar13/afile.tmp,): %s in %s on line %d 101bool(false) 102 103Warning: rename(,%s/renameVar13/afile.tmp):%s in %s on line %d 104bool(false) 105-- 5 testing ' ' string -- 106 107Warning: rename(%s/renameVar13/afile.tmp, ): The filename, directory name, or volume label syntax is incorrect. (code: 123) in %s on line %d 108bool(false) 109 110Warning: rename( ,%s/renameVar13/afile.tmp): The filename, directory name, or volume label syntax is incorrect. (code: 123) in %s on line %d 111bool(false) 112-- 6 testing '' string -- 113bool(false) 114bool(false) 115-- 7 testing 'Array' array -- 116 117Warning: rename() expects parameter 2 to be string, array given in %s on line %d 118bool(false) 119 120Warning: file_exists() expects parameter 1 to be string, array given in %s on line %d 121 122Warning: rename() expects parameter 1 to be string, array given in %s on line %d 123bool(false) 124-- 8 testing '/no/such/file/dir' string -- 125 126Warning: rename(%s/renameVar13/afile.tmp,/no/such/file/dir): The system cannot find the path specified. (code: 3) in %s on line %d 127bool(false) 128 129Warning: rename(/no/such/file/dir,%s/renameVar13/afile.tmp): The system cannot find the path specified. (code: 3) in %s on line %d 130bool(false) 131-- 9 testing 'php/php' string -- 132 133Warning: rename(%s/renameVar13/afile.tmp,php/php): The system cannot find the path specified. (code: 3) in %s on line %d 134bool(false) 135 136Warning: rename(php/php,%s/renameVar13/afile.tmp): The system cannot find the path specified. (code: 3) in %s on line %d 137bool(false) 138 139*** Done *** 140 141