1--TEST--
2Test unlink() function : variation: various valid and 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.. only for Windows');
9}
10?>
11--FILE--
12<?php
13/* Prototype  : bool unlink(string filename[, context context])
14 * Description: Delete a file
15 * Source code: ext/standard/file.c
16 * Alias to functions:
17 */
18
19echo "*** Testing unlink() : variation ***\n";
20
21$workDir = "unlinkVar9.tmp";
22$tmpFile = "file.tmp";
23chdir(__DIR__);
24mkdir($workDir);
25$cwd = __DIR__;
26$unixifiedFile = '/'.substr(str_replace('\\','/',$cwd).'/'.$workDir.'/'.$tmpFile, 3);
27
28$files = array(
29             // relative
30             $workDir.'\\'.$tmpFile,
31             '.\\'.$workDir.'\\'.$tmpFile,
32             $workDir.'\\..\\'.$workDir.'\\'.$tmpFile,
33
34             // relative bad path
35             $workDir.'\\..\\BADDIR\\'.$tmpFile,
36             'BADDIR\\'.$tmpFile,
37
38             //absolute
39             $cwd.'\\'.$workDir.'\\'.$tmpFile,
40             $cwd.'\\.\\'.$workDir.'\\'.$tmpFile,
41             $cwd.'\\'.$workDir.'\\..\\'.$workDir.'\\'.$tmpFile,
42
43             //absolute bad path
44             $cwd.'\\BADDIR\\'.$tmpFile,
45
46             //trailing separators
47             $workDir.'\\'.$tmpFile.'\\',
48             $cwd.'\\'.$workDir.'\\'.$tmpFile.'\\',
49
50             // multiple separators
51             $workDir.'\\\\'.$tmpFile,
52             $cwd.'\\\\'.$workDir.'\\\\'.$tmpFile,
53
54             // Unixified File
55             $unixifiedFile,
56
57             );
58
59
60foreach($files as $fileToUnlink) {
61	$file = $workDir.'/'.$tmpFile;
62	$tounlink = $fileToUnlink;
63   touch($file);
64   echo "-- removing $tounlink --\n";
65   $res = unlink($tounlink);
66   if ($res === true) {
67      if (file_exists($tounlink) === false) {
68      	echo "file removed\n";
69      }
70      else {
71        echo "FAILED: file not removed\n";
72      }
73   }
74   else {
75      unlink($file);
76   }
77}
78
79rmdir($workDir);
80?>
81===DONE===
82--EXPECTF--
83*** Testing unlink() : variation ***
84-- removing unlinkVar9.tmp\file.tmp --
85file removed
86-- removing .\unlinkVar9.tmp\file.tmp --
87file removed
88-- removing unlinkVar9.tmp\..\unlinkVar9.tmp\file.tmp --
89file removed
90-- removing unlinkVar9.tmp\..\BADDIR\file.tmp --
91
92Warning: unlink(unlinkVar9.tmp\..\BADDIR\file.tmp): No such file or directory in %s on line %d
93-- removing BADDIR\file.tmp --
94
95Warning: unlink(BADDIR\file.tmp): No such file or directory in %s on line %d
96-- removing %s\unlinkVar9.tmp\file.tmp --
97file removed
98-- removing %s\.\unlinkVar9.tmp\file.tmp --
99file removed
100-- removing %s\unlinkVar9.tmp\..\unlinkVar9.tmp\file.tmp --
101file removed
102-- removing %s\BADDIR\file.tmp --
103
104Warning: unlink(%s\BADDIR\file.tmp): No such file or directory in %s on line %d
105-- removing unlinkVar9.tmp\file.tmp\ --
106
107Warning: unlink(unlinkVar9.tmp\file.tmp\): Invalid argument in %s on line %d
108-- removing %s\unlinkVar9.tmp\file.tmp\ --
109
110Warning: unlink(%s\unlinkVar9.tmp\file.tmp\): Invalid argument in %s on line %d
111-- removing unlinkVar9.tmp\\file.tmp --
112file removed
113-- removing %s\\unlinkVar9.tmp\\file.tmp --
114file removed
115-- removing /%s/unlinkVar9.tmp/file.tmp --
116file removed
117===DONE===
118