rename_variation-win32.phpt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. require __DIR__.'/file.inc';
  12. /* create directory */
  13. $file_path = __DIR__;
  14. mkdir("$file_path/rename_variation");
  15. /* rename files across directories */
  16. echo "*** Testing rename() : rename files across directories ***\n";
  17. $src_filenames = array(
  18. "$file_path/rename_variation/rename_variation.tmp",
  19. /* Testing a file trailing slash */
  20. "$file_path/rename_variation/rename_variation.tmp/",
  21. /* Testing file with double slashes */
  22. "$file_path/rename_variation//rename_variation.tmp",
  23. "$file_path//rename_variation//rename_variation.tmp",
  24. );
  25. $counter = 1;
  26. /* loop through each $file and rename it to rename_variation2.tmp */
  27. foreach($src_filenames as $src_filename) {
  28. echo "-- Iteration $counter --\n";
  29. $fp = fopen("$file_path/rename_variation/rename_variation.tmp", "w");
  30. fclose($fp);
  31. $dest_filename = "$file_path/rename_variation2.tmp";
  32. var_dump( rename($src_filename, $dest_filename) );
  33. // ensure that file got renamed to new name
  34. var_dump( file_exists($src_filename) ); // expecting false
  35. var_dump( file_exists($dest_filename) ); // expecting true
  36. $counter++;
  37. // unlink the file
  38. unlink($dest_filename);
  39. }
  40. rmdir("$file_path/rename_variation");
  41. echo "Done\n";
  42. ?>
  43. --CLEAN--
  44. <?php
  45. $file_path = __DIR__;
  46. unlink($file_path."/rename_variation_link.tmp");
  47. unlink($file_path."/rename_variation.tmp");
  48. rmdir($file_path."/rename_variation_dir");
  49. ?>
  50. --EXPECTF--
  51. *** Testing rename() : rename files across directories ***
  52. -- Iteration 1 --
  53. bool(true)
  54. bool(false)
  55. bool(true)
  56. -- Iteration 2 --
  57. Warning: rename(%s/rename_variation/rename_variation.tmp/,%s/rename_variation2.tmp): The filename, directory name, or volume label syntax is incorrect (code: 123) in %s on line %d
  58. bool(false)
  59. bool(false)
  60. bool(false)
  61. Warning: unlink(%s/rename_variation2.tmp): No such file or directory in %s on line %d
  62. -- Iteration 3 --
  63. bool(true)
  64. bool(false)
  65. bool(true)
  66. -- Iteration 4 --
  67. bool(true)
  68. bool(false)
  69. bool(true)
  70. Done