1--TEST--
2Test copy() function: usage variations - destination file names(special chars)
3--SKIPIF--
4<?php
5if(substr(PHP_OS, 0, 3) != "WIN")
6  die("skip only run on Windows");
7?>
8--FILE--
9<?php
10/* Prototype: bool copy ( string $source, string $dest );
11   Description: Makes a copy of the file source to dest.
12     Returns TRUE on success or FALSE on failure.
13*/
14
15/* Test copy() function: In creation of destination file names containing special characters
16     and checking the existence and size of destination files
17*/
18
19echo "*** Test copy() function: destination file names containing special characters ***\n";
20$file_path = dirname(__FILE__);
21$src_file_name = $file_path."/copy_variation2.tmp";
22$file_handle = fopen($src_file_name, "w");
23fwrite( $file_handle, str_repeat(b"Hello2World...\n", 100) );
24fclose($file_handle);
25
26/* array of destination file names */
27$dest_files = array(
28
29  /* File names containing special(non-alpha numeric) characters */
30  "_copy_variation2.tmp",
31  "@copy_variation2.tmp",
32  "#copy_variation2.tmp",
33  "+copy_variation2.tmp",
34  "?copy_variation2.tmp",
35  ">copy_variation2.tmp",
36  "!copy_variation2.tmp",
37  "&copy_variation2.tmp",
38  "(copy_variation2.tmp",
39  ":copy_variation2.tmp",
40  ";copy_variation2.tmp",
41  "=copy_variation2.tmp",
42  "[copy_variation2.tmp",
43  "^copy_variation2.tmp",
44  "{copy_variation2.tmp",
45  "|copy_variation2.tmp",
46  "~copy_variation2.tmp",
47  "\$copy_variation2.tmp"
48);
49
50echo "Size of the source file before copy operation => ";
51var_dump( filesize("$src_file_name") );
52clearstatcache();
53
54echo "\n--- Now applying copy() on source file to create copies ---";
55$count = 1;
56foreach($dest_files as $dest_file) {
57  echo "\n-- Iteration $count --\n";
58  $dest_file_name = $file_path."/$dest_file";
59
60  echo "Copy operation => ";
61  var_dump( copy($src_file_name, $dest_file_name) );
62
63  echo "Existence of destination file => ";
64  var_dump( file_exists($dest_file_name) );
65
66  if( file_exists($dest_file_name) ) {
67    echo "Destination file name => ";
68    print($dest_file_name);
69    echo "\n";
70
71    echo "Size of source file => ";
72    var_dump( filesize($src_file_name) );
73    clearstatcache();
74
75    echo "Size of destination file => ";
76    var_dump( filesize($dest_file_name) );
77    clearstatcache();
78
79    unlink($dest_file_name);
80  }
81  $count++;
82}
83
84echo "*** Done ***\n";
85?>
86--CLEAN--
87<?php
88unlink(dirname(__FILE__)."/copy_variation2.tmp");
89?>
90--EXPECTF--
91*** Test copy() function: destination file names containing special characters ***
92Size of the source file before copy operation => int(1500)
93
94--- Now applying copy() on source file to create copies ---
95-- Iteration 1 --
96Copy operation => bool(true)
97Existence of destination file => bool(true)
98Destination file name => %s/_copy_variation2.tmp
99Size of source file => int(1500)
100Size of destination file => int(1500)
101
102-- Iteration 2 --
103Copy operation => bool(true)
104Existence of destination file => bool(true)
105Destination file name => %s/@copy_variation2.tmp
106Size of source file => int(1500)
107Size of destination file => int(1500)
108
109-- Iteration 3 --
110Copy operation => bool(true)
111Existence of destination file => bool(true)
112Destination file name => %s/#copy_variation2.tmp
113Size of source file => int(1500)
114Size of destination file => int(1500)
115
116-- Iteration 4 --
117Copy operation => bool(true)
118Existence of destination file => bool(true)
119Destination file name => %s/+copy_variation2.tmp
120Size of source file => int(1500)
121Size of destination file => int(1500)
122
123-- Iteration 5 --
124Copy operation =>
125Warning: copy(%s): %s
126bool(false)
127Existence of destination file => bool(false)
128
129-- Iteration 6 --
130Copy operation =>
131Warning: copy(%s): %s
132bool(false)
133Existence of destination file => bool(false)
134
135-- Iteration 7 --
136Copy operation => bool(true)
137Existence of destination file => bool(true)
138Destination file name => %s/!copy_variation2.tmp
139Size of source file => int(1500)
140Size of destination file => int(1500)
141
142-- Iteration 8 --
143Copy operation => bool(true)
144Existence of destination file => bool(true)
145Destination file name => %s/&copy_variation2.tmp
146Size of source file => int(1500)
147Size of destination file => int(1500)
148
149-- Iteration 9 --
150Copy operation => bool(true)
151Existence of destination file => bool(true)
152Destination file name => %s/(copy_variation2.tmp
153Size of source file => int(1500)
154Size of destination file => int(1500)
155
156-- Iteration 10 --
157Copy operation =>
158Warning: copy(%s): %s
159bool(false)
160Existence of destination file => bool(false)
161
162-- Iteration 11 --
163Copy operation => bool(true)
164Existence of destination file => bool(true)
165Destination file name => %s/;copy_variation2.tmp
166Size of source file => int(1500)
167Size of destination file => int(1500)
168
169-- Iteration 12 --
170Copy operation => bool(true)
171Existence of destination file => bool(true)
172Destination file name => %s/=copy_variation2.tmp
173Size of source file => int(1500)
174Size of destination file => int(1500)
175
176-- Iteration 13 --
177Copy operation => bool(true)
178Existence of destination file => bool(true)
179Destination file name => %s/[copy_variation2.tmp
180Size of source file => int(1500)
181Size of destination file => int(1500)
182
183-- Iteration 14 --
184Copy operation => bool(true)
185Existence of destination file => bool(true)
186Destination file name => %s/^copy_variation2.tmp
187Size of source file => int(1500)
188Size of destination file => int(1500)
189
190-- Iteration 15 --
191Copy operation => bool(true)
192Existence of destination file => bool(true)
193Destination file name => %s/{copy_variation2.tmp
194Size of source file => int(1500)
195Size of destination file => int(1500)
196
197-- Iteration 16 --
198Copy operation =>
199Warning: copy(%s): %s
200bool(false)
201Existence of destination file => bool(false)
202
203-- Iteration 17 --
204Copy operation => bool(true)
205Existence of destination file => bool(true)
206Destination file name => %s/~copy_variation2.tmp
207Size of source file => int(1500)
208Size of destination file => int(1500)
209
210-- Iteration 18 --
211Copy operation => bool(true)
212Existence of destination file => bool(true)
213Destination file name => %s/$copy_variation2.tmp
214Size of source file => int(1500)
215Size of destination file => int(1500)
216*** Done ***
217