rename_variation11-win32.phpt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. --TEST--
  2. Test rename() function : variation - various relative, absolute 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 Only valid 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. echo "*** Testing rename() with absolute and relative paths ***\n";
  18. $mainDir = "renameVar11";
  19. $subDir = "renameVar11Sub";
  20. $absMainDir = dirname(__FILE__)."\\".$mainDir;
  21. mkdir($absMainDir);
  22. $absSubDir = $absMainDir."\\".$subDir;
  23. mkdir($absSubDir);
  24. $fromFile = "renameMe.tmp";
  25. $toFile = "IwasRenamed.tmp";
  26. $old_dir_path = getcwd();
  27. chdir(dirname(__FILE__));
  28. $unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3);
  29. $allDirs = array(
  30. // absolute paths
  31. "$absSubDir\\",
  32. "$absSubDir\\..\\".$subDir,
  33. "$absSubDir\\\\..\\.\\".$subDir,
  34. "$absSubDir\\..\\..\\".$mainDir."\\.\\".$subDir,
  35. "$absSubDir\\..\\\\\\".$subDir."\\\\..\\\\..\\".$subDir,
  36. "$absSubDir\\BADDIR",
  37. // relative paths
  38. $mainDir."\\".$subDir,
  39. $mainDir."\\\\".$subDir,
  40. $mainDir."\\\\\\".$subDir,
  41. ".\\".$mainDir."\\..\\".$mainDir."\\".$subDir,
  42. "BADDIR",
  43. // unixifed path
  44. $unixifiedDir,
  45. );
  46. for($i = 0; $i<count($allDirs); $i++) {
  47. $j = $i+1;
  48. $dir = $allDirs[$i];
  49. echo "\n-- Iteration $j --\n";
  50. touch($absSubDir."\\".$fromFile);
  51. $res = rename($dir."\\".$fromFile, $dir."\\".$toFile);
  52. var_dump($res);
  53. if ($res == true) {
  54. $res = rename($dir."\\".$toFile, $dir."\\".$fromFile);
  55. var_dump($res);
  56. }
  57. unlink($absSubDir."\\".$fromFile);
  58. }
  59. chdir($old_dir_path);
  60. rmdir($absSubDir);
  61. rmdir($absMainDir);
  62. echo "\n*** Done ***\n";
  63. ?>
  64. --EXPECTF--
  65. *** Testing rename() with absolute and relative paths ***
  66. -- Iteration 1 --
  67. bool(true)
  68. bool(true)
  69. -- Iteration 2 --
  70. bool(true)
  71. bool(true)
  72. -- Iteration 3 --
  73. bool(true)
  74. bool(true)
  75. -- Iteration 4 --
  76. bool(true)
  77. bool(true)
  78. -- Iteration 5 --
  79. Warning: rename(%s\renameVar11\renameVar11Sub\..\\\renameVar11Sub\\..\\..\renameVar11Sub\renameMe.tmp,%s\renameVar11\renameVar11Sub\..\\\renameVar11Sub\\..\\..\renameVar11Sub\IwasRenamed.tmp): The system cannot find the path specified. (code: 3) in %s on line %d
  80. bool(false)
  81. -- Iteration 6 --
  82. Warning: rename(%s\renameVar11\renameVar11Sub\BADDIR\renameMe.tmp,%s\renameVar11\renameVar11Sub\BADDIR\IwasRenamed.tmp): The system cannot find the path specified. (code: 3) in %s on line %d
  83. bool(false)
  84. -- Iteration 7 --
  85. bool(true)
  86. bool(true)
  87. -- Iteration 8 --
  88. bool(true)
  89. bool(true)
  90. -- Iteration 9 --
  91. bool(true)
  92. bool(true)
  93. -- Iteration 10 --
  94. bool(true)
  95. bool(true)
  96. -- Iteration 11 --
  97. Warning: rename(BADDIR\renameMe.tmp,BADDIR\IwasRenamed.tmp): The system cannot find the path specified. (code: 3) in %s on line %d
  98. bool(false)
  99. -- Iteration 12 --
  100. bool(true)
  101. bool(true)
  102. *** Done ***