rename_variation12-win32.phpt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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') die('skip.. for Windows');
  8. ?>
  9. --FILE--
  10. <?php
  11. /* Prototype : bool rename(string old_name, string new_name[, resource context])
  12. * Description: Rename a file
  13. * Source code: ext/standard/file.c
  14. * Alias to functions:
  15. */
  16. /* Creating unique files in various dirs by passing relative paths to $dir arg */
  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. $allDirs = array(
  29. // absolute paths
  30. "$absSubDir/",
  31. "$absSubDir/../".$subDir,
  32. "$absSubDir//.././".$subDir,
  33. "$absSubDir/../../".$mainDir."/./".$subDir,
  34. "$absSubDir/..///".$subDir."//..//../".$subDir,
  35. "$absSubDir/BADDIR",
  36. // relative paths
  37. $mainDir."/".$subDir,
  38. $mainDir."//".$subDir,
  39. $mainDir."///".$subDir,
  40. "./".$mainDir."/../".$mainDir."/".$subDir,
  41. "BADDIR",
  42. );
  43. for($i = 0; $i<count($allDirs); $i++) {
  44. $j = $i+1;
  45. $dir = $allDirs[$i];
  46. echo "\n-- Iteration $j --\n";
  47. touch($absSubDir."/".$fromFile);
  48. $res = rename($dir."/".$fromFile, $dir."/".$toFile);
  49. var_dump($res);
  50. if ($res == true) {
  51. $res = rename($dir."/".$toFile, $dir."/".$fromFile);
  52. var_dump($res);
  53. }
  54. unlink($absSubDir."/".$fromFile);
  55. }
  56. chdir($old_dir_path);
  57. rmdir($absSubDir);
  58. rmdir($absMainDir);
  59. echo "\n*** Done ***\n";
  60. ?>
  61. --EXPECTF--
  62. *** Testing rename() with absolute and relative paths ***
  63. -- Iteration 1 --
  64. bool(true)
  65. bool(true)
  66. -- Iteration 2 --
  67. bool(true)
  68. bool(true)
  69. -- Iteration 3 --
  70. bool(true)
  71. bool(true)
  72. -- Iteration 4 --
  73. bool(true)
  74. bool(true)
  75. -- Iteration 5 --
  76. 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
  77. bool(false)
  78. -- Iteration 6 --
  79. 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
  80. bool(false)
  81. -- Iteration 7 --
  82. bool(true)
  83. bool(true)
  84. -- Iteration 8 --
  85. bool(true)
  86. bool(true)
  87. -- Iteration 9 --
  88. bool(true)
  89. bool(true)
  90. -- Iteration 10 --
  91. bool(true)
  92. bool(true)
  93. -- Iteration 11 --
  94. Warning: rename(BADDIR/renameMe.tmp,BADDIR/IwasRenamed.tmp): The system cannot find the path specified. (code: 3) in %s on line %d
  95. bool(false)
  96. *** Done ***