Skip to content

Commit 6f0b733

Browse files
committed
Enable readlink_realpath_* tests on Windows
We modify _basic1.phpt so it runs on Windows as well. The other test cases hit the issue that `readlink()` fails normally for regular files, but succeeds on Windows[1]. Therefore, we split these tests, but still fix the skip reasons. [1] <http://svn.php.net/viewvc?view=revision&revision=350097>
1 parent 1973ca2 commit 6f0b733

9 files changed

+374
-15
lines changed

ext/standard/tests/file/readlink_realpath_basic1.phpt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
Test readlink() and realpath functions: basic functionality - diff. path notation for links(Bug #42038)
33
--SKIPIF--
44
<?php
5-
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
5+
if (PHP_OS_FAMILY === 'Windows') {
6+
include __DIR__ . '/windows_links/common.inc';
7+
skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__);
78
}
89
?>
910
--FILE--
@@ -74,32 +75,32 @@ rmdir("$name_prefix/");
7475
*** Testing readlink() and realpath(): with valid and invalid path ***
7576

7677
-- Iteration 1 --
77-
string(%d) "%s/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp"
78-
string(%d) "%s/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp"
78+
string(%d) "%s%ereadlink_realpath_basic1%ehome%ereadlink_realpath_basic1.tmp"
79+
string(%d) "%s%ereadlink_realpath_basic1%ehome%ereadlink_realpath_basic1.tmp"
7980

8081
-- Iteration 2 --
81-
string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
82-
string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
82+
string(%d) "%s%ereadlink_realpath_basic1%ehome%etest%ereadlink_realpath_basic1.tmp"
83+
string(%d) "%s%ereadlink_realpath_basic1%ehome%etest%ereadlink_realpath_basic1.tmp"
8384

8485
-- Iteration 3 --
85-
string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
86-
string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
86+
string(%d) "%s%ereadlink_realpath_basic1%ehome%etest%ereadlink_realpath_basic1.tmp"
87+
string(%d) "%s%ereadlink_realpath_basic1%ehome%etest%ereadlink_realpath_basic1.tmp"
8788

8889
-- Iteration 4 --
8990

90-
Warning: readlink(): No such file or directory in %s on line %d
91+
Warning: readlink(): %s in %s on line %d
9192
bool(false)
9293
bool(false)
9394

9495
-- Iteration 5 --
9596

96-
Warning: readlink(): No such file or directory in %s on line %d
97+
Warning: readlink(): %s in %s on line %d
9798
bool(false)
9899
bool(false)
99100

100101
-- Iteration 6 --
101102

102-
Warning: readlink(): No such file or directory in %s on line %d
103+
Warning: readlink(): %s in %s on line %d
103104
bool(false)
104105
%s
105106

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 only for 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 = __DIR__;
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+
/* filenames with invalid path */
38+
"$file_path///readlink_realpath_basic2/home//..//././test//readlink_realpath_basic2.tmp",
39+
"$file_path/readlink_realpath_basic2/home/../home/../test/../readlink_realpath_basic2.tmp",
40+
"$file_path/readlink_realpath_basic2/readlink_realpath_basic2.tmp/"
41+
);
42+
43+
$counter = 1;
44+
/* loop through $files to read the filepath of $file in the above array */
45+
foreach($filenames as $file) {
46+
echo "\n-- Iteration $counter --\n";
47+
var_dump( realpath($file) );
48+
$counter++;
49+
}
50+
51+
echo "Done\n";
52+
?>
53+
--CLEAN--
54+
<?php
55+
$name_prefix = __DIR__."/readlink_realpath_basic2";
56+
unlink("$name_prefix/home/test/readlink_realpath_basic2.tmp");
57+
unlink("$name_prefix/home/readlink_realpath_basic2.tmp");
58+
unlink("$name_prefix/readlink_realpath_basic2.tmp");
59+
rmdir("$name_prefix/home/test/");
60+
rmdir("$name_prefix/home/");
61+
rmdir("$name_prefix/");
62+
?>
63+
--EXPECTF--
64+
*** Testing realpath() on filenames ***
65+
66+
-- Iteration 1 --
67+
string(%d) "%s%ereadlink_realpath_basic2%ehome%ereadlink_realpath_basic2.tmp"
68+
69+
-- Iteration 2 --
70+
string(%d) "%s%ereadlink_realpath_basic2%ereadlink_realpath_basic2.tmp"
71+
72+
-- Iteration 3 --
73+
string(%d) "%s%ereadlink_realpath_basic2%ehome%etest%ereadlink_realpath_basic2.tmp"
74+
75+
-- Iteration 4 --
76+
string(%d) "%s%ereadlink_realpath_basic2%ereadlink_realpath_basic2.tmp"
77+
78+
-- Iteration 5 --
79+
bool(false)
80+
81+
-- Iteration 6 --
82+
string(%d) "%s%eext%estandard%etests%efile%ereadlink_realpath_basic2%ereadlink_realpath_basic2.tmp"
83+
84+
-- Iteration 7 --
85+
%s
86+
Done

