1--TEST--
2Test rename() function : variation - various invalid paths
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--SKIPIF--
6<?php
7if(substr(PHP_OS, 0, 3) != "WIN")
8  die("skip run only on 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/* An array of files */
18$names_arr = array(
19  /* Invalid args */
20  -1, /* -1 is just a valid filename on windows */
21  TRUE, /* 1 as well, (string)TRUE > "1" */
22  FALSE,
23  NULL,
24  "", // I think both p8 and php are wrong on the messages here
25  //p8 generates different messages to php, php is probably wrong
26  //php has either "File Exists" or "Permission Denied".
27  " ",
28  "\0",
29
30  // as before
31  array(),
32
33  /* prefix with path separator of a non existing directory*/
34  "/no/such/file/dir",
35  "php/php"
36
37);
38
39/* disable notice so we don't get the array to string conversion notice for "$name" where $name = array() */
40error_reporting(E_ALL ^ E_NOTICE);
41
42echo "*** Testing rename() with obscure files ***\n";
43$file_path = dirname(__FILE__)."/renameVar13";
44$aFile = $file_path.'/afile.tmp';
45
46if (!mkdir($file_path)) {
47	die("fail to create $file_path tmp dir");
48}
49
50for( $i=0; $i < count($names_arr); $i++ ) {
51  $name = $names_arr[$i];
52  echo "-- $i testing '$name' " . gettype($name) . " --\n";
53
54  touch($aFile);
55  var_dump(rename($aFile, $name));
56  if (file_exists($name)) {
57     @unlink($name);
58  }
59
60  if (file_exists($aFile)) {
61     @unlink($aFile);
62  }
63  var_dump(rename($name, $aFile));
64  if (file_exists($aFile)) {
65     @unlink($aFile);
66  }
67}
68
69rmdir($file_path);
70echo "\n*** Done ***\n";
71?>
72--EXPECTF--
73*** Testing rename() with obscure files ***
74-- 0 testing '-1' integer --
75bool(true)
76
77Warning: rename(-1,%safile.tmp): The system cannot find the file specified. (code: 2) in %srename_variation13-win32.php on line %d
78bool(false)
79-- 1 testing '1' boolean --
80bool(true)
81
82Warning: rename(1,%safile.tmp): The system cannot find the file specified. (code: 2) in %srename_variation13-win32.php on line %d
83bool(false)
84-- 2 testing '' boolean --
85
86Warning: rename(%safile.tmp,): %r(Invalid argument|The system cannot find the path specified. \(code: 3\))%r in %srename_variation13-win32.php on line %d
87bool(false)
88
89Warning: rename(,%safile.tmp): %r(Invalid argument|The system cannot find the path specified. \(code: 3\))%r in %srename_variation13-win32.php on line %d
90bool(false)
91-- 3 testing '' NULL --
92
93Warning: rename(%safile.tmp,): %r(Invalid argument|The system cannot find the path specified. \(code: 3\))%r in %srename_variation13-win32.php on line %d
94bool(false)
95
96Warning: rename(,%safile.tmp): %r(Invalid argument|The system cannot find the path specified. \(code: 3\))%r in %srename_variation13-win32.php on line %d
97bool(false)
98-- 4 testing '' string --
99
100Warning: rename(%safile.tmp,): %r(Invalid argument|The system cannot find the path specified. \(code: 3\))%r in %srename_variation13-win32.php on line %d
101bool(false)
102
103Warning: rename(,%safile.tmp): %r(Invalid argument|The system cannot find the path specified. \(code: 3\))%r in %srename_variation13-win32.php on line %d
104bool(false)
105-- 5 testing ' ' string --
106
107Warning: rename(%s): The filename, directory name, or volume label syntax is incorrect. (code: 123) in %srename_variation13-win32.php on line %d
108bool(false)
109
110Warning: rename(%s): The filename, directory name, or volume label syntax is incorrect. (code: 123) in %srename_variation13-win32.php on line %d
111bool(false)
112-- 6 testing '�' string --
113
114Warning: rename() expects parameter 2 to be a valid path, string given in %srename_variation13-win32.php on line %d
115bool(false)
116
117Warning: file_exists() expects parameter 1 to be a valid path, string given in %srename_variation13-win32.php on line %d
118
119Warning: rename() expects parameter 1 to be a valid path, string given in %srename_variation13-win32.php on line %d
120bool(false)
121-- 7 testing 'Array' array --
122
123Warning: rename() expects parameter 2 to be a valid path, array given in %srename_variation13-win32.php on line %d
124bool(false)
125
126Warning: file_exists() expects parameter 1 to be a valid path, array given in %srename_variation13-win32.php on line %d
127
128Warning: rename() expects parameter 1 to be a valid path, array given in %srename_variation13-win32.php on line %d
129bool(false)
130-- 8 testing '/no/such/file/dir' string --
131
132Warning: rename(%safile.tmp,/no/such/file/dir): The system cannot find the path specified. (code: 3) in %srename_variation13-win32.php on line %d
133bool(false)
134
135Warning: rename(/no/such/file/dir,%safile.tmp): The system cannot find the path specified. (code: 3) in %srename_variation13-win32.php on line %d
136bool(false)
137-- 9 testing 'php/php' string --
138
139Warning: rename(%safile.tmp,php/php): The system cannot find the path specified. (code: 3) in %srename_variation13-win32.php on line %d
140bool(false)
141
142Warning: rename(php/php,%safile.tmp): The system cannot find the path specified. (code: 3) in %srename_variation13-win32.php on line %d
143bool(false)
144
145*** Done ***
146