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