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. Not for 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 18echo "*** Testing rename() with obscure files ***\n"; 19$file_path = dirname(__FILE__)."/renameVar13"; 20$aFile = $file_path.'/afile.tmp'; 21 22mkdir($file_path); 23 24/* An array of files */ 25$names_arr = array( 26 /* Invalid args */ 27 -1, 28 TRUE, 29 FALSE, 30 NULL, 31 "", 32 " ", 33 "\0", 34 array(), 35 36 /* prefix with path separator of a non existing directory*/ 37 "/no/such/file/dir", 38 "php/php" 39 40); 41 42for( $i=0; $i<count($names_arr); $i++ ) { 43 $name = $names_arr[$i]; 44 echo @"-- testing '$name' --\n"; 45 touch($aFile); 46 var_dump(rename($aFile, $name)); 47 if (file_exists($name)) { 48 unlink($name); 49 } 50 if (file_exists($aFile)) { 51 unlink($aFile); 52 } 53 var_dump(rename($name, $aFile)); 54 if (file_exists($aFile)) { 55 unlink($aFile); 56 } 57} 58 59rmdir($file_path); 60echo "\n*** Done ***\n"; 61?> 62--EXPECTF-- 63*** Testing rename() with obscure files *** 64-- testing '-1' -- 65bool(true) 66 67Warning: rename(-1,%s/renameVar13/afile.tmp): No such file or directory in %s on line %d 68bool(false) 69-- testing '1' -- 70bool(true) 71 72Warning: rename(1,%s/renameVar13/afile.tmp): No such file or directory in %s on line %d 73bool(false) 74-- testing '' -- 75 76Warning: rename(%s/renameVar13/afile.tmp,): %s in %s on line %d 77bool(false) 78 79Warning: rename(,%s/renameVar13/afile.tmp): %s in %s on line %d 80bool(false) 81-- testing '' -- 82 83Warning: rename(%s/renameVar13/afile.tmp,): %s in %s on line %d 84bool(false) 85 86Warning: rename(,%s/renameVar13/afile.tmp): %s in %s on line %d 87bool(false) 88-- testing '' -- 89 90Warning: rename(%s/renameVar13/afile.tmp,): %s in %s on line %d 91bool(false) 92 93Warning: rename(,%s/renameVar13/afile.tmp): %s in %s on line %d 94bool(false) 95-- testing ' ' -- 96bool(true) 97 98Warning: rename( ,%s/renameVar13/afile.tmp): No such file or directory in %s on line %d 99bool(false) 100-- testing '%s' -- 101 102Warning: rename() %s in %s on line %d 103bool(false) 104 105Warning: file_exists() expects parameter 1 to be a valid path, string given in %s on line %d 106 107Warning: rename() expects parameter 1 to be a valid path, string given in %s on line %d 108bool(false) 109-- testing 'Array' -- 110 111Warning: rename() expects parameter 2 to be a valid path, array given in %s on line %d 112bool(false) 113 114Warning: file_exists() expects parameter 1 to be a valid path, array given in %s on line %d 115 116Warning: rename() expects parameter 1 to be a valid path, array given in %s on line %d 117bool(false) 118-- testing '/no/such/file/dir' -- 119 120Warning: rename(%s/renameVar13/afile.tmp,/no/such/file/dir): No such file or directory in %s on line %d 121bool(false) 122 123Warning: rename(/no/such/file/dir,%s/renameVar13/afile.tmp): No such file or directory in %s on line %d 124bool(false) 125-- testing 'php/php' -- 126 127Warning: rename(%s/renameVar13/afile.tmp,php/php): %s directory in %s on line %d 128bool(false) 129 130Warning: rename(php/php,%s/renameVar13/afile.tmp): %s directory in %s on line %d 131bool(false) 132 133*** Done *** 134