File:
[ELWIX - Embedded LightWeight unIX -] /
embedaddon /
php /
ext /
standard /
tests /
file /
readlink_realpath_basic1.phpt
Revision
1.1.1.1 (vendor branch):
download - view:
text,
annotated -
select for diffs -
revision graph
Tue Feb 21 23:48:04 2012 UTC (12 years, 8 months ago) by
misho
Branches:
php,
MAIN
CVS tags:
v5_4_3elwix,
v5_4_29p0,
v5_4_29,
v5_4_20p0,
v5_4_20,
v5_4_17p0,
v5_4_17,
v5_3_10,
HEAD
php
--TEST--
Test readlink() and realpath functions: basic functionality - diff. path notation for links(Bug #42038)
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip no symlinks on 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 = dirname(__FILE__);
mkdir("$file_path/readlink_realpath_basic1/home/test/", 0777, true);
$file_handle1 = fopen("$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp", "w");
$file_handle2 = fopen("$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp", "w");
$file_handle3 = fopen("$file_path/readlink_realpath_basic1/readlink_realpath_basic1.tmp", "w");
fclose($file_handle1);
fclose($file_handle2);
fclose($file_handle3);
symlink("$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp",
"$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1_link.tmp");
symlink("$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp",
"$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1_link.tmp");
echo "*** Testing readlink() and realpath(): with valid and invalid path ***\n";
$linknames = array (
/* linknames resulting in valid paths */
"$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1_link.tmp",
"$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1_link.tmp",
"$file_path/readlink_realpath_basic1//home/test//../test/./readlink_realpath_basic1_link.tmp",
/* linknames with invalid linkpath */
"$file_path///readlink_realpath_basic1/home//..//././test//readlink_realpath_basic1_link.tmp",
"$file_path/readlink_realpath_basic1/home/../home/../test/../readlink_realpath_basic1_link.tmp",
"$file_path/readlink_realpath_basic1/..readlink_realpath_basic1_link.tmp",
"$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1_link.tmp/"
);
$counter = 1;
/* loop through $files to read the linkpath of
the link created from each $file in the above array */
foreach($linknames as $link) {
echo "\n-- Iteration $counter --\n";
var_dump( readlink($link) );
var_dump( realpath($link) );
$counter++;
}
echo "Done\n";
?>
--CLEAN--
<?php
$name_prefix = dirname(__FILE__)."/readlink_realpath_basic1";
unlink("$name_prefix/home/test/readlink_realpath_basic1.tmp");
unlink("$name_prefix/home/readlink_realpath_basic1.tmp");
unlink("$name_prefix/readlink_realpath_basic1.tmp");
unlink("$name_prefix/home/test/readlink_realpath_basic1_link.tmp");
unlink("$name_prefix/home/readlink_realpath_basic1_link.tmp");
rmdir("$name_prefix/home/test/");
rmdir("$name_prefix/home/");
rmdir("$name_prefix/");
?>
--EXPECTF--
*** Testing readlink() and realpath(): with valid and invalid path ***
-- Iteration 1 --
string(%d) "%s/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp"
string(%d) "%s/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp"
-- Iteration 2 --
string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
-- Iteration 3 --
string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
-- Iteration 4 --
Warning: readlink(): No such file or directory in %s on line %d
bool(false)
bool(false)
-- Iteration 5 --
Warning: readlink(): No such file or directory in %s on line %d
bool(false)
bool(false)
-- Iteration 6 --
Warning: readlink(): No such file or directory in %s on line %d
bool(false)
%s
-- Iteration 7 --
Warning: readlink(): %s in %s on line %d
bool(false)
%s
Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>