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