rename_variation13-win32.phpt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. --TEST--
  2. Test rename() function : variation - various invalid paths
  3. --CREDITS--
  4. Dave Kelsey <d_kelsey@uk.ibm.com>
  5. --SKIPIF--
  6. <?php
  7. if(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. // as before
  30. array(),
  31. /* prefix with path separator of a non existing directory*/
  32. "/no/such/file/dir",
  33. "php/php"
  34. );
  35. /* disable notice so we don't get the array to string conversion notice for "$name" where $name = array() */
  36. error_reporting(E_ALL ^ E_NOTICE);
  37. echo "*** Testing rename() with obscure files ***\n";
  38. $file_path = dirname(__FILE__)."/renameVar13";
  39. $aFile = $file_path.'/afile.tmp';
  40. if (!mkdir($file_path)) {
  41. die("fail to create $file_path tmp dir");
  42. }
  43. for( $i=0; $i < count($names_arr); $i++ ) {
  44. $name = $names_arr[$i];
  45. echo "-- $i testing '$name' " . gettype($name) . " --\n";
  46. touch($aFile);
  47. var_dump(rename($aFile, $name));
  48. if (file_exists($name)) {
  49. @unlink($name);
  50. }
  51. if (file_exists($aFile)) {
  52. @unlink($aFile);
  53. }
  54. var_dump(rename($name, $aFile));
  55. if (file_exists($aFile)) {
  56. @unlink($aFile);
  57. }
  58. }
  59. rmdir($file_path);
  60. echo "\n*** Done ***\n";
  61. ?>
  62. --EXPECTF--
  63. *** Testing rename() with obscure files ***
  64. -- 0 testing '-1' integer --
  65. bool(true)
  66. Warning: rename(-1,%safile.tmp): The system cannot find the file specified. (code: 2) in %srename_variation13-win32.php on line %d
  67. bool(false)
  68. -- 1 testing '1' boolean --
  69. bool(true)
  70. Warning: rename(1,%safile.tmp): The system cannot find the file specified. (code: 2) in %srename_variation13-win32.php on line %d
  71. bool(false)
  72. -- 2 testing '' boolean --
  73. Warning: rename(%safile.tmp,): %r(Invalid argument|The system cannot find the path specified. \(code: 3\))%r in %srename_variation13-win32.php on line %d
  74. bool(false)
  75. Warning: rename(,%safile.tmp): %r(Invalid argument|The system cannot find the path specified. \(code: 3\))%r in %srename_variation13-win32.php on line %d
  76. bool(false)
  77. -- 3 testing '' NULL --
  78. Warning: rename(%safile.tmp,): %r(Invalid argument|The system cannot find the path specified. \(code: 3\))%r in %srename_variation13-win32.php on line %d
  79. bool(false)
  80. Warning: rename(,%safile.tmp): %r(Invalid argument|The system cannot find the path specified. \(code: 3\))%r in %srename_variation13-win32.php on line %d
  81. bool(false)
  82. -- 4 testing '' string --
  83. Warning: rename(%safile.tmp,): %r(Invalid argument|The system cannot find the path specified. \(code: 3\))%r in %srename_variation13-win32.php on line %d
  84. bool(false)
  85. Warning: rename(,%safile.tmp): %r(Invalid argument|The system cannot find the path specified. \(code: 3\))%r in %srename_variation13-win32.php on line %d
  86. bool(false)
  87. -- 5 testing ' ' string --
  88. Warning: rename(%s): The filename, directory name, or volume label syntax is incorrect. (code: 123) in %srename_variation13-win32.php on line %d
  89. bool(false)
  90. Warning: rename(%s): The filename, directory name, or volume label syntax is incorrect. (code: 123) in %srename_variation13-win32.php on line %d
  91. bool(false)
  92. -- 6 testing '�' string --
  93. Warning: rename() expects parameter 2 to be a valid path, string given in %srename_variation13-win32.php on line %d
  94. bool(false)
  95. Warning: file_exists() expects parameter 1 to be a valid path, string given in %srename_variation13-win32.php on line %d
  96. Warning: rename() expects parameter 1 to be a valid path, string given in %srename_variation13-win32.php on line %d
  97. bool(false)
  98. -- 7 testing 'Array' array --
  99. Warning: rename() expects parameter 2 to be a valid path, array given in %srename_variation13-win32.php on line %d
  100. bool(false)
  101. Warning: file_exists() expects parameter 1 to be a valid path, array given in %srename_variation13-win32.php on line %d
  102. Warning: rename() expects parameter 1 to be a valid path, array given in %srename_variation13-win32.php on line %d
  103. bool(false)
  104. -- 8 testing '/no/such/file/dir' string --
  105. Warning: rename(%safile.tmp,/no/such/file/dir): The system cannot find the path specified. (code: 3) in %srename_variation13-win32.php on line %d
  106. bool(false)
  107. Warning: rename(/no/such/file/dir,%safile.tmp): The system cannot find the path specified. (code: 3) in %srename_variation13-win32.php on line %d
  108. bool(false)
  109. -- 9 testing 'php/php' string --
  110. Warning: rename(%safile.tmp,php/php): The system cannot find the path specified. (code: 3) in %srename_variation13-win32.php on line %d
  111. bool(false)
  112. Warning: rename(php/php,%safile.tmp): The system cannot find the path specified. (code: 3) in %srename_variation13-win32.php on line %d
  113. bool(false)
  114. *** Done ***