Annotation of embedaddon/php/ext/standard/tests/file/unlink_variation1-win32.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test unlink() function : usage variations - unlinking file in a directory
3: --SKIPIF--
4: <?php
5: if (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__);
21:
22: // temp dir name used here
23: $dirname = "$file_path/unlink_variation1";
24: // temp filename used here
25: $filename = "$dirname/unlink_variation1-win32.tmp";
26:
27: echo "\n*** Testing unlink() on file inside a directory ***\n";
28: // create temp dir
29: mkdir($dirname);
30: // create temp file inside $dirname
31: $fp = fopen($filename, "w");
32: fclose($fp);
33:
34: echo "-- Unlink file having default permission and its dir having read only permission --\n";
35: // remove write permission of $dirname
36: // on windows dir permission is not respected
37: var_dump( chmod($dirname, 0444) );
38: // now try deleting $filename
39: var_dump( unlink($filename) ); // expected: true
40: var_dump( file_exists($filename) ); // confirm file is deleted
41:
42: // remove the dir
43: var_dump( chmod($dirname, 0777) );
44: rmdir($dirname);
45:
46: echo "\n-- Unlinking file without write permission, its dir having default permission --\n";
47: // create the temp dir
48: mkdir($dirname);
49:
50: // create the temp file
51: $fp = fopen($filename, "w");
52: fclose($fp);
53:
54: // remove write permission from file
55: var_dump( chmod($filename, 0444) );
56:
57: // now try deleting temp file inside $dirname
58: var_dump( unlink($filename) ); // expected: false
59:
60: // reassign write permission to temp file
61: chmod($filename, 0777);
62: // delete temp file
63: var_dump( unlink($filename) );
64: var_dump( file_exists($filename) ); // confirm file is deleted
65: // remove temp dir
66: rmdir($dirname);
67:
68: echo "Done\n";
69: ?>
70: --EXPECTF--
71: *** Testing unlink() on file inside a directory ***
72: -- Unlink file having default permission and its dir having read only permission --
73: bool(true)
74: bool(true)
75: bool(false)
76: bool(true)
77:
78: -- Unlinking file without write permission, its dir having default permission --
79: bool(true)
80:
81: Warning: unlink(%s/unlink_variation1/unlink_variation1-win32.tmp): Permission denied in %s on line %d
82: bool(false)
83: bool(true)
84: bool(false)
85: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>