xref: /PHP-5.5/ext/standard/tests/file/006_error.phpt (revision f17c2db7)
1--TEST--
2Test fileperms(), chmod() functions: error conditions
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip Not on Windows');
7}
8// Skip if being run by root
9$filename = dirname(__FILE__)."/006_root_check.tmp";
10$fp = fopen($filename, 'w');
11fclose($fp);
12if(fileowner($filename) == 0) {
13        unlink ($filename);
14        die('skip cannot be run as root');
15}
16
17unlink($filename);
18
19?>
20--FILE--
21<?php
22/*
23  Prototype: int fileperms ( string $filename )
24  Description: Returns the permissions on the file, or FALSE in case of an error
25
26  Prototype: bool chmod ( string $filename, int $mode )
27  Description: Attempts to change the mode of the file specified by
28    filename to that given in mode
29*/
30
31echo "*** Testing error conditions for fileperms(), chmod() ***\n";
32
33/* With standard files and dirs */
34var_dump( chmod("/etc/passwd", 0777) );
35printf("%o", fileperms("/etc/passwd") );
36echo "\n";
37clearstatcache();
38
39var_dump( chmod("/etc", 0777) );
40printf("%o", fileperms("/etc") );
41echo "\n";
42clearstatcache();
43
44/* With non-existing file or dir */
45var_dump( chmod("/no/such/file/dir", 0777) );
46var_dump( fileperms("/no/such/file/dir") );
47echo "\n";
48
49/* With args less than expected */
50$fp = fopen(dirname(__FILE__)."/006_error.tmp", "w");
51fclose($fp);
52var_dump( chmod(dirname(__FILE__)."/006_error.tmp") );
53var_dump( chmod("nofile") );
54var_dump( chmod() );
55var_dump( fileperms() );
56
57/* With args greater than expected */
58var_dump( chmod(dirname(__FILE__)."/006_error.tmp", 0755, TRUE) );
59var_dump( fileperms(dirname(__FILE__)."/006_error.tmp", 0777) );
60var_dump( fileperms("nofile", 0777) );
61
62echo "\n*** Done ***\n";
63?>
64--CLEAN--
65<?php
66unlink( dirname(__FILE__)."/006_error.tmp");
67?>
68--EXPECTF--
69*** Testing error conditions for fileperms(), chmod() ***
70
71Warning: chmod(): %s in %s on line %d
72bool(false)
73100%d44
74
75Warning: chmod(): %s in %s on line %d
76bool(false)
7740755
78
79Warning: chmod(): No such file or directory in %s on line %d
80bool(false)
81
82Warning: fileperms(): stat failed for /no/such/file/dir in %s on line %d
83bool(false)
84
85
86Warning: chmod() expects exactly 2 parameters, 1 given in %s on line %d
87NULL
88
89Warning: chmod() expects exactly 2 parameters, 1 given in %s on line %d
90NULL
91
92Warning: chmod() expects exactly 2 parameters, 0 given in %s on line %d
93NULL
94
95Warning: fileperms() expects exactly 1 parameter, 0 given in %s on line %d
96NULL
97
98Warning: chmod() expects exactly 2 parameters, 3 given in %s on line %d
99NULL
100
101Warning: fileperms() expects exactly 1 parameter, 2 given in %s on line %d
102NULL
103
104Warning: fileperms() expects exactly 1 parameter, 2 given in %s on line %d
105NULL
106
107*** Done ***
108