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/* creating directory */
18$file_path = __DIR__;
19
20// rename dirs across directories
21echo "\n*** Testing rename() : renaming directory across directories ***\n";
22$src_dirs = array (
23  /* Testing simple directory tree */
24  "$file_path/rename_variation/",
25
26  /* Testing a dir with trailing slash */
27  "$file_path/rename_variation/",
28
29  /* Testing dir with double trailing slashes */
30  "$file_path//rename_variation//",
31);
32
33$dest_dir = "$file_path/rename_variation_dir";
34
35// create the $dest_dir
36mkdir($dest_dir);
37
38$counter = 1;
39
40/* loop through each $src_dirs and rename it to  $dest_dir */
41foreach($src_dirs as $src_dir) {
42  echo "-- Iteration $counter --\n";
43
44  // create the src dir
45  mkdir("$file_path/rename_variation/");
46  // rename the src dir to a new dir in dest dir
47  var_dump( rename($src_dir, $dest_dir."/new_dir") );
48  // ensure that dir was renamed
49  var_dump( file_exists($src_dir) );  // expecting false
50  var_dump( file_exists($dest_dir."/new_dir") ); // expecting true
51
52  // remove the new dir
53  rmdir($dest_dir."/new_dir");
54  $counter++;
55}
56
57echo "Done\n";
58?>
59--CLEAN--
60<?php
61$file_path = __DIR__;
62unlink($file_path."/rename_variation_link.tmp");
63unlink($file_path."/rename_variation.tmp");
64rmdir($file_path."/rename_variation_dir");
65?>
66--EXPECT--
67*** Testing rename() : renaming directory across directories ***
68-- Iteration 1 --
69bool(true)
70bool(false)
71bool(true)
72-- Iteration 2 --
73bool(true)
74bool(false)
75bool(true)
76-- Iteration 3 --
77bool(true)
78bool(false)
79bool(true)
80Done
81