Skip to content

Commit fda3f33

Browse files
author
Raghubansh Kumar
committed
Fix and smaller testcases for is_readable_variation.phpt, is_executable_variation.phpt & is_writable_variation.phpt
1 parent 0cfa8b1 commit fda3f33

9 files changed

+866
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
--TEST--
2+
Test is_executable() function: usage variations - diff. path notations
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) == 'WIN') {
6+
die('skip.. only for LINUX');
7+
}
8+
// Skip if being run by root (files are always readable, writeable and executable)
9+
$filename = dirname(__FILE__)."/is_executable_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\n');
15+
}
16+
17+
unlink($filename);
18+
?>
19+
--FILE--
20+
<?php
21+
/* Prototype: bool is_executable ( string $filename );
22+
Description: Tells whether the filename is executable
23+
*/
24+
25+
/* test is_executable() with file having different filepath notation */
26+
27+
require dirname(__FILE__).'/file.inc';
28+
echo "*** Testing is_executable(): usage variations ***\n";
29+
30+
$file_path = dirname(__FILE__);
31+
mkdir("$file_path/is_executable_variation1");
32+
33+
// create a new temporary file
34+
$fp = fopen("$file_path/is_executable_variation1/bar.tmp", "w");
35+
fclose($fp);
36+
37+
/* array of files checked to see if they are executable files
38+
using is_executable() function */
39+
$files_arr = array(
40+
"$file_path/is_executable_variation1/bar.tmp",
41+
42+
/* Testing a file with trailing slash */
43+
"$file_path/is_executable_variation1/bar.tmp/",
44+
45+
/* Testing file with double slashes */
46+
"$file_path/is_executable_variation1//bar.tmp",
47+
"$file_path/is_executable_variation1/*.tmp",
48+
"$file_path/is_executable_variation1/b*.tmp",
49+
50+
/* Testing Binary safe */
51+
"$file_path/is_executable_variation1".chr(0)."bar.temp",
52+
"$file_path".chr(0)."is_executable_variation1/bar.temp",
53+
"$file_path/is_executable_variation1x000/",
54+
55+
/* Testing directories */
56+
".", // current directory, exp: bool(true)
57+
"$file_path/is_executable_variation1" // temp directory, exp: bool(true)
58+
);
59+
$counter = 1;
60+
/* loop through to test each element in the above array
61+
is an executable file */
62+
foreach($files_arr as $file) {
63+
echo "-- Iteration $counter --\n";
64+
var_dump( is_executable($file) );
65+
$counter++;
66+
clearstatcache();
67+
}
68+
69+
echo "Done\n";
70+
?>
71+
--CLEAN--
72+
<?php
73+
unlink(dirname(__FILE__)."/is_executable_variation1/bar.tmp");
74+
rmdir(dirname(__FILE__)."/is_executable_variation1/");
75+
?>
76+
--EXPECTF--
77+
*** Testing is_executable(): usage variations ***
78+
-- Iteration 1 --
79+
bool(false)
80+
-- Iteration 2 --
81+
bool(false)
82+
-- Iteration 3 --
83+
bool(false)
84+
-- Iteration 4 --
85+
bool(false)
86+
-- Iteration 5 --
87+
bool(false)
88+
-- Iteration 6 --
89+
bool(true)
90+
-- Iteration 7 --
91+
bool(true)
92+
-- Iteration 8 --
93+
bool(false)
94+
-- Iteration 9 --
95+
bool(true)
96+
-- Iteration 10 --
97+
bool(true)
98+
Done
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
--TEST--
2+
Test is_executable() function: usage variations - file/dir with diff. perms
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) == 'WIN') {
6+
die('skip.. only for LINUX');
7+
}
8+
// Skip if being run by root (files are always readable, writeable and executable)
9+
$filename = dirname(__FILE__)."/is_executable_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\n');
15+
}
16+
17+
unlink($filename);
18+
?>
19+
--FILE--
20+
<?php
21+
/* Prototype: bool is_executable ( string $filename );
22+
Description: Tells whether the filename is executable
23+
*/
24+
25+
/* test is_executable() with file/dir having different permissions */
26+
27+
require dirname(__FILE__).'/file.inc';
28+
echo "*** Testing is_executable(): usage variations ***\n";
29+
30+
$file_path = dirname(__FILE__);
31+
mkdir("$file_path/is_executable_variation2");
32+
33+
echo "\n*** Testing is_executable() on directory without execute permission ***\n";
34+
chmod("$file_path/is_executable_variation2", 0444);
35+
var_dump( is_executable("$file_path/is_executable_variation2") ); // exp: bool(false)
36+
chmod("$file_path/is_executable_variation2", 0777); // chmod to enable deletion of directory
37+
38+
echo "\n*** Testing miscelleneous input for is_executable() function ***\n";
39+
$name_prefix = "is_executable_variation2";
40+
create_files(dirname(__FILE__), 1, "numeric", 0755, 1, "w", $name_prefix, 1);
41+
create_files(dirname(__FILE__), 1, "text", 0755, 1, "w", $name_prefix, 2);
42+
create_files(dirname(__FILE__), 1, "empty", 0755, 1, "w", $name_prefix, 3);
43+
create_files(dirname(__FILE__), 1, "numeric", 0755, 1, "w", $name_prefix, 4);
44+
create_files(dirname(__FILE__), 1, "text", 0222, 1, "w", $name_prefix, 5);
45+
create_files(dirname(__FILE__), 1, "numeric", 0711, 1, "w", $name_prefix, 6);
46+
create_files(dirname(__FILE__), 1, "text", 0714, 1, "w", $name_prefix, 7);
47+
create_files(dirname(__FILE__), 1, "numeric", 0744, 1, "w", $name_prefix, 8);
48+
create_files(dirname(__FILE__), 1, "text", 0421, 1, "w", $name_prefix, 9);
49+
create_files(dirname(__FILE__), 1, "text", 0712, 1, "w", $name_prefix, 10);
50+
51+
$files = array (
52+
"$file_path/is_executable_variation21.tmp",
53+
"$file_path/is_executable_variation22.tmp",
54+
"$file_path/is_executable_variation23.tmp",
55+
"$file_path/is_executable_variation24.tmp",
56+
"$file_path/is_executable_variation25.tmp",
57+
"$file_path/is_executable_variation26.tmp",
58+
"$file_path/is_executable_variation27.tmp",
59+
"$file_path/is_executable_variation28.tmp",
60+
"$file_path/is_executable_variation29.tmp",
61+
"$file_path/is_executable_variation210.tmp",
62+
);
63+
$counter = 1;
64+
/* loop through to test each element in the above array
65+
is an executable file */
66+
foreach($files as $file) {
67+
echo "-- Iteration $counter --\n";
68+
var_dump( is_executable($file) );
69+
$counter++;
70+
clearstatcache();
71+
}
72+
73+
// change all file's permissions to 777 before deleting
74+
change_file_perms($file_path, 10, 0777, $name_prefix);
75+
delete_files($file_path, 10, $name_prefix);
76+
77+
echo "Done\n";
78+
?>
79+
--CLEAN--
80+
<?php
81+
rmdir(dirname(__FILE__)."/is_executable_variation2/");
82+
?>
83+
--EXPECTF--
84+
*** Testing is_executable(): usage variations ***
85+
86+
*** Testing is_executable() on directory without execute permission ***
87+
bool(false)
88+
89+
*** Testing miscelleneous input for is_executable() function ***
90+
-- Iteration 1 --
91+
bool(true)
92+
-- Iteration 2 --
93+
bool(true)
94+
-- Iteration 3 --
95+
bool(true)
96+
-- Iteration 4 --
97+
bool(true)
98+
-- Iteration 5 --
99+
bool(false)
100+
-- Iteration 6 --
101+
bool(true)
102+
-- Iteration 7 --
103+
bool(true)
104+
-- Iteration 8 --
105+
bool(true)
106+
-- Iteration 9 --
107+
bool(false)
108+
-- Iteration 10 --
109+
bool(true)
110+
Done
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
--TEST--
2+
Test is_executable() function: usage variations - invalid file names
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) == 'WIN') {
6+
die('skip.. only for LINUX');
7+
}
8+
// Skip if being run by root (files are always readable, writeable and executable)
9+
$filename = dirname(__FILE__)."/is_executable_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\n');
15+
}
16+
17+
unlink($filename);
18+
?>
19+
--FILE--
20+
<?php
21+
/* Prototype: bool is_executable ( string $filename );
22+
Description: Tells whether the filename is executable
23+
*/
24+
25+
/* test is_executable() with invalid arguments */
26+
27+
echo "*** Testing is_executable(): usage variations ***\n";
28+
29+
$file_handle = fopen(__FILE__, "r");
30+
unset($file_handle);
31+
32+
echo "\n*** Testing is_executable() on invalid files ***\n";
33+
$invalid_files = array(
34+
0,
35+
1234,
36+
-2.34555,
37+
TRUE,
38+
FALSE,
39+
NULL,
40+
@array(),
41+
@$file_handle
42+
);
43+
/* loop through to test each element in the above array
44+
is an executable file */
45+
foreach( $invalid_files as $invalid_file ) {
46+
var_dump( is_executable($invalid_file) );
47+
clearstatcache();
48+
}
49+
50+
echo "Done\n";
51+
?>
52+
--EXPECTF--
53+
*** Testing is_executable(): usage variations ***
54+
55+
*** Testing is_executable() on invalid files ***
56+
bool(false)
57+
bool(false)
58+
bool(false)
59+
bool(false)
60+
bool(false)
61+
bool(false)
62+
63+
Notice: Array to string conversion in %s on line %d
64+
bool(false)
65+
bool(false)
66+
Done
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
--TEST--
2+
Test is_readable() function: usage variations - diff. file notations
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) == 'WIN') {
6+
die('skip.. only for LINUX');
7+
}
8+
// Skip if being run by root (files are always readable, writeable and executable)
9+
$filename = dirname(__FILE__)."/is_readable_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\n');
15+
}
16+
17+
unlink($filename);
18+
?>
19+
--FILE--
20+
<?php
21+
/* Prototype: bool is_readable ( string $filename );
22+
Description: Tells whether the filename is readable.
23+
*/
24+
25+
/* test is_readable() with file having different filepath notation */
26+
27+
require dirname(__FILE__).'/file.inc';
28+
echo "*** Testing is_readable(): usage variations ***\n";
29+
30+
$file_path = dirname(__FILE__);
31+
mkdir("$file_path/is_readable_variation1");
32+
33+
// create a new temporary file
34+
$fp = fopen("$file_path/is_readable_variation1/bar.tmp", "w");
35+
fclose($fp);
36+
37+
/* array of files to be tested if they are readable by using
38+
is_readable() function */
39+
$files_arr = array(
40+
"$file_path/is_readable_variation1/bar.tmp",
41+
42+
/* Testing a file trailing slash */
43+
"$file_path/is_readable_variation1/bar.tmp/",
44+
45+
/* Testing file with double slashes */
46+
"$file_path/is_readable_variation1//bar.tmp",
47+
"$file_path//is_readable_variation1//bar.tmp",
48+
"$file_path/is_readable_variation1/*.tmp",
49+
"$file_path/is_readable_variation1/b*.tmp",
50+
51+
/* Testing Binary safe */
52+
"$file_path/is_readable_variation1".chr(0)."bar.tmp",
53+
"$file_path".chr(0)."is_readable_variation1/bar.tmp",
54+
"$file_path".chr(0)."is_readable_variation1/bar.tmp",
55+
56+
/* Testing directories */
57+
".", // current directory, exp: bool(true)
58+
"$file_path/is_readable_variation1" // temp directory, exp: bool(true)
59+
);
60+
$counter = 1;
61+
/* loop through to test each element in the above array
62+
is a writable file */
63+
foreach($files_arr as $file) {
64+
echo "-- Iteration $counter --\n";
65+
var_dump( is_readable($file) );
66+
$counter++;
67+
clearstatcache();
68+
}
69+
70+
echo "Done\n";
71+
?>
72+
--CLEAN--
73+
<?php
74+
unlink(dirname(__FILE__)."/is_readable_variation1/bar.tmp");
75+
rmdir(dirname(__FILE__)."/is_readable_variation1/");
76+
?>
77+
--EXPECTF--
78+
*** Testing is_readable(): usage variations ***
79+
-- Iteration 1 --
80+
bool(true)
81+
-- Iteration 2 --
82+
bool(%s)
83+
-- Iteration 3 --
84+
bool(true)
85+
-- Iteration 4 --
86+
bool(true)
87+
-- Iteration 5 --
88+
bool(false)
89+
-- Iteration 6 --
90+
bool(false)
91+
-- Iteration 7 --
92+
bool(true)
93+
-- Iteration 8 --
94+
bool(true)
95+
-- Iteration 9 --
96+
bool(true)
97+
-- Iteration 10 --
98+
bool(true)
99+
-- Iteration 11 --
100+
bool(true)
101+
Done

0 commit comments

Comments
 (0)