summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/is_writable_variation2.phpt
blob: a8cafb25bdcaca3b772a69b2cfcbad1cbedb5612 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
--TEST--
Test is_writable() and its alias is_writeable() function: usage variations - file/dir with diff. perms
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
    die('skip.. only on LINUX');
}
// Skip if being run by root
$filename = __DIR__."/is_readable_root_check.tmp";
$fp = fopen($filename, 'w');
fclose($fp);
if(fileowner($filename) == 0) {
        unlink ($filename);
        die('skip cannot be run as root');
}

unlink ($filename);
?>
--FILE--
<?php
/* Prototype: bool is_writable ( string $filename );
   Description: Tells whether the filename is writable.

   is_writeable() is an alias of is_writable()
*/

/* test is_executable() with file/dir having different permissions */

require __DIR__.'/file.inc';
echo "*** Testing is_writable(): usage variations ***\n";

$file_path = __DIR__;
mkdir("$file_path/is_writable_variation2");

echo "\n*** Testing is_writable() on directory without write permission ***\n";
chmod("$file_path/is_writable_variation2", 0004);
var_dump( is_writable("$file_path/is_writable_variation2") );  // exp: bool(false)
var_dump( is_writeable("$file_path/is_writable_variation2") );  // exp: bool(false)
chmod("$file_path/is_writable_variation2", 0777);  // chmod to enable deletion of directory

echo "\n*** Testing miscelleneous input for is_writable() function ***\n";
$name_prefix = "is_writable_variation2";
create_files(__DIR__, 1, "numeric", 0755, 1, "w", $name_prefix, 1);
create_files(__DIR__, 1, "text", 0755, 1, "w", $name_prefix, 2);
create_files(__DIR__, 1, "empty", 0755, 1, "w", $name_prefix, 3);
create_files(__DIR__, 1, "numeric", 0555, 1, "w", $name_prefix, 4);
create_files(__DIR__, 1, "text", 0222, 1, "w", $name_prefix, 5);
create_files(__DIR__, 1, "numeric", 0711, 1, "w", $name_prefix, 6);
create_files(__DIR__, 1, "text", 0114, 1, "w", $name_prefix, 7);
create_files(__DIR__, 1, "numeric", 0244, 1, "w", $name_prefix, 8);
create_files(__DIR__, 1, "text", 0421, 1, "w", $name_prefix, 9);
create_files(__DIR__, 1, "text", 0422, 1, "w", $name_prefix, 10);

$misc_files = array (
  "$file_path/is_writable_variation21.tmp",
  "$file_path/is_writable_variation22.tmp",
  "$file_path/is_writable_variation23.tmp",
  "$file_path/is_writable_variation24.tmp",
  "$file_path/is_writable_variation25.tmp",
  "$file_path/is_writable_variation26.tmp",
  "$file_path/is_writable_variation27.tmp",
  "$file_path/is_writable_variation28.tmp",
  "$file_path/is_writable_variation29.tmp",
  "$file_path/is_writable_variation210.tmp"
);

$counter = 1;
/* loop through to test each element in the above array
   is a writable file */
foreach($misc_files as $misc_file) {
  echo "-- Iteration $counter --\n";
  var_dump( is_writable($misc_file) );
  var_dump( is_writeable($misc_file) );
  $counter++;
  clearstatcache();
}

// change all file's permissions to 777 before deleting
change_file_perms($file_path, 10, 0777, $name_prefix);
delete_files($file_path, 10, $name_prefix);

echo "Done\n";
?>
--CLEAN--
<?php
rmdir(__DIR__."/is_writable_variation2/");
?>
--EXPECT--
*** Testing is_writable(): usage variations ***

*** Testing is_writable() on directory without write permission ***
bool(false)
bool(false)

*** Testing miscelleneous input for is_writable() function ***
-- Iteration 1 --
bool(true)
bool(true)
-- Iteration 2 --
bool(true)
bool(true)
-- Iteration 3 --
bool(true)
bool(true)
-- Iteration 4 --
bool(false)
bool(false)
-- Iteration 5 --
bool(true)
bool(true)
-- Iteration 6 --
bool(true)
bool(true)
-- Iteration 7 --
bool(false)
bool(false)
-- Iteration 8 --
bool(true)
bool(true)
-- Iteration 9 --
bool(false)
bool(false)
-- Iteration 10 --
bool(false)
bool(false)
Done