1--TEST--
2Test symlink(), linkinfo(), link() and is_link() functions: basic functionality - link to files
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
14// temp dir created in present working directory
15$dirname = "symlink_link_linkinfo_is_link_basic1";
16mkdir("$file_path/$dirname");  // creating temp dir
17
18/* Creating soft/hard link to $filename created in temp directory $dirname
19   and checking linkinfo() and is_link() on the link created */
20
21echo "*** Testing symlink(), linkinfo(), link() and is_link() : basic functionality ***\n";
22
23// creating file in $dirname, links are created to the this file
24$filename = "$file_path/$dirname/symlink_link_linkinfo_is_link_basic1.tmp";
25$filename = fopen($filename, "w");
26fclose($filename);
27
28// name of the soft link created to $filename
29$sym_linkname = "$file_path/$dirname/symlink_link_linkinfo_is_link_softlink_basic1.tmp";
30
31// name of the hard link created to $filename
32$linkname = "$file_path/$dirname/symlink_link_linkinfo_is_link_hardlink_basic1.tmp";
33
34// filename stored in array with single and double slash notation in its path
35$files = array (
36  "$file_path/$dirname/symlink_link_linkinfo_is_link_basic1.tmp",
37  "$file_path//$dirname//symlink_link_linkinfo_is_link_basic1.tmp"
38);
39
40$counter = 1;
41/* create soft/hard link to  the file
42   and check linkinfo() and is_link() on the link created */
43foreach($files as $file) {
44  echo "\n-- Iteration $counter --\n";
45  echo "-- Testing on soft links --\n";
46  // create soft link
47  var_dump( symlink($file, $sym_linkname) );
48  // checking information of link with linkinfo()
49  $linkinfo = linkinfo($sym_linkname);
50  var_dump( is_int($linkinfo) && $linkinfo !== -1 );
51  // checking if given file is soft link
52  var_dump( is_link($sym_linkname) );
53  // clear the cache
54  clearstatcache();
55
56  // testing on hard link
57  echo "-- Testing on hard links --\n";
58  // creating hard link
59  var_dump( link($file, $linkname) );
60  // checking information of link with linkinfo()
61  $linkinfo = linkinfo($sym_linkname);
62  var_dump( is_int($linkinfo) && $linkinfo !== -1 );
63  // checking if given link is soft link; expected: false
64  var_dump( is_link($linkname) );
65  // clear the cache
66  clearstatcache();
67
68  // deleting the links
69  unlink($sym_linkname);
70  unlink($linkname);
71  $counter++;
72}
73
74echo "Done\n";
75?>
76--CLEAN--
77<?php
78$dirname = __DIR__."/symlink_link_linkinfo_is_link_basic1";
79unlink("$dirname/symlink_link_linkinfo_is_link_basic1.tmp");
80rmdir($dirname);
81?>
82--EXPECT--
83*** Testing symlink(), linkinfo(), link() and is_link() : basic functionality ***
84
85-- Iteration 1 --
86-- Testing on soft links --
87bool(true)
88bool(true)
89bool(true)
90-- Testing on hard links --
91bool(true)
92bool(true)
93bool(false)
94
95-- Iteration 2 --
96-- Testing on soft links --
97bool(true)
98bool(true)
99bool(true)
100-- Testing on hard links --
101bool(true)
102bool(true)
103bool(false)
104Done
105