rename_variation.phpt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. --TEST--
  2. Test rename() function: usage variations-1 (Bug#42638)
  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. mkdir("$file_path/rename_variation");
  14. /* rename files across directories */
  15. echo "*** Testing rename() : rename files across directories ***\n";
  16. $src_filenames = array(
  17. "$file_path/rename_variation/rename_variation.tmp",
  18. /* Testing a file trailing slash */
  19. "$file_path/rename_variation/rename_variation.tmp/",
  20. /* Testing file with double slashes */
  21. "$file_path/rename_variation//rename_variation.tmp",
  22. "$file_path//rename_variation//rename_variation.tmp",
  23. );
  24. $counter = 1;
  25. /* loop through each $file and rename it to rename_variation_renamed.tmp */
  26. foreach($src_filenames as $src_filename) {
  27. echo "-- Iteration $counter --\n";
  28. $fp = fopen("$file_path/rename_variation/rename_variation.tmp", "w");
  29. fclose($fp);
  30. $dest_filename = "$file_path/rename_variation_renamed.tmp";
  31. var_dump( rename($src_filename, $dest_filename) );
  32. // ensure that file got renamed to new name
  33. var_dump( file_exists($src_filename) ); // expecting false
  34. var_dump( file_exists($dest_filename) ); // expecting true
  35. $counter++;
  36. // unlink the file
  37. unlink($dest_filename);
  38. }
  39. // clean the temp dir and file
  40. rmdir("$file_path/rename_variation");
  41. echo "Done\n";
  42. ?>
  43. --EXPECTF--
  44. *** Testing rename() : rename files across directories ***
  45. -- Iteration 1 --
  46. bool(true)
  47. bool(false)
  48. bool(true)
  49. -- Iteration 2 --
  50. Warning: rename(%s,%s): Not a directory in %s on line %d
  51. bool(false)
  52. bool(false)
  53. bool(false)
  54. Warning: unlink(%s): No such file or directory in %s on line %d
  55. -- Iteration 3 --
  56. bool(true)
  57. bool(false)
  58. bool(true)
  59. -- Iteration 4 --
  60. bool(true)
  61. bool(false)
  62. bool(true)
  63. Done