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