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