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