-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
9 changed files
with
374 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
ext/standard/tests/file/readlink_realpath_basic2-win32.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
--TEST-- | ||
Test readlink() and realpath functions: basic functionality - diff. path notation for files | ||
--SKIPIF-- | ||
<?php | ||
if (substr(PHP_OS, 0, 3) != 'WIN') { | ||
die('skip only for Windows'); | ||
} | ||
?> | ||
--FILE-- | ||
<?php | ||
/* Prototype: string readlink ( string $path ); | ||
Description: Returns the target of a symbolic link | ||
Prototype: string realpath ( string $path ); | ||
Description: Returns canonicalized absolute pathname | ||
*/ | ||
|
||
/* creating directories, symbolic links and files */ | ||
$file_path = __DIR__; | ||
mkdir("$file_path/readlink_realpath_basic2/home/test/", 0777, true); | ||
|
||
$file_handle1 = fopen("$file_path/readlink_realpath_basic2/home/test/readlink_realpath_basic2.tmp", "w"); | ||
$file_handle2 = fopen("$file_path/readlink_realpath_basic2/home/readlink_realpath_basic2.tmp", "w"); | ||
$file_handle3 = fopen("$file_path/readlink_realpath_basic2/readlink_realpath_basic2.tmp", "w"); | ||
fclose($file_handle1); | ||
fclose($file_handle2); | ||
fclose($file_handle3); | ||
|
||
echo "\n*** Testing realpath() on filenames ***\n"; | ||
$filenames = array ( | ||
/* filenames resulting in valid paths */ | ||
"$file_path/readlink_realpath_basic2/home/readlink_realpath_basic2.tmp", | ||
"$file_path/readlink_realpath_basic2/readlink_realpath_basic2.tmp", | ||
"$file_path/readlink_realpath_basic2//home/test//../test/./readlink_realpath_basic2.tmp", | ||
"$file_path/readlink_realpath_basic2/home//../././readlink_realpath_basic2.tmp", | ||
|
||
/* filenames with invalid path */ | ||
"$file_path///readlink_realpath_basic2/home//..//././test//readlink_realpath_basic2.tmp", | ||
"$file_path/readlink_realpath_basic2/home/../home/../test/../readlink_realpath_basic2.tmp", | ||
"$file_path/readlink_realpath_basic2/readlink_realpath_basic2.tmp/" | ||
); | ||
|
||
$counter = 1; | ||
/* loop through $files to read the filepath of $file in the above array */ | ||
foreach($filenames as $file) { | ||
echo "\n-- Iteration $counter --\n"; | ||
var_dump( realpath($file) ); | ||
$counter++; | ||
} | ||
|
||
echo "Done\n"; | ||
?> | ||
--CLEAN-- | ||
<?php | ||
$name_prefix = __DIR__."/readlink_realpath_basic2"; | ||
unlink("$name_prefix/home/test/readlink_realpath_basic2.tmp"); | ||
unlink("$name_prefix/home/readlink_realpath_basic2.tmp"); | ||
unlink("$name_prefix/readlink_realpath_basic2.tmp"); | ||
rmdir("$name_prefix/home/test/"); | ||
rmdir("$name_prefix/home/"); | ||
rmdir("$name_prefix/"); | ||
?> | ||
--EXPECTF-- | ||
*** Testing realpath() on filenames *** | ||
|
||
-- Iteration 1 -- | ||
string(%d) "%s%ereadlink_realpath_basic2%ehome%ereadlink_realpath_basic2.tmp" | ||
|
||
-- Iteration 2 -- | ||
string(%d) "%s%ereadlink_realpath_basic2%ereadlink_realpath_basic2.tmp" | ||
|
||
-- Iteration 3 -- | ||
string(%d) "%s%ereadlink_realpath_basic2%ehome%etest%ereadlink_realpath_basic2.tmp" | ||
|
||
-- Iteration 4 -- | ||
string(%d) "%s%ereadlink_realpath_basic2%ereadlink_realpath_basic2.tmp" | ||
|
||
-- Iteration 5 -- | ||
bool(false) | ||
|
||
-- Iteration 6 -- | ||
string(%d) "%s%eext%estandard%etests%efile%ereadlink_realpath_basic2%ereadlink_realpath_basic2.tmp" | ||
|
||
-- Iteration 7 -- | ||
%s | ||
Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
ext/standard/tests/file/readlink_realpath_error-win32.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--TEST-- | ||
Test readlink() and realpath() functions: error conditions | ||
--SKIPIF-- | ||
<?php | ||
if (substr(PHP_OS, 0, 3) != 'WIN') { | ||
die('skip only for Windows'); | ||
} | ||
?> | ||
--FILE-- | ||
<?php | ||
/* Prototype: string readlink ( string $path ); | ||
Description: Returns the target of a symbolic link | ||
Prototype: string realpath ( string $path ); | ||
Description: Returns canonicalized absolute pathname | ||
*/ | ||
|
||
echo "*** Testing readlink(): error conditions ***\n"; | ||
var_dump( readlink() ); // args < expected | ||
var_dump( readlink(__FILE__, 2) ); // args > expected | ||
|
||
echo "\n*** Testing readlink() on a non-existent link ***\n"; | ||
var_dump( readlink(__DIR__."/readlink_error.tmp") ); | ||
|
||
echo "\n*** Testing readlink() on existing file ***\n"; | ||
var_dump( readlink(__FILE__) ); | ||
|
||
echo "\n*** Testing readlink() on existing directory ***\n"; | ||
var_dump( readlink(__DIR__) ); | ||
|
||
echo "*** Testing realpath(): error conditions ***\n"; | ||
var_dump( realpath() ); // args < expected | ||
var_dump( realpath(1, 2) ); // args > expected | ||
|
||
echo "\n*** Testing realpath() on a non-existent file ***\n"; | ||
var_dump( realpath(__DIR__."/realpath_error.tmp") ); | ||
|
||
echo "Done\n"; | ||
?> | ||
--EXPECTF-- | ||
*** Testing readlink(): error conditions *** | ||
|
||
Warning: readlink() expects exactly 1 parameter, 0 given in %s on line %d | ||
NULL | ||
|
||
Warning: readlink() expects exactly 1 parameter, 2 given in %s on line %d | ||
NULL | ||
|
||
*** Testing readlink() on a non-existent link *** | ||
|
||
Warning: readlink(): readlink failed to read the symbolic link (%s, error %d) in %s on line %d | ||
bool(false) | ||
|
||
*** Testing readlink() on existing file *** | ||
string(%d) "%s%eext%estandard%etests%efile%ereadlink_realpath_error-win32.php" | ||
|
||
*** Testing readlink() on existing directory *** | ||
string(%d) "%s%eext%estandard%etests%efile" | ||
*** Testing realpath(): error conditions *** | ||
|
||
Warning: realpath() expects exactly 1 parameter, 0 given in %s on line %d | ||
NULL | ||
|
||
Warning: realpath() expects exactly 1 parameter, 2 given in %s on line %d | ||
NULL | ||
|
||
*** Testing realpath() on a non-existent file *** | ||
%s | ||
Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
ext/standard/tests/file/readlink_realpath_variation1-win32.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
--TEST-- | ||
Test readlink() and realpath() functions: usage variation - linkname/filename stored in object(Bug #42038) | ||
--SKIPIF-- | ||
<?php | ||
if (substr(PHP_OS, 0, 3) != 'WIN') { | ||
die('skip only for Windows'); | ||
} else { | ||
include __DIR__ . '/windows_links/common.inc'; | ||
skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__); | ||
} | ||
?> | ||
--FILE-- | ||
<?php | ||
/* Prototype: string readlink ( string $path ); | ||
Description: Returns the target of a symbolic link | ||
Prototype: string realpath ( string $path ); | ||
Description: Returns canonicalized absolute pathname | ||
*/ | ||
|
||
echo "*** Testing readlink() and realpath() : usage variations ***\n"; | ||
$name_prefix = __DIR__; | ||
$filename = "$name_prefix/readlink_realpath_variation1/home/tests/link/readlink_realpath_variation1.tmp"; | ||
mkdir("$name_prefix/readlink_realpath_variation1/home/tests/link/", 0777, true); | ||
|
||
echo "\n*** Testing readlink() and realpath() with linkname stored inside a object ***\n"; | ||
// create a temp file | ||
$file_handle = fopen($filename, "w"); | ||
fclose($file_handle); | ||
|
||
// creating object with members as linkname | ||
class object_temp { | ||
public $linkname; | ||
function __construct($link) { | ||
$this->linkname = $link; | ||
} | ||
} | ||
$obj1 = new object_temp("$name_prefix/readlink_realpath_variation1/../././readlink_realpath_variation1/home/readlink_realpath_variation1_link.tmp"); | ||
$obj2 = new object_temp("$name_prefix/readlink_realpath_variation1/home/../..///readlink_realpath_variation1_link.tmp"); | ||
|
||
echo "\n-- Testing readlink() and realpath() with softlink, linkname stored inside an object --\n"; | ||
// creating the links | ||
var_dump( symlink($filename, $obj1->linkname) ); | ||
var_dump( readlink($obj1->linkname) ); | ||
var_dump( realpath($obj1->linkname) ); | ||
var_dump( symlink($filename, $obj2->linkname) ); | ||
var_dump( readlink($obj2->linkname) ); | ||
var_dump( realpath($obj2->linkname) ); | ||
|
||
// deleting the link | ||
unlink($obj1->linkname); | ||
unlink($obj2->linkname); | ||
|
||
echo "\n-- Testing readlink() and realpath() with hardlink, linkname stored inside an object --\n"; | ||
// creating hard links | ||
var_dump( link($filename, $obj1->linkname) ); | ||
var_dump( readlink($obj1->linkname) ); // invalid because readlink doesn't work with hardlink | ||
var_dump( realpath($obj1->linkname) ); | ||
var_dump( link($filename, $obj2->linkname) ); | ||
var_dump( readlink($obj2->linkname) ); // invalid because readlink doesn't work with hardlink | ||
var_dump( realpath($obj2->linkname) ); | ||
|
||
// delete the links | ||
unlink($obj1->linkname); | ||
unlink($obj2->linkname); | ||
|
||
echo "Done\n"; | ||
?> | ||
--CLEAN-- | ||
<?php | ||
$name_prefix = __DIR__."/readlink_realpath_variation1"; | ||
unlink("$name_prefix/home/tests/link/readlink_realpath_variation1.tmp"); | ||
rmdir("$name_prefix/home/tests/link/"); | ||
rmdir("$name_prefix/home/tests/"); | ||
rmdir("$name_prefix/home/"); | ||
rmdir("$name_prefix/"); | ||
?> | ||
--EXPECTF-- | ||
*** Testing readlink() and realpath() : usage variations *** | ||
|
||
*** Testing readlink() and realpath() with linkname stored inside a object *** | ||
|
||
-- Testing readlink() and realpath() with softlink, linkname stored inside an object -- | ||
bool(true) | ||
string(%d) "%s%ereadlink_realpath_variation1%ehome%etests%elink%ereadlink_realpath_variation1.tmp" | ||
string(%d) "%s%ereadlink_realpath_variation1%ehome%etests%elink%ereadlink_realpath_variation1.tmp" | ||
bool(true) | ||
string(%d) "%s%ereadlink_realpath_variation1%ehome%etests%elink%ereadlink_realpath_variation1.tmp" | ||
string(%d) "%s%ereadlink_realpath_variation1%ehome%etests%elink%ereadlink_realpath_variation1.tmp" | ||
|
||
-- Testing readlink() and realpath() with hardlink, linkname stored inside an object -- | ||
bool(true) | ||
string(%d) "%s%ereadlink_realpath_variation1%ehome%ereadlink_realpath_variation1_link.tmp" | ||
string(%d) "%s%ereadlink_realpath_variation1%ehome%ereadlink_realpath_variation1_link.tmp" | ||
bool(true) | ||
string(%d) "%s%ereadlink_realpath_variation1_link.tmp" | ||
string(%d) "%s%ereadlink_realpath_variation1_link.tmp" | ||
Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.