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