ext/standard/tests/file/readlink_realpath_basic2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Test readlink() and realpath functions: basic functionality - diff. path notatio
33
--SKIPIF--
44
<?php
55
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
6+
die('skip not for Windows');
77
}
88
?>
99
--FILE--
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
--TEST--
2+
Test readlink() and realpath() functions: error conditions
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) != 'WIN') {
6+
die('skip only for 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+
echo "*** Testing readlink(): error conditions ***\n";
19+
var_dump( readlink() ); // args < expected
20+
var_dump( readlink(__FILE__, 2) ); // args > expected
21+
22+
echo "\n*** Testing readlink() on a non-existent link ***\n";
23+
var_dump( readlink(__DIR__."/readlink_error.tmp") );
24+
25+
echo "\n*** Testing readlink() on existing file ***\n";
26+
var_dump( readlink(__FILE__) );
27+
28+
echo "\n*** Testing readlink() on existing directory ***\n";
29+
var_dump( readlink(__DIR__) );
30+
31+
echo "*** Testing realpath(): error conditions ***\n";
32+
var_dump( realpath() ); // args < expected
33+
var_dump( realpath(1, 2) ); // args > expected
34+
35+
echo "\n*** Testing realpath() on a non-existent file ***\n";
36+
var_dump( realpath(__DIR__."/realpath_error.tmp") );
37+
38+
echo "Done\n";
39+
?>
40+
--EXPECTF--
41+
*** Testing readlink(): error conditions ***
42+
43+
Warning: readlink() expects exactly 1 parameter, 0 given in %s on line %d
44+
NULL
45+
46+
Warning: readlink() expects exactly 1 parameter, 2 given in %s on line %d
47+
NULL
48+
49+
*** Testing readlink() on a non-existent link ***
50+
51+
Warning: readlink(): readlink failed to read the symbolic link (%s, error %d) in %s on line %d
52+
bool(false)
53+
54+
*** Testing readlink() on existing file ***
55+
string(%d) "%s%eext%estandard%etests%efile%ereadlink_realpath_error-win32.php"
56+
57+
*** Testing readlink() on existing directory ***
58+
string(%d) "%s%eext%estandard%etests%efile"
59+
*** Testing realpath(): error conditions ***
60+
61+
Warning: realpath() expects exactly 1 parameter, 0 given in %s on line %d
62+
NULL
63+
64+
Warning: realpath() expects exactly 1 parameter, 2 given in %s on line %d
65+
NULL
66+
67+
*** Testing realpath() on a non-existent file ***
68+
%s
69+
Done

ext/standard/tests/file/readlink_realpath_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Test readlink() and realpath() functions: error conditions
33
--SKIPIF--
44
<?php
55
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
6+
die('skip not for Windows');
77
}
88
?>
99
--FILE--
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
--TEST--
2+
Test readlink() and realpath() functions: usage variation - linkname/filename stored in object(Bug #42038)
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) != 'WIN') {
6+
die('skip only for Windows');
7+
} else {
8+
include __DIR__ . '/windows_links/common.inc';
9+
skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__);
10+
}
11+
?>
12+
--FILE--
13+
<?php
14+
/* Prototype: string readlink ( string $path );
15+
Description: Returns the target of a symbolic link
16+
17+
Prototype: string realpath ( string $path );
18+
Description: Returns canonicalized absolute pathname
19+
*/
20+
21+
echo "*** Testing readlink() and realpath() : usage variations ***\n";
22+
$name_prefix = __DIR__;
23+
$filename = "$name_prefix/readlink_realpath_variation1/home/tests/link/readlink_realpath_variation1.tmp";
24+
mkdir("$name_prefix/readlink_realpath_variation1/home/tests/link/", 0777, true);
25+
26+
echo "\n*** Testing readlink() and realpath() with linkname stored inside a object ***\n";
27+
// create a temp file
28+
$file_handle = fopen($filename, "w");
29+
fclose($file_handle);
30+
31+
// creating object with members as linkname
32+
class object_temp {
33+
public $linkname;
34+
function __construct($link) {
35+
$this->linkname = $link;
36+
}
37+
}
38+
$obj1 = new object_temp("$name_prefix/readlink_realpath_variation1/../././readlink_realpath_variation1/home/readlink_realpath_variation1_link.tmp");
39+
$obj2 = new object_temp("$name_prefix/readlink_realpath_variation1/home/../..///readlink_realpath_variation1_link.tmp");
40+
41+
echo "\n-- Testing readlink() and realpath() with softlink, linkname stored inside an object --\n";
42+
// creating the links
43+
var_dump( symlink($filename, $obj1->linkname) );
44+
var_dump( readlink($obj1->linkname) );
45+
var_dump( realpath($obj1->linkname) );
46+
var_dump( symlink($filename, $obj2->linkname) );
47+
var_dump( readlink($obj2->linkname) );
48+
var_dump( realpath($obj2->linkname) );
49+
50+
// deleting the link
51+
unlink($obj1->linkname);
52+
unlink($obj2->linkname);
53+
54+
echo "\n-- Testing readlink() and realpath() with hardlink, linkname stored inside an object --\n";
55+
// creating hard links
56+
var_dump( link($filename, $obj1->linkname) );
57+
var_dump( readlink($obj1->linkname) ); // invalid because readlink doesn't work with hardlink
58+
var_dump( realpath($obj1->linkname) );
59+
var_dump( link($filename, $obj2->linkname) );
60+
var_dump( readlink($obj2->linkname) ); // invalid because readlink doesn't work with hardlink
61+
var_dump( realpath($obj2->linkname) );
62+
63+
// delete the links
64+
unlink($obj1->linkname);
65+
unlink($obj2->linkname);
66+
67+
echo "Done\n";
68+
?>
69+
--CLEAN--
70+
<?php
71+
$name_prefix = __DIR__."/readlink_realpath_variation1";
72+
unlink("$name_prefix/home/tests/link/readlink_realpath_variation1.tmp");
73+
rmdir("$name_prefix/home/tests/link/");
74+
rmdir("$name_prefix/home/tests/");
75+
rmdir("$name_prefix/home/");
76+
rmdir("$name_prefix/");
77+
?>
78+
--EXPECTF--
79+
*** Testing readlink() and realpath() : usage variations ***
80+
81+
*** Testing readlink() and realpath() with linkname stored inside a object ***
82+
83+
-- Testing readlink() and realpath() with softlink, linkname stored inside an object --
84+
bool(true)
85+
string(%d) "%s%ereadlink_realpath_variation1%ehome%etests%elink%ereadlink_realpath_variation1.tmp"
86+
string(%d) "%s%ereadlink_realpath_variation1%ehome%etests%elink%ereadlink_realpath_variation1.tmp"
87+
bool(true)
88+
string(%d) "%s%ereadlink_realpath_variation1%ehome%etests%elink%ereadlink_realpath_variation1.tmp"
89+
string(%d) "%s%ereadlink_realpath_variation1%ehome%etests%elink%ereadlink_realpath_variation1.tmp"
90+
91+
-- Testing readlink() and realpath() with hardlink, linkname stored inside an object --
92+
bool(true)
93+
string(%d) "%s%ereadlink_realpath_variation1%ehome%ereadlink_realpath_variation1_link.tmp"
94+
string(%d) "%s%ereadlink_realpath_variation1%ehome%ereadlink_realpath_variation1_link.tmp"
95+
bool(true)
96+
string(%d) "%s%ereadlink_realpath_variation1_link.tmp"
97+
string(%d) "%s%ereadlink_realpath_variation1_link.tmp"
98+
Done

ext/standard/tests/file/readlink_realpath_variation1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Test readlink() and realpath() functions: usage variation - linkname/filename st
33
--SKIPIF--
44
<?php
55
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
6+
die('skip not for Windows');
77
}
88
?>
99
--FILE--

0 commit comments

Comments
 (0)