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