Skip to content

Commit f159642

Browse files
author
Raghubansh Kumar
committed
Fix and smaller testcases for mkdir_rmdir_variation.phpt, popen_pclose_error.phpt, readlink_realpath_basic.phpt, readlink_realpath_error.phpt & readlink_realpath_variation.phpt
1 parent 539f67e commit f159642

10 files changed

+2213
-4
lines changed

ext/standard/tests/file/mkdir_rmdir_variation1.phpt

Lines changed: 1579 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
--TEST--
2+
Test mkdir() and rmdir() functions: usage variations - misc.
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__)."/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 mkdir ( string $pathname [, int $mode [, bool $recursive [, resource $context]]] );
22+
Description: Makes directory
23+
*/
24+
25+
$context = stream_context_create();
26+
27+
$file_path = dirname(__FILE__);
28+
29+
echo "\n*** Testing mkdir() and rmdir() by giving stream context as fourth argument ***\n";
30+
var_dump( mkdir("$file_path/mkdir_variation2/test/", 0777, true, $context) );
31+
var_dump( rmdir("$file_path/mkdir_variation2/test/", $context) );
32+
33+
echo "\n*** Testing rmdir() on a non-empty directory ***\n";
34+
var_dump( mkdir("$file_path/mkdir_variation2/test/", 0777, true) );
35+
var_dump( rmdir("$file_path/mkdir_variation2/") );
36+
37+
echo "\n*** Testing mkdir() and rmdir() for binary safe functionality ***\n";
38+
var_dump( mkdir("$file_path/temp".chr(0)."/") );
39+
var_dump( rmdir("$file_path/temp".chr(0)."/") );
40+
41+
echo "\n*** Testing mkdir() with miscelleneous input ***\n";
42+
/* changing mode of mkdir to prevent creating sub-directory under it */
43+
var_dump( chmod("$file_path/mkdir_variation2/", 0000) );
44+
/* creating sub-directory test1 under mkdir, expected: false */
45+
var_dump( mkdir("$file_path/mkdir_variation2/test1", 0777, true) );
46+
var_dump( chmod("$file_path/mkdir_variation2/", 0777) ); // chmod to enable removing test1 directory
47+
48+
echo "Done\n";
49+
?>
50+
--CLEAN--
51+
<?php
52+
rmdir(dirname(__FILE__)."/mkdir_variation2/test/");
53+
rmdir(dirname(__FILE__)."/mkdir_variation2/test1/");
54+
rmdir(dirname(__FILE__)."/mkdir_variation2/");
55+
?>
56+
--EXPECTF--
57+
*** Testing mkdir() and rmdir() by giving stream context as fourth argument ***
58+
bool(true)
59+
bool(true)
60+
61+
*** Testing rmdir() on a non-empty directory ***
62+
bool(true)
63+
64+
Warning: rmdir(%s/mkdir_variation2/): %s on line %d
65+
bool(false)
66+
67+
*** Testing mkdir() and rmdir() for binary safe functionality ***
68+
bool(true)
69+
bool(true)
70+
71+
*** Testing mkdir() with miscelleneous input ***
72+
bool(true)
73+
74+
Warning: mkdir(): Permission denied in %s on line %d
75+
bool(false)
76+
bool(true)
77+
Done
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
--TEST--
2+
Test popen() and pclose function: error conditions
3+
--SKIPIF--
4+
<?php
5+
if( substr(PHP_OS, 0, 3) != 'Sun')
6+
die("skip Only valid for Sun Solaris");
7+
?>
8+
9+
--FILE--
10+
<?php
11+
/*
12+
* Prototype: resource popen ( string command, string mode )
13+
* Description: Opens process file pointer.
14+
15+
* Prototype: int pclose ( resource handle );
16+
* Description: Closes process file pointer.
17+
*/
18+
$file_path = dirname(__FILE__);
19+
echo "*** Testing for error conditions ***\n";
20+
var_dump( popen() ); // Zero Arguments
21+
var_dump( popen("abc.txt") ); // Single Argument
22+
var_dump( popen("abc.txt", "rw") ); // Invalid mode Argument
23+
var_dump( pclose() );
24+
$file_handle = fopen($file_path."/popen.tmp", "w");
25+
var_dump( pclose($file_handle, $file_handle) );
26+
fclose($file_handle);
27+
var_dump( pclose(1) );
28+
echo "\n--- Done ---";
29+
?>
30+
--CLEAN--
31+
<?php
32+
$file_path = dirname(__FILE__);
33+
unlink($file_path."/popen.tmp");
34+
?>
35+
--EXPECTF--
36+
*** Testing for error conditions ***
37+
38+
Warning: Wrong parameter count for popen() in %s on line %d
39+
NULL
40+
41+
Warning: Wrong parameter count for popen() in %s on line %d
42+
NULL
43+
resource(%d) of type (stream)
44+
sh: abc.txt: not found
45+
Warning: Wrong parameter count for pclose() in %s on line %d
46+
NULL
47+
48+
Warning: Wrong parameter count for pclose() in %s on line %d
49+
NULL
50+
51+
Warning: pclose(): supplied argument is not a valid stream resource in %s on line %d
52+
bool(false)
53+
54+
--- Done ---

