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.. Not for Windows');
9}
10?>
11--FILE--
12<?php
13echo "*** Testing unlink() : variation ***\n";
14
15$workDir = "unlinkVar8.tmp";
16$tmpFile = "file.tmp";
17$fileToLinkTo = $workDir.'/'."linkme.tmp";
18
19mkdir($workDir);
20$cwd = getcwd();
21touch($fileToLinkTo);
22
23$files = array(
24             // relative
25             $workDir.'/'.$tmpFile,
26             './'.$workDir.'/'.$tmpFile,
27             $workDir.'/../'.$workDir.'/'.$tmpFile,
28
29             // relative bad path
30             $workDir.'/../BADDIR/'.$tmpFile,
31             'BADDIR/'.$tmpFile,
32
33             //absolute
34             $cwd.'/'.$workDir.'/'.$tmpFile,
35             $cwd.'/./'.$workDir.'/'.$tmpFile,
36             $cwd.'/'.$workDir.'/../'.$workDir.'/'.$tmpFile,
37
38             //absolute bad path
39             $cwd.'/BADDIR/'.$tmpFile,
40
41             //trailing separators
42             $workDir.'/'.$tmpFile.'/',
43             $cwd.'/'.$workDir.'/'.$tmpFile.'/',
44
45             // multiple separators
46             $workDir.'//'.$tmpFile,
47             $cwd.'//'.$workDir.'//'.$tmpFile,
48
49             );
50
51
52foreach($files as $fileToUnlink) {
53   test_realfile($workDir.'/'.$tmpFile, $fileToUnlink);
54   test_link($workDir.'/'.$tmpFile, $fileToLinkTo, $fileToUnlink, true);  //soft link
55   test_link($workDir.'/'.$tmpFile, $fileToLinkTo, $fileToUnlink, false); //hard link
56}
57
58unlink($fileToLinkTo);
59rmdir($workDir);
60
61function test_realfile($file, $tounlink) {
62   touch($file);
63   echo "-- removing $tounlink --\n";
64   $res = unlink($tounlink);
65   if ($res === true) {
66      if (file_exists($tounlink) === false) {
67        echo "file removed\n";
68      }
69      else {
70        echo "FAILED: file not removed\n";
71      }
72   }
73   else {
74      unlink($file);
75   }
76}
77
78function test_link($linkedfile, $toLinkTo, $tounlink, $softlink) {
79   if ($softlink == true) {
80      symlink($toLinkTo, $linkedfile);
81      $msg = "soft link";
82   }
83   else {
84      link($toLinkTo, $linkedfile);
85      $msg = "hard link";
86   }
87   echo "-- unlinking $msg $tounlink --\n";
88   $res = unlink($tounlink);
89   if ($res === true) {
90      if (file_exists($tounlink) === false) {
91        echo "file unlinked\n";
92      }
93      else {
94        echo "FAILED: file not unlinked\n";
95      }
96   }
97   else {
98      unlink($linkedfile);
99   }
100}
101
102
103?>
104--EXPECTF--
105*** Testing unlink() : variation ***
106-- removing unlinkVar8.tmp/file.tmp --
107file removed
108-- unlinking soft link unlinkVar8.tmp/file.tmp --
109file unlinked
110-- unlinking hard link unlinkVar8.tmp/file.tmp --
111file unlinked
112-- removing ./unlinkVar8.tmp/file.tmp --
113file removed
114-- unlinking soft link ./unlinkVar8.tmp/file.tmp --
115file unlinked
116-- unlinking hard link ./unlinkVar8.tmp/file.tmp --
117file unlinked
118-- removing unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp --
119file removed
120-- unlinking soft link unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp --
121file unlinked
122-- unlinking hard link unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp --
123file unlinked
124-- removing unlinkVar8.tmp/../BADDIR/file.tmp --
125
126Warning: unlink(unlinkVar8.tmp/../BADDIR/file.tmp): No such file or directory in %s on line %d
127-- unlinking soft link unlinkVar8.tmp/../BADDIR/file.tmp --
128
129Warning: unlink(unlinkVar8.tmp/../BADDIR/file.tmp): No such file or directory in %s on line %d
130-- unlinking hard link unlinkVar8.tmp/../BADDIR/file.tmp --
131
132Warning: unlink(unlinkVar8.tmp/../BADDIR/file.tmp): No such file or directory in %s on line %d
133-- removing BADDIR/file.tmp --
134
135Warning: unlink(BADDIR/file.tmp): No such file or directory in %s on line %d
136-- unlinking soft link BADDIR/file.tmp --
137
138Warning: unlink(BADDIR/file.tmp): No such file or directory in %s on line %d
139-- unlinking hard link BADDIR/file.tmp --
140
141Warning: unlink(BADDIR/file.tmp): No such file or directory in %s on line %d
142-- removing /%s/unlinkVar8.tmp/file.tmp --
143file removed
144-- unlinking soft link /%s/unlinkVar8.tmp/file.tmp --
145file unlinked
146-- unlinking hard link /%s/unlinkVar8.tmp/file.tmp --
147file unlinked
148-- removing /%s/./unlinkVar8.tmp/file.tmp --
149file removed
150-- unlinking soft link /%s/./unlinkVar8.tmp/file.tmp --
151file unlinked
152-- unlinking hard link /%s/./unlinkVar8.tmp/file.tmp --
153file unlinked
154-- removing /%s/unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp --
155file removed
156-- unlinking soft link /%s/unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp --
157file unlinked
158-- unlinking hard link /%s/unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp --
159file unlinked
160-- removing /%s/BADDIR/file.tmp --
161
162Warning: unlink(/%s/BADDIR/file.tmp): No such file or directory in %s on line %d
163-- unlinking soft link /%s/BADDIR/file.tmp --
164
165Warning: unlink(/%s/BADDIR/file.tmp): No such file or directory in %s on line %d
166-- unlinking hard link /%s/BADDIR/file.tmp --
167
168Warning: unlink(/%s/BADDIR/file.tmp): No such file or directory in %s on line %d
169-- removing unlinkVar8.tmp/file.tmp/ --
170
171Warning: unlink(unlinkVar8.tmp/file.tmp/): Not a directory in %s on line %d
172-- unlinking soft link unlinkVar8.tmp/file.tmp/ --
173
174Warning: unlink(unlinkVar8.tmp/file.tmp/): %s directory in %s on line %d
175-- unlinking hard link unlinkVar8.tmp/file.tmp/ --
176
177Warning: unlink(unlinkVar8.tmp/file.tmp/): Not a directory in %s on line %d
178-- removing /%s/unlinkVar8.tmp/file.tmp/ --
179
180Warning: unlink(/%s/unlinkVar8.tmp/file.tmp/): Not a directory in %s on line %d
181-- unlinking soft link /%s/unlinkVar8.tmp/file.tmp/ --
182
183Warning: unlink(/%s/unlinkVar8.tmp/file.tmp/): %s directory in %s on line %d
184-- unlinking hard link /%s/unlinkVar8.tmp/file.tmp/ --
185
186Warning: unlink(/%s/unlinkVar8.tmp/file.tmp/): Not a directory in %s on line %d
187-- removing unlinkVar8.tmp//file.tmp --
188file removed
189-- unlinking soft link unlinkVar8.tmp//file.tmp --
190file unlinked
191-- unlinking hard link unlinkVar8.tmp//file.tmp --
192file unlinked
193-- removing /%s//unlinkVar8.tmp//file.tmp --
194file removed
195-- unlinking soft link /%s//unlinkVar8.tmp//file.tmp --
196file unlinked
197-- unlinking hard link /%s//unlinkVar8.tmp//file.tmp --
198file unlinked
199