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/* Prototype : bool unlink ( string $filename [, resource $context] );
12   Description : Deletes filename
13*/
14
15/* Delete file having default permission but its dir having readonly permission
16   Delete file having readonly permission but dir having default permission
17*/
18
19
20$file_path = dirname(__FILE__).DIRECTORY_SEPARATOR."私はガラスを食べられます";
21@mkdir($file_path);
22
23// temp dir name used here
24$dirname = "$file_path/unlink_variation1";
25// temp filename used here
26$filename = "$dirname/unlink_variation1-win32.tmp";
27
28echo "\n*** Testing unlink() on file inside a directory ***\n";
29// create temp dir
30mkdir($dirname);
31// create temp file inside $dirname
32$fp = fopen($filename, "w");
33fclose($fp);
34
35echo "-- Unlink file having default permission and its dir having read only permission --\n";
36// remove write permission of $dirname
37// on windows dir permission is not respected
38var_dump( chmod($dirname, 0444) );
39// now try deleting $filename
40var_dump( unlink($filename) );  // expected: true
41var_dump( file_exists($filename) );  // confirm file is deleted
42
43// remove the dir
44var_dump( chmod($dirname, 0777) );
45rmdir($dirname);
46
47echo "\n-- Unlinking file without write permission, its dir having default permission --\n";
48// create the temp dir
49mkdir($dirname);
50
51// create the temp file
52$fp = fopen($filename, "w");
53fclose($fp);
54
55// remove write permission from file
56var_dump( chmod($filename, 0444) );
57
58// now try deleting temp file inside $dirname
59var_dump( unlink($filename) );  // expected: false
60
61// reassign write permission to temp file
62chmod($filename, 0777);
63// delete temp file
64var_dump( unlink($filename) );
65var_dump( file_exists($filename) );  // confirm file is deleted
66// remove temp dir
67rmdir($dirname);
68rmdir($file_path);
69
70echo "Done\n";
71?>
72--EXPECTF--
73*** Testing unlink() on file inside a directory ***
74-- Unlink file having default permission and its dir having read only permission --
75bool(true)
76bool(true)
77bool(false)
78bool(true)
79
80-- Unlinking file without write permission, its dir having default permission --
81bool(true)
82
83Warning: unlink(%s/unlink_variation1/unlink_variation1-win32.tmp): Permission denied in %s on line %d
84bool(false)
85bool(true)
86bool(false)
87Done
88