1--TEST--
2Test symlink(), linkinfo(), link() and is_link() functions: basic functionality - link to dirs
3--SKIPIF--
4<?php
5if (PHP_OS_FAMILY === 'Windows') {
6    require_once __DIR__ . '/windows_links/common.inc';
7    skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__);
8}
9?>
10--FILE--
11<?php
12$file_path = __DIR__;
13
14echo "*** Testing symlink(), linkinfo(), link() and is_link() : basic functionality ***\n";
15
16/* Creating soft/hard link to the temporary dir $dirname and checking
17   linkinfo() and is_link() on the link created to $dirname */
18
19$dirname = "symlink_link_linkinfo_is_link_basic2";
20mkdir($file_path."/".$dirname);
21
22echo "\n*** Testing symlink(), linkinfo(), link() and is_link() on directory ***\n";
23
24// name of the soft link created to $dirname
25$sym_linkname = "$file_path/$dirname/symlink_link_linkinfo_is_link_softlink_basic2.tmp";
26
27// name of the hard link created to $dirname
28$linkname = "$file_path/$dirname/symlink_link_linkinfo_is_link_hardlink_basic2.tmp";
29
30// testing on soft link
31echo "\n-- Testing on soft links --\n";
32// creating soft link to $dirname
33var_dump( symlink("$file_path/$dirname", $sym_linkname) ); // this works, expected true
34// gets information about soft link created to directory; expected: true
35$linkinfo = linkinfo($sym_linkname);
36var_dump( is_int($linkinfo) && $linkinfo !== -1 );
37// checks if link created is soft link; expected: true
38var_dump( is_link($sym_linkname) );
39// clear the cache
40clearstatcache();
41
42// testing on hard link
43echo "\n-- Testing on hard links --\n";
44// creating hard link to $dirname; expected: false
45var_dump( link("$file_path/$dirname", $linkname) ); // this doesn't work, expected false
46var_dump( linkinfo($linkname) ); // link doesn't exists as not created, expected false
47var_dump( is_link($linkname) ); // link doesn't exists as not created, expected false
48// clear the cache
49clearstatcache();
50
51// deleting the links
52if (PHP_OS_FAMILY === 'Windows') {
53   rmdir($sym_linkname);
54} else {
55   unlink($sym_linkname);
56}
57
58echo "Done\n";
59?>
60--CLEAN--
61<?php
62$dirname = __DIR__."/symlink_link_linkinfo_is_link_basic2";
63rmdir($dirname);
64?>
65--EXPECTF--
66*** Testing symlink(), linkinfo(), link() and is_link() : basic functionality ***
67
68*** Testing symlink(), linkinfo(), link() and is_link() on directory ***
69
70-- Testing on soft links --
71bool(true)
72bool(true)
73bool(true)
74
75-- Testing on hard links --
76
77Warning: link(): %s in %s on line %d
78bool(false)
79
80Warning: linkinfo(): No such file or directory in %s on line %d
81int(-1)
82bool(false)
83Done
84