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