rename_variation1-win32.phpt 1.8 KB

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