1--TEST--
2Test copy() function: usage variations - copying links across dirs
3--SKIPIF--
4<?php
5if(substr(PHP_OS, 0, 3) == "WIN")
6  die("skip Invalid for Windows");
7?>
8--FILE--
9<?php
10/* Trying to copy the links across dir paths given in various notations
11     and dirs having limited access */
12
13echo "*** Testing copy() function: copying links across different directories ***\n";
14
15$file_path = __DIR__;
16
17$base_dir = $file_path."/copy_variation8";
18mkdir($base_dir);
19$sub_dir = $base_dir."/copy_variation8_sub";
20mkdir($sub_dir);
21$dirname_with_blank = $sub_dir."/copy variation6";
22mkdir($dirname_with_blank);
23
24$file = $file_path."/copy_variation8.tmp";
25fclose( fopen($file, "w") );
26
27$symlink = $file_path."/copy_variation8_symlink.tmp";
28$hardlink = $file_path."/copy_variation8_hardlink.tmp";
29
30symlink($file, $symlink);  //creating symlink
31link($file, $hardlink);  //creating hardlink
32
33$dests = array(
34  $base_dir."/copy_copy_variation8.tmp",
35  $base_dir."/copy_variation8_sub/copy_copy_variation8.tmp",
36  "$sub_dir/copy_copy_variation8.tmp",
37  "$sub_dir/../copy_copy_variation8.tmp",
38  "$sub_dir/../copy_variation8_sub/copy_copy_variation8.tmp",
39  "$sub_dir/..///../copy_copy_variation8.tmp",
40  "$sub_dir///../*",
41  "$dirname_with_blank/copy_copy_variation8.tmp"
42);
43
44$count = 1;
45foreach($dests as $dest) {
46  echo "\n-- Iteration $count --\n";
47  echo "- With symlink -\n";
48  var_dump( copy($symlink, $dest) );
49  var_dump( file_exists($dest) );
50  var_dump( is_link($dest) ); //expected: bool(false)
51  var_dump( is_file($dest) );  //expected: bool(true)
52  clearstatcache();
53  unlink("$dest");
54  echo "- With hardlink -\n";
55  var_dump( copy($hardlink, $dest) );
56  var_dump( file_exists($dest) );
57  var_dump( is_link($dest) );  //expected: bool(flase)
58  var_dump( is_file($dest) );  //expected: bool(true)
59  clearstatcache();
60  unlink("$dest");
61  $count++;
62}
63
64unlink($symlink);
65unlink($hardlink);
66unlink($file);
67rmdir($dirname_with_blank);
68rmdir($sub_dir);
69rmdir($base_dir);
70
71echo "*** Done ***\n";
72?>
73--EXPECT--
74*** Testing copy() function: copying links across different directories ***
75
76-- Iteration 1 --
77- With symlink -
78bool(true)
79bool(true)
80bool(false)
81bool(true)
82- With hardlink -
83bool(true)
84bool(true)
85bool(false)
86bool(true)
87
88-- Iteration 2 --
89- With symlink -
90bool(true)
91bool(true)
92bool(false)
93bool(true)
94- With hardlink -
95bool(true)
96bool(true)
97bool(false)
98bool(true)
99
100-- Iteration 3 --
101- With symlink -
102bool(true)
103bool(true)
104bool(false)
105bool(true)
106- With hardlink -
107bool(true)
108bool(true)
109bool(false)
110bool(true)
111
112-- Iteration 4 --
113- With symlink -
114bool(true)
115bool(true)
116bool(false)
117bool(true)
118- With hardlink -
119bool(true)
120bool(true)
121bool(false)
122bool(true)
123
124-- Iteration 5 --
125- With symlink -
126bool(true)
127bool(true)
128bool(false)
129bool(true)
130- With hardlink -
131bool(true)
132bool(true)
133bool(false)
134bool(true)
135
136-- Iteration 6 --
137- With symlink -
138bool(true)
139bool(true)
140bool(false)
141bool(true)
142- With hardlink -
143bool(true)
144bool(true)
145bool(false)
146bool(true)
147
148-- Iteration 7 --
149- With symlink -
150bool(true)
151bool(true)
152bool(false)
153bool(true)
154- With hardlink -
155bool(true)
156bool(true)
157bool(false)
158bool(true)
159
160-- Iteration 8 --
161- With symlink -
162bool(true)
163bool(true)
164bool(false)
165bool(true)
166- With hardlink -
167bool(true)
168bool(true)
169bool(false)
170bool(true)
171*** Done ***
172