1--TEST--
2Test readlink() and realpath() functions: usage variation - linkname/filename stored in array(Bug #42038)
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip not for Windows');
7}
8?>
9--FILE--
10<?php
11echo "*** Testing readlink() and realpath() : usage variations ***\n";
12$name_prefix = __DIR__;
13// create temp dir
14mkdir("$name_prefix/readlink_realpath_variation2/home/tests/link/", 0777, true);
15// create the file
16$filename = "$name_prefix/readlink_realpath_variation2/home/tests/link/readlink_realpath_variation2.tmp";
17$fp = fopen($filename, "w");
18fclose($fp);
19
20echo "\n*** Testing readlink() and realpath() with linkname stored in an array ***\n";
21$link_arr = array (
22  "$name_prefix////readlink_realpath_variation2/home/tests/link/readlink_realpath_variation2_link.tmp",
23  "$name_prefix/./readlink_realpath_variation2/home/../home//tests//..//..//..//home//readlink_realpath_variation2_link.tmp/"
24);
25
26echo "\n-- Testing readlink() and realpath() with softlink, linkname stored inside an array --\n";
27// creating the links
28var_dump( symlink($filename, $link_arr[0]) );
29var_dump( readlink($link_arr[0]) );
30var_dump( realpath($link_arr[0]) );
31var_dump( symlink($filename, $link_arr[1]) );
32var_dump( readlink($link_arr[1]) );
33var_dump( realpath($link_arr[1]) );
34
35// deleting the link
36unlink($link_arr[0]);
37unlink($link_arr[1]);
38
39echo "\n-- Testing readlink() and realpath() with hardlink, linkname stored inside an array --\n";
40// creating hard links
41var_dump( link($filename, $link_arr[0]) );
42var_dump( readlink($link_arr[0]) );   // invalid because readlink doesn't work with hardlink
43var_dump( realpath($link_arr[0]) );
44var_dump( link($filename, $link_arr[1]) );
45var_dump( readlink($link_arr[1]) );   // invalid because readlink doesn't work with hardlink
46var_dump( realpath($link_arr[1]) );
47
48// delete the links
49unlink($link_arr[0]);
50unlink($link_arr[1]);
51
52echo "Done\n";
53?>
54--CLEAN--
55<?php
56$name_prefix = __DIR__."/readlink_realpath_variation2";
57unlink("$name_prefix/home/tests/link/readlink_realpath_variation2.tmp");
58rmdir("$name_prefix/home/tests/link/");
59rmdir("$name_prefix/home/tests/");
60rmdir("$name_prefix/home/");
61rmdir("$name_prefix/");
62?>
63--EXPECTF--
64*** Testing readlink() and realpath() : usage variations ***
65
66*** Testing readlink() and realpath() with linkname stored in an array ***
67
68-- Testing readlink() and realpath() with softlink, linkname stored inside an array --
69bool(true)
70string(%d) "%s/readlink_realpath_variation2/home/tests/link/readlink_realpath_variation2.tmp"
71string(%d) "%s/readlink_realpath_variation2/home/tests/link/readlink_realpath_variation2.tmp"
72
73Warning: symlink(): No such file or directory in %s on line %d
74bool(false)
75
76Warning: readlink(): No such file or directory in %s on line %d
77bool(false)
78bool(false)
79
80Warning: unlink(%s/./readlink_realpath_variation2/home/../home//tests//..//..//..//home//readlink_realpath_variation2_link.tmp/): No such file or directory in %s on line %d
81
82-- Testing readlink() and realpath() with hardlink, linkname stored inside an array --
83bool(true)
84
85Warning: readlink(): Invalid argument in %s on line %d
86bool(false)
87string(%d) "%s/readlink_realpath_variation2/home/tests/link/readlink_realpath_variation2_link.tmp"
88
89Warning: link(): No such file or directory in %s on line %d
90bool(false)
91
92Warning: readlink(): No such file or directory in %s on line %d
93bool(false)
94bool(false)
95
96Warning: unlink(%s/./readlink_realpath_variation2/home/../home//tests//..//..//..//home//readlink_realpath_variation2_link.tmp/): No such file or directory in %s on line %d
97Done
98