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
13echo "*** Testing unlink() : variation ***\n";
14
15$workDir = "unlinkVar8.tmp";
16$tmpFile = "file.tmp";
17chdir(__DIR__);
18mkdir($workDir);
19$cwd = __DIR__;
20
21$files = array(
22             // relative
23             $workDir.'/'.$tmpFile,
24             './'.$workDir.'/'.$tmpFile,
25             $workDir.'/../'.$workDir.'/'.$tmpFile,
26
27             // relative bad path
28             $workDir.'/../BADDIR/'.$tmpFile,
29             'BADDIR/'.$tmpFile,
30
31             //absolute
32             $cwd.'/'.$workDir.'/'.$tmpFile,
33             $cwd.'/./'.$workDir.'/'.$tmpFile,
34             $cwd.'/'.$workDir.'/../'.$workDir.'/'.$tmpFile,
35
36             //absolute bad path
37             $cwd.'/BADDIR/'.$tmpFile,
38
39             //trailing separators
40             $workDir.'/'.$tmpFile.'/',
41             $cwd.'/'.$workDir.'/'.$tmpFile.'/',
42
43             // multiple separators
44             $workDir.'//'.$tmpFile,
45             $cwd.'//'.$workDir.'//'.$tmpFile,
46
47             );
48
49
50foreach($files as $fileToUnlink) {
51   test_realfile($workDir.'/'.$tmpFile, $fileToUnlink);
52}
53
54rmdir($workDir);
55
56function test_realfile($file, $tounlink) {
57   touch($file);
58   echo "-- removing $tounlink --\n";
59   $res = unlink($tounlink);
60   if ($res === true) {
61      if (file_exists($tounlink) === false) {
62        echo "file removed\n";
63      }
64      else {
65        echo "FAILED: file not removed\n";
66      }
67   }
68   else {
69      unlink($file);
70   }
71}
72?>
73--EXPECTF--
74*** Testing unlink() : variation ***
75-- removing unlinkVar8.tmp/file.tmp --
76file removed
77-- removing ./unlinkVar8.tmp/file.tmp --
78file removed
79-- removing unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp --
80file removed
81-- removing unlinkVar8.tmp/../BADDIR/file.tmp --
82
83Warning: unlink(unlinkVar8.tmp/../BADDIR/file.tmp): No such file or directory in %s on line %d
84-- removing BADDIR/file.tmp --
85
86Warning: unlink(BADDIR/file.tmp): No such file or directory in %s on line %d
87-- removing %s/unlinkVar8.tmp/file.tmp --
88file removed
89-- removing %s/./unlinkVar8.tmp/file.tmp --
90file removed
91-- removing %s/unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp --
92file removed
93-- removing %s/BADDIR/file.tmp --
94
95Warning: unlink(%s/BADDIR/file.tmp): No such file or directory in %s on line %d
96-- removing unlinkVar8.tmp/file.tmp/ --
97
98Warning: unlink(unlinkVar8.tmp/file.tmp/): No such file or directory in %s on line %d
99-- removing %s/unlinkVar8.tmp/file.tmp/ --
100
101Warning: unlink(%s/unlinkVar8.tmp/file.tmp/): No such file or directory in %s on line %d
102-- removing unlinkVar8.tmp//file.tmp --
103file removed
104-- removing %s//unlinkVar8.tmp//file.tmp --
105file removed
106