1--TEST--
2Test rename() function : variation - various relative, absolute paths
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--SKIPIF--
6<?php
7if(substr(PHP_OS, 0, 3) != "WIN")
8  die("skip Only valid for Windows");
9?>
10--FILE--
11<?php
12echo "*** Testing rename() with absolute and relative paths ***\n";
13$mainDir = "renameVar11";
14$subDir = "renameVar11Sub";
15$absMainDir = __DIR__."\\".$mainDir;
16mkdir($absMainDir);
17$absSubDir = $absMainDir."\\".$subDir;
18mkdir($absSubDir);
19
20$fromFile = "renameMe.tmp";
21$toFile = "IwasRenamed.tmp";
22
23$old_dir_path = getcwd();
24chdir(__DIR__);
25$unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3);
26
27
28$allDirs = array(
29  // absolute paths
30  "$absSubDir\\",
31  "$absSubDir\\..\\".$subDir,
32  "$absSubDir\\\\..\\.\\".$subDir,
33  "$absSubDir\\..\\..\\".$mainDir."\\.\\".$subDir,
34  "$absSubDir\\..\\\\\\".$subDir."\\\\..\\\\..\\".$subDir,
35  "$absSubDir\\BADDIR",
36
37  // relative paths
38  $mainDir."\\".$subDir,
39  $mainDir."\\\\".$subDir,
40   $mainDir."\\\\\\".$subDir,
41  ".\\".$mainDir."\\..\\".$mainDir."\\".$subDir,
42  "BADDIR",
43
44  // unixifed path
45  $unixifiedDir,
46);
47
48for($i = 0; $i<count($allDirs); $i++) {
49  $j = $i+1;
50  $dir = $allDirs[$i];
51  echo "\n-- Iteration $j --\n";
52  touch($absSubDir."\\".$fromFile);
53  $res = rename($dir."\\".$fromFile, $dir."\\".$toFile);
54  var_dump($res);
55  if ($res == true) {
56     $res = rename($dir."\\".$toFile, $dir."\\".$fromFile);
57     var_dump($res);
58  }
59  unlink($absSubDir."\\".$fromFile);
60}
61
62chdir($old_dir_path);
63rmdir($absSubDir);
64rmdir($absMainDir);
65
66echo "\n*** Done ***\n";
67?>
68--EXPECTF--
69*** Testing rename() with absolute and relative paths ***
70
71-- Iteration 1 --
72bool(true)
73bool(true)
74
75-- Iteration 2 --
76bool(true)
77bool(true)
78
79-- Iteration 3 --
80bool(true)
81bool(true)
82
83-- Iteration 4 --
84bool(true)
85bool(true)
86
87-- Iteration 5 --
88
89Warning: rename(%s\renameVar11\renameVar11Sub\..\\\renameVar11Sub\\..\\..\renameVar11Sub\renameMe.tmp,%s\renameVar11\renameVar11Sub\..\\\renameVar11Sub\\..\\..\renameVar11Sub\IwasRenamed.tmp): The system cannot find the path specified (code: 3) in %s on line %d
90bool(false)
91
92-- Iteration 6 --
93
94Warning: rename(%s\renameVar11\renameVar11Sub\BADDIR\renameMe.tmp,%s\renameVar11\renameVar11Sub\BADDIR\IwasRenamed.tmp): The system cannot find the path specified (code: 3) in %s on line %d
95bool(false)
96
97-- Iteration 7 --
98bool(true)
99bool(true)
100
101-- Iteration 8 --
102bool(true)
103bool(true)
104
105-- Iteration 9 --
106bool(true)
107bool(true)
108
109-- Iteration 10 --
110bool(true)
111bool(true)
112
113-- Iteration 11 --
114
115Warning: rename(BADDIR\renameMe.tmp,BADDIR\IwasRenamed.tmp): The system cannot find the path specified (code: 3) in %s on line %d
116bool(false)
117
118-- Iteration 12 --
119bool(true)
120bool(true)
121
122*** Done ***
123