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
12/* Prototype  : bool rename(string old_name, string new_name[, resource context])
13 * Description: Rename a file
14 * Source code: ext/standard/file.c
15 * Alias to functions:
16 */
17
18echo "*** Testing rename() with absolute and relative paths ***\n";
19$mainDir = "renameVar11";
20$subDir = "renameVar11Sub";
21$absMainDir = dirname(__FILE__)."\\".$mainDir;
22mkdir($absMainDir);
23$absSubDir = $absMainDir."\\".$subDir;
24mkdir($absSubDir);
25
26$fromFile = "renameMe.tmp";
27$toFile = "IwasRenamed.tmp";
28
29$old_dir_path = getcwd();
30chdir(dirname(__FILE__));
31$unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3);
32
33
34$allDirs = array(
35  // absolute paths
36  "$absSubDir\\",
37  "$absSubDir\\..\\".$subDir,
38  "$absSubDir\\\\..\\.\\".$subDir,
39  "$absSubDir\\..\\..\\".$mainDir."\\.\\".$subDir,
40  "$absSubDir\\..\\\\\\".$subDir."\\\\..\\\\..\\".$subDir,
41  "$absSubDir\\BADDIR",
42
43  // relative paths
44  $mainDir."\\".$subDir,
45  $mainDir."\\\\".$subDir,
46   $mainDir."\\\\\\".$subDir,
47  ".\\".$mainDir."\\..\\".$mainDir."\\".$subDir,
48  "BADDIR",
49
50  // unixifed path
51  $unixifiedDir,
52);
53
54for($i = 0; $i<count($allDirs); $i++) {
55  $j = $i+1;
56  $dir = $allDirs[$i];
57  echo "\n-- Iteration $j --\n";
58  touch($absSubDir."\\".$fromFile);
59  $res = rename($dir."\\".$fromFile, $dir."\\".$toFile);
60  var_dump($res);
61  if ($res == true) {
62     $res = rename($dir."\\".$toFile, $dir."\\".$fromFile);
63     var_dump($res);
64  }
65  unlink($absSubDir."\\".$fromFile);
66}
67
68chdir($old_dir_path);
69rmdir($absSubDir);
70rmdir($absMainDir);
71
72echo "\n*** Done ***\n";
73?>
74--EXPECTF--
75*** Testing rename() with absolute and relative paths ***
76
77-- Iteration 1 --
78bool(true)
79bool(true)
80
81-- Iteration 2 --
82bool(true)
83bool(true)
84
85-- Iteration 3 --
86bool(true)
87bool(true)
88
89-- Iteration 4 --
90bool(true)
91bool(true)
92
93-- Iteration 5 --
94
95Warning: 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
96bool(false)
97
98-- Iteration 6 --
99
100Warning: 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
101bool(false)
102
103-- Iteration 7 --
104bool(true)
105bool(true)
106
107-- Iteration 8 --
108bool(true)
109bool(true)
110
111-- Iteration 9 --
112bool(true)
113bool(true)
114
115-- Iteration 10 --
116bool(true)
117bool(true)
118
119-- Iteration 11 --
120
121Warning: rename(BADDIR\renameMe.tmp,BADDIR\IwasRenamed.tmp): The system cannot find the path specified. (code: 3) in %s on line %d
122bool(false)
123
124-- Iteration 12 --
125bool(true)
126bool(true)
127
128*** Done ***
129