1--TEST--
2Test unlink() function : usage variations - unlinking file in a directory
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6    die('skip only on Windows');
7}
8?>
9--FILE--
10<?php
11
12/* Delete file having default permission but its dir having readonly permission
13   Delete file having readonly permission but dir having default permission
14*/
15
16
17$file_path = __DIR__;
18
19// temp dir name used here
20$dirname = "$file_path/unlink_variation1";
21// temp filename used here
22$filename = "$dirname/unlink_variation1-win32.tmp";
23
24echo "\n*** Testing unlink() on file inside a directory ***\n";
25// create temp dir
26mkdir($dirname);
27// create temp file inside $dirname
28$fp = fopen($filename, "w");
29fclose($fp);
30
31echo "-- Unlink file having default permission and its dir having read only permission --\n";
32// remove write permission of $dirname
33// on windows dir permission is not respected
34var_dump( chmod($dirname, 0444) );
35// now try deleting $filename
36var_dump( unlink($filename) );  // expected: true
37var_dump( file_exists($filename) );  // confirm file is deleted
38
39// remove the dir
40var_dump( chmod($dirname, 0777) );
41rmdir($dirname);
42
43echo "\n-- Unlinking file without write permission, its dir having default permission --\n";
44// create the temp dir
45mkdir($dirname);
46
47// create the temp file
48$fp = fopen($filename, "w");
49fclose($fp);
50
51// remove write permission from file
52var_dump( chmod($filename, 0444) );
53
54// now try deleting temp file inside $dirname
55var_dump( unlink($filename) );  // expected: false
56
57// reassign write permission to temp file
58chmod($filename, 0777);
59// delete temp file
60var_dump( unlink($filename) );
61var_dump( file_exists($filename) );  // confirm file is deleted
62// remove temp dir
63rmdir($dirname);
64
65echo "Done\n";
66?>
67--EXPECTF--
68*** Testing unlink() on file inside a directory ***
69-- Unlink file having default permission and its dir having read only permission --
70bool(true)
71bool(true)
72bool(false)
73bool(true)
74
75-- Unlinking file without write permission, its dir having default permission --
76bool(true)
77
78Warning: unlink(%s/unlink_variation1/unlink_variation1-win32.tmp): Permission denied in %s on line %d
79bool(false)
80bool(true)
81bool(false)
82Done
83