1--TEST--
2Test readlink() and realpath functions: basic functionality - diff. path notation for links(Bug #42038)
3--SKIPIF--
4<?php
5if (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__);
20mkdir("$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");
25fclose($file_handle1);
26fclose($file_handle2);
27fclose($file_handle3);
28
29symlink("$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp",
30        "$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1_link.tmp");
31symlink("$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp",
32        "$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1_link.tmp");
33
34
35echo "*** 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  /* linknames with invalid linkpath */
43  "$file_path///readlink_realpath_basic1/home//..//././test//readlink_realpath_basic1_link.tmp",
44  "$file_path/readlink_realpath_basic1/home/../home/../test/../readlink_realpath_basic1_link.tmp",
45  "$file_path/readlink_realpath_basic1/..readlink_realpath_basic1_link.tmp",
46  "$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1_link.tmp/"
47);
48
49$counter = 1;
50/* loop through $files to read the linkpath of
51   the link created from each $file in the above array */
52foreach($linknames as $link) {
53  echo "\n-- Iteration $counter --\n";
54  var_dump( readlink($link) );
55  var_dump( realpath($link) );
56  $counter++;
57}
58
59echo "Done\n";
60?>
61--CLEAN--
62<?php
63$name_prefix = dirname(__FILE__)."/readlink_realpath_basic1";
64unlink("$name_prefix/home/test/readlink_realpath_basic1.tmp");
65unlink("$name_prefix/home/readlink_realpath_basic1.tmp");
66unlink("$name_prefix/readlink_realpath_basic1.tmp");
67unlink("$name_prefix/home/test/readlink_realpath_basic1_link.tmp");
68unlink("$name_prefix/home/readlink_realpath_basic1_link.tmp");
69rmdir("$name_prefix/home/test/");
70rmdir("$name_prefix/home/");
71rmdir("$name_prefix/");
72?>
73--EXPECTF--
74*** Testing readlink() and realpath(): with valid and invalid path ***
75
76-- Iteration 1 --
77string(%d) "%s/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp"
78string(%d) "%s/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp"
79
80-- Iteration 2 --
81string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
82string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
83
84-- Iteration 3 --
85string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
86string(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp"
87
88-- Iteration 4 --
89
90Warning: readlink(): No such file or directory in %s on line %d
91bool(false)
92bool(false)
93
94-- Iteration 5 --
95
96Warning: readlink(): No such file or directory in %s on line %d
97bool(false)
98bool(false)
99
100-- Iteration 6 --
101
102Warning: readlink(): No such file or directory in %s on line %d
103bool(false)
104%s
105
106-- Iteration 7 --
107
108Warning: readlink(): %s in %s on line %d
109bool(false)
110%s
111Done
112