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