Annotation of embedaddon/php/ext/standard/tests/file/unlink_variation1.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 Linux');
7: }
8: // Skip if being run by root (files are always readable, writeable and executable)
9: $filename = dirname(__FILE__)."/unlink_root_check.tmp";
10: $fp = fopen($filename, 'w');
11: fclose($fp);
12: if(fileowner($filename) == 0) {
13: unlink ($filename);
14: die('skip cannot be run as root');
15: }
16:
17: unlink($filename);
18: ?>
19: --FILE--
20: <?php
21: /* Prototype : bool unlink ( string $filename [, resource $context] );
22: Description : Deletes filename
23: */
24:
25: /* Delete file having default permission but its dir having readonly permission
26: Delete file having readonly permission but dir having default permission
27: */
28:
29:
30: $file_path = dirname(__FILE__);
31:
32: // temp dir name used here
33: $dirname = "$file_path/unlink_variation1";
34: // temp filename used here
35: $filename = "$dirname/unlink_variation1.tmp";
36:
37: echo "\n*** Testing unlink() on file inside a directory ***\n";
38: // create temp dir
39: mkdir($dirname);
40: // create temp file inside $dirname
41: $fp = fopen($filename, "w");
42: fclose($fp);
43:
44: echo "-- Unlink file having default permission and its dir having read only permission --\n";
45: // remove write permission of $dirname
46: var_dump( chmod($dirname, 0444) );
47: // now try deleting $filename
48: var_dump( unlink($filename) ); // expected false
49: var_dump( file_exists($filename) ); // confirm file is deleted
50:
51: // remove the dir
52: var_dump( chmod($dirname, 0777) );
53: var_dump( unlink($filename) ); // expected true
54: var_dump( rmdir($dirname) );
55:
56: echo "\n-- Unlinking file without write permission, its dir having default permission --\n";
57: // create the temp dir
58: var_dump( mkdir($dirname) );
59: // create the temp file
60: $fp = fopen($filename, "w");
61: fclose($fp);
62:
63: // remove write permission from file
64: var_dump( chmod($filename, 0444) );
65: // now try deleting temp file inside $dirname
66: var_dump( unlink($filename) ); // expected: true
67: var_dump( file_exists($filename) ); // expected: false
68:
69: // remove temp dir
70: var_dump( rmdir($dirname) );
71:
72: echo "Done\n";
73: ?>
74: --EXPECTF--
75: *** Testing unlink() on file inside a directory ***
76: -- Unlink file having default permission and its dir having read only permission --
77: bool(true)
78:
79: Warning: unlink(%s): %s in %s on line %d
80: bool(false)
81: bool(false)
82: bool(true)
83: bool(true)
84: bool(true)
85:
86: -- Unlinking file without write permission, its dir having default permission --
87: bool(true)
88: bool(true)
89: bool(true)
90: bool(false)
91: bool(true)
92: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>