rename_variation1.phpt 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. --TEST--
  2. Test rename() function: usage variations-2
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) == 'WIN') {
  6. die('skip.. only for Linux');
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. /* creating directory */
  12. $file_path = __DIR__;
  13. // rename dirs across directories
  14. echo "\n*** Testing rename() : renaming directory across directories ***\n";
  15. $src_dirs = array (
  16. /* Testing simple directory tree */
  17. "$file_path/rename_variation1/",
  18. /* Testing a dir with trailing slash */
  19. "$file_path/rename_variation1/",
  20. /* Testing dir with double trailing slashes */
  21. "$file_path//rename_variation1//",
  22. );
  23. $dest_dir = "$file_path/rename_variation1_dir";
  24. // create the $dest_dir
  25. mkdir($dest_dir);
  26. $counter = 1;
  27. /* loop through each $src_dirs and rename it to $dest_dir */
  28. foreach($src_dirs as $src_dir) {
  29. echo "-- Iteration $counter --\n";
  30. // create the src dir
  31. mkdir("$file_path/rename_variation1/");
  32. // rename the src dir to a new dir in dest dir
  33. var_dump( rename($src_dir, $dest_dir."/new_dir") );
  34. // ensure that dir was renamed
  35. var_dump( file_exists($src_dir) ); // expecting false
  36. var_dump( file_exists($dest_dir."/new_dir") ); // expecting true
  37. // remove the new dir
  38. rmdir($dest_dir."/new_dir");
  39. $counter++;
  40. }
  41. echo "Done\n";
  42. ?>
  43. --CLEAN--
  44. <?php
  45. $file_path = __DIR__;
  46. rmdir($file_path."/rename_variation1_dir");
  47. ?>
  48. --EXPECT--
  49. *** Testing rename() : renaming directory across directories ***
  50. -- Iteration 1 --
  51. bool(true)
  52. bool(false)
  53. bool(true)
  54. -- Iteration 2 --
  55. bool(true)
  56. bool(false)
  57. bool(true)
  58. -- Iteration 3 --
  59. bool(true)
  60. bool(false)
  61. bool(true)
  62. Done