1--TEST-- 2Test readlink() and realpath functions: basic functionality - diff. path notation for links(Bug #42038) 3--SKIPIF-- 4<?php 5if (PHP_OS_FAMILY === 'Windows') { 6 include __DIR__ . '/windows_links/common.inc'; 7 skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__); 8} 9?> 10--FILE-- 11<?php 12/* creating directories, symbolic links and files */ 13$file_path = __DIR__; 14mkdir("$file_path/readlink_realpath_basic1/home/test/", 0777, true); 15 16$file_handle1 = fopen("$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp", "w"); 17$file_handle2 = fopen("$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp", "w"); 18$file_handle3 = fopen("$file_path/readlink_realpath_basic1/readlink_realpath_basic1.tmp", "w"); 19fclose($file_handle1); 20fclose($file_handle2); 21fclose($file_handle3); 22 23symlink("$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp", 24 "$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1_link.tmp"); 25symlink("$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp", 26 "$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1_link.tmp"); 27 28 29echo "*** Testing readlink() and realpath(): with valid and invalid path ***\n"; 30$linknames = array ( 31 /* linknames resulting in valid paths */ 32 "$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1_link.tmp", 33 "$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1_link.tmp", 34 "$file_path/readlink_realpath_basic1//home/test//../test/./readlink_realpath_basic1_link.tmp", 35 36 /* linknames with invalid linkpath */ 37 "$file_path///readlink_realpath_basic1/home//..//././test//readlink_realpath_basic1_link.tmp", 38 "$file_path/readlink_realpath_basic1/home/../home/../test/../readlink_realpath_basic1_link.tmp", 39 "$file_path/readlink_realpath_basic1/..readlink_realpath_basic1_link.tmp", 40 "$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1_link.tmp/" 41); 42 43$counter = 1; 44/* loop through $files to read the linkpath of 45 the link created from each $file in the above array */ 46foreach($linknames as $link) { 47 echo "\n-- Iteration $counter --\n"; 48 var_dump( readlink($link) ); 49 var_dump( realpath($link) ); 50 $counter++; 51} 52 53echo "Done\n"; 54?> 55--CLEAN-- 56<?php 57$name_prefix = __DIR__."/readlink_realpath_basic1"; 58unlink("$name_prefix/home/test/readlink_realpath_basic1.tmp"); 59unlink("$name_prefix/home/readlink_realpath_basic1.tmp"); 60unlink("$name_prefix/readlink_realpath_basic1.tmp"); 61unlink("$name_prefix/home/test/readlink_realpath_basic1_link.tmp"); 62unlink("$name_prefix/home/readlink_realpath_basic1_link.tmp"); 63rmdir("$name_prefix/home/test/"); 64rmdir("$name_prefix/home/"); 65rmdir("$name_prefix/"); 66?> 67--EXPECTF-- 68*** Testing readlink() and realpath(): with valid and invalid path *** 69 70-- Iteration 1 -- 71string(%d) "%s%ereadlink_realpath_basic1%ehome%ereadlink_realpath_basic1.tmp" 72string(%d) "%s%ereadlink_realpath_basic1%ehome%ereadlink_realpath_basic1.tmp" 73 74-- Iteration 2 -- 75string(%d) "%s%ereadlink_realpath_basic1%ehome%etest%ereadlink_realpath_basic1.tmp" 76string(%d) "%s%ereadlink_realpath_basic1%ehome%etest%ereadlink_realpath_basic1.tmp" 77 78-- Iteration 3 -- 79string(%d) "%s%ereadlink_realpath_basic1%ehome%etest%ereadlink_realpath_basic1.tmp" 80string(%d) "%s%ereadlink_realpath_basic1%ehome%etest%ereadlink_realpath_basic1.tmp" 81 82-- Iteration 4 -- 83 84Warning: readlink(): %s in %s on line %d 85bool(false) 86bool(false) 87 88-- Iteration 5 -- 89 90Warning: readlink(): %s in %s on line %d 91bool(false) 92bool(false) 93 94-- Iteration 6 -- 95 96Warning: readlink(): %s in %s on line %d 97bool(false) 98%s 99 100-- Iteration 7 -- 101 102Warning: readlink(): %s in %s on line %d 103bool(false) 104%s 105Done 106