ext/standard/tests/file/popen_pclose_error.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Test popen() and pclose function: error conditions
33
--SKIPIF--
44
<?php
5-
if(substr(PHP_OS, 0, 3) == 'WIN' )
6-
die("skip Not Valid for Windows");
5+
if(substr(PHP_OS, 0, 3) == 'WIN' || substr(PHP_OS, 0, 3) == 'Sun')
6+
die("skip Not Valid for Windows and Sun Solaris");
77
?>
88

99
--FILE--
@@ -41,7 +41,7 @@ NULL
4141
Warning: Wrong parameter count for popen() in %s on line %d
4242
NULL
4343

44-
Warning: popen(abc.txt,rw): Invalid argument in %s on line %d
44+
Warning: popen(abc.txt,rw): %s on line %d
4545
bool(false)
4646

4747
Warning: Wrong parameter count for pclose() in %s on line %d
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
--TEST--
2+
Test readlink() and realpath functions: basic functionality - diff. path notation for links
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) == 'WIN') {
6+
die('skip no symlinks on Windows');
7+
}
8+
?>
9+
--FILE--
10+
<?php
11+
/* Prototype: string readlink ( string $path );
12+
Description: Returns the target of a symbolic link
13+
14+
Prototype: string realpath ( string $path );
15+
Description: Returns canonicalized absolute pathname
16+
*/
17+
18+
/* creating directories, symbolic links and files */
19+
$file_path = dirname(__FILE__);
20+
mkdir("$file_path/readlink_realpath_basic1/home/test/", 0777, true);
21+
22+
$file_handle1 = fopen("$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp", "w");
23+
$file_handle2 = fopen("$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp", "w");
24+
$file_handle3 = fopen("$file_path/readlink_realpath_basic1/readlink_realpath_basic1.tmp", "w");
25+
fclose($file_handle1);
26+
fclose($file_handle2);
27+
fclose($file_handle3);
28+
29+
symlink("$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp",
30+
"$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1_link.tmp");
31+
symlink("$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp",
32+
"$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1_link.tmp");
33+
34+
35+
echo "*** Testing readlink() and realpath(): with valid and invalid path ***\n";
36+
$linknames = array (
37+
/* linknames resulting in valid paths */
38+
"$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1_link.tmp",
39+
"$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1_link.tmp",
40+
"$file_path/readlink_realpath_basic1//home/test//../test/./readlink_realpath_basic1_link.tmp",
41+
42+
// checking for binary safe
43+
b"$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1_link.tmp",
44+
45+
/* linknames with invalid linkpath */
46+
"$file_path///readlink_realpath_basic1/home//..//././test//readlink_realpath_basic1_link.tmp",
47+
"$file_path/readlink_realpath_basic1/home/../home/../test/../readlink_realpath_basic1_link.tmp",
48+
"$file_path/readlink_realpath_basic1/..readlink_realpath_basic1_link.tmp",
49+
"$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1_link.tmp/"
50+
);
51+
52+
$counter = 1;
53+
/* loop through $files to read the linkpath of
54+
the link created from each $file in the above array */
55+
foreach($linknames as $link) {
56+
echo "\n-- Iteration $counter --\n";
57+
var_dump( readlink($link) );
58+
var_dump( realpath($link) );
59+
$counter++;
60+
}
61+
62+
echo "Done\n";
63+
?>
64+
--CLEAN--
65+
<?php
66+
$name_prefix = dirname(__FILE__)."/readlink_realpath_basic1";
67+
unlink("$name_prefix/home/test/readlink_realpath_basic1.tmp");
68+
unlink("$name_prefix/home/readlink_realpath_basic1.tmp");
69+
unlink("$name_prefix/readlink_realpath_basic1.tmp");
70+
unlink("$name_prefix/home/test/readlink_realpath_basic1_link.tmp");
71+
unlink("$name_prefix/home/readlink_realpath_basic1_link.tmp");
72+
rmdir("$name_prefix/home/test/");
73+
rmdir("$name_prefix/home/");
74+
rmdir("$name_prefix/");
75+
?>
76+
--EXPECTF--
77+
*** Testing readlink() and realpath(): with valid and invalid path ***
78+
79+
-- Iteration 1 --
80+
string(%d) "%s/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp"
81+
string(%d) "%s/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp"
82+
83+
-- Iteration 2 --
84+
string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
85+
string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
86+
87+
-- Iteration 3 --
88+
string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
89+
string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
90+
91+
-- Iteration 4 --
92+
string(%d) "%s/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp"
93+
string(%d) "%s/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp"
94+
95+
-- Iteration 5 --
96+
97+
Warning: readlink(): No such file or directory in %s on line %d
98+
bool(false)
99+
bool(false)
100+
101+
-- Iteration 6 --
102+
103+
Warning: readlink(): No such file or directory in %s on line %d
104+
bool(false)
105+
bool(false)
106+
107+
-- Iteration 7 --
108+
109+
Warning: readlink(): No such file or directory in %s on line %d
110+
bool(false)
111+
%s
112+
113+
-- Iteration 8 --
114+
115+
Warning: readlink(): %s in %s on line %d
116+
bool(false)
117+
%s
118+
Done
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
--TEST--
2+
Test readlink() and realpath functions: basic functionality - diff. path notation for files
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) == 'WIN') {
6+
die('skip no symlinks on Windows');
7+
}
8+
?>
9+
--FILE--
10+
<?php
11+
/* Prototype: string readlink ( string $path );
12+
Description: Returns the target of a symbolic link
13+
14+
Prototype: string realpath ( string $path );
15+
Description: Returns canonicalized absolute pathname
16+
*/
17+
18+
/* creating directories, symbolic links and files */
19+
$file_path = dirname(__FILE__);
20+
mkdir("$file_path/readlink_realpath_basic2/home/test/", 0777, true);
21+
22+
$file_handle1 = fopen("$file_path/readlink_realpath_basic2/home/test/readlink_realpath_basic2.tmp", "w");
23+
$file_handle2 = fopen("$file_path/readlink_realpath_basic2/home/readlink_realpath_basic2.tmp", "w");
24+
$file_handle3 = fopen("$file_path/readlink_realpath_basic2/readlink_realpath_basic2.tmp", "w");
25+
fclose($file_handle1);
26+
fclose($file_handle2);
27+
fclose($file_handle3);
28+
29+
echo "\n*** Testing realpath() on filenames ***\n";
30+
$filenames = array (
31+
/* filenames resulting in valid paths */
32+
"$file_path/readlink_realpath_basic2/home/readlink_realpath_basic2.tmp",
33+
"$file_path/readlink_realpath_basic2/readlink_realpath_basic2.tmp",
34+
"$file_path/readlink_realpath_basic2//home/test//../test/./readlink_realpath_basic2.tmp",
35+
"$file_path/readlink_realpath_basic2/home//../././readlink_realpath_basic2.tmp",
36+
37+
// checking for binary safe
38+
b"$file_path/readlink_realpath_basic2/home/readlink_realpath_basic2.tmp",
39+
40+
/* filenames with invalid path */
41+
"$file_path///readlink_realpath_basic2/home//..//././test//readlink_realpath_basic2.tmp",
42+
"$file_path/readlink_realpath_basic2/home/../home/../test/../readlink_realpath_basic2.tmp",
43+
"$file_path/readlink_realpath_basic2/readlink_realpath_basic2.tmp/"
44+
);
45+
46+
$counter = 1;
47+
/* loop through $files to read the filepath of $file in the above array */
48+
foreach($filenames as $file) {
49+
echo "\n-- Iteration $counter --\n";
50+
var_dump( realpath($file) );
51+
$counter++;
52+
}
53+
54+
echo "Done\n";
55+
?>
56+
--CLEAN--
57+
<?php
58+
$name_prefix = dirname(__FILE__)."/readlink_realpath_basic2";
59+
unlink("$name_prefix/home/test/readlink_realpath_basic2.tmp");
60+
unlink("$name_prefix/home/readlink_realpath_basic2.tmp");
61+
unlink("$name_prefix/readlink_realpath_basic2.tmp");
62+
rmdir("$name_prefix/home/test/");
63+
rmdir("$name_prefix/home/");
64+
rmdir("$name_prefix/");
65+
?>
66+
--EXPECTF--
67+
*** Testing realpath() on filenames ***
68+
69+
-- Iteration 1 --
70+
string(%d) "%s/readlink_realpath_basic2/home/readlink_realpath_basic2.tmp"
71+
72+
-- Iteration 2 --
73+
string(%d) "%s/readlink_realpath_basic2/readlink_realpath_basic2.tmp"
74+
75+
-- Iteration 3 --
76+
string(%d) "%s/readlink_realpath_basic2/home/test/readlink_realpath_basic2.tmp"
77+
78+
-- Iteration 4 --
79+
string(%d) "%s/readlink_realpath_basic2/readlink_realpath_basic2.tmp"
80+
81+
-- Iteration 5 --
82+
string(%d) "%s/readlink_realpath_basic2/home/readlink_realpath_basic2.tmp"
83+
84+
-- Iteration 6 --
85+
bool(false)
86+
87+
-- Iteration 7 --
88+
bool(false)
89+
90+
-- Iteration 8 --
91+
%s
92+
Done

ext/standard/tests/file/readlink_realpath_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ Warning: Wrong parameter count for realpath() in %s on line %d
6969
NULL
7070

7171
*** Testing realpath() on a non-existent file ***
72-
bool(false)
72+
%s
7373
Done

0 commit comments

Comments
 (0)