1--TEST--
2Test symlink(), linkinfo(), link() and is_link() functions: basic functionality - link to dirs
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: bool symlink ( string $target, string $link );
12   Description: creates a symbolic link to the existing target with the specified name link
13
14   Prototype: bool is_link ( string $filename );
15   Description: Tells whether the given file is a symbolic link.
16
17   Prototype: bool link ( string $target, string $link );
18   Description: Create a hard link
19
20   Prototype: int linkinfo ( string $path );
21   Description: Gets information about a link
22*/
23
24$file_path = dirname(__FILE__);
25
26echo "*** Testing symlink(), linkinfo(), link() and is_link() : basic functionality ***\n";
27
28/* Creating soft/hard link to the temporary dir $dirname and checking
29   linkinfo() and is_link() on the link created to $dirname */
30
31$dirname = "symlink_link_linkinfo_is_link_basic2";
32mkdir($file_path."/".$dirname);
33
34echo "\n*** Testing symlink(), linkinfo(), link() and is_link() on directory ***\n";
35
36// name of the soft link created to $dirname
37$sym_linkname = "$file_path/$dirname/symlink_link_linkinfo_is_link_softlink_basic2.tmp";
38
39// name of the hard link created to $dirname
40$linkname = "$file_path/$dirname/symlink_link_linkinfo_is_link_hardlink_basic2.tmp";
41
42// testing on soft link
43echo "\n-- Testing on soft links --\n";
44// creating soft link to $dirname
45var_dump( symlink("$file_path/$dirname", $sym_linkname) ); // this works, expected true
46// gets information about soft link created to directory; expected: true
47var_dump( linkinfo($sym_linkname) );
48// checks if link created is soft link; expected: true
49var_dump( is_link($sym_linkname) );
50// clear the cache
51clearstatcache();
52
53// testing on hard link
54echo "\n-- Testing on hard links --\n";
55// creating hard link to $dirname; expected: false
56var_dump( link("$file_path/$dirname", $linkname) ); // this doesn't work, expected false
57var_dump( linkinfo($linkname) ); // link doesn't exists as not created, expected false
58var_dump( is_link($linkname) ); // link doesn't exists as not created, expected false
59// clear the cache
60clearstatcache();
61
62// deleting the links
63unlink($sym_linkname);
64
65echo "Done\n";
66?>
67--CLEAN--
68<?php
69$dirname = dirname(__FILE__)."/symlink_link_linkinfo_is_link_basic2";
70rmdir($dirname);
71?>
72--EXPECTF--
73*** Testing symlink(), linkinfo(), link() and is_link() : basic functionality ***
74
75*** Testing symlink(), linkinfo(), link() and is_link() on directory ***
76
77-- Testing on soft links --
78bool(true)
79int(%d)
80bool(true)
81
82-- Testing on hard links --
83
84Warning: link(): %s in %s on line %d
85bool(false)
86
87Warning: linkinfo(): No such file or directory in %s on line %d
88int(-1)
89bool(false)
90Done
91