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
87--CLEAN--
88<?php
89unlink(dirname(__FILE__)."/copy_variation2.tmp");
90?>
91
92--EXPECTF--
93*** Test copy() function: destination file names containing special characters ***
94Size of the source file before copy operation => int(1500)
95
96--- Now applying copy() on source file to create copies ---
97-- Iteration 1 --
98Copy operation => bool(true)
99Existence of destination file => bool(true)
100Destination file name => %s/_copy_variation2.tmp
101Size of source file => int(1500)
102Size of destination file => int(1500)
103
104-- Iteration 2 --
105Copy operation => bool(true)
106Existence of destination file => bool(true)
107Destination file name => %s/@copy_variation2.tmp
108Size of source file => int(1500)
109Size of destination file => int(1500)
110
111-- Iteration 3 --
112Copy operation => bool(true)
113Existence of destination file => bool(true)
114Destination file name => %s/#copy_variation2.tmp
115Size of source file => int(1500)
116Size of destination file => int(1500)
117
118-- Iteration 4 --
119Copy operation => bool(true)
120Existence of destination file => bool(true)
121Destination file name => %s/+copy_variation2.tmp
122Size of source file => int(1500)
123Size of destination file => int(1500)
124
125-- Iteration 5 --
126Copy operation =>
127Warning: copy(%s): %s
128bool(false)
129Existence of destination file => bool(false)
130
131-- Iteration 6 --
132Copy operation =>
133Warning: copy(%s): %s
134bool(false)
135Existence of destination file => bool(false)
136
137-- Iteration 7 --
138Copy operation => bool(true)
139Existence of destination file => bool(true)
140Destination file name => %s/!copy_variation2.tmp
141Size of source file => int(1500)
142Size of destination file => int(1500)
143
144-- Iteration 8 --
145Copy operation => bool(true)
146Existence of destination file => bool(true)
147Destination file name => %s/&copy_variation2.tmp
148Size of source file => int(1500)
149Size of destination file => int(1500)
150
151-- Iteration 9 --
152Copy operation => bool(true)
153Existence of destination file => bool(true)
154Destination file name => %s/(copy_variation2.tmp
155Size of source file => int(1500)
156Size of destination file => int(1500)
157
158-- Iteration 10 --
159Copy operation =>
160Warning: copy(%s): %s
161bool(false)
162Existence of destination file => bool(false)
163
164-- Iteration 11 --
165Copy operation => bool(true)
166Existence of destination file => bool(true)
167Destination file name => %s/;copy_variation2.tmp
168Size of source file => int(1500)
169Size of destination file => int(1500)
170
171-- Iteration 12 --
172Copy operation => bool(true)
173Existence of destination file => bool(true)
174Destination file name => %s/=copy_variation2.tmp
175Size of source file => int(1500)
176Size of destination file => int(1500)
177
178-- Iteration 13 --
179Copy operation => bool(true)
180Existence of destination file => bool(true)
181Destination file name => %s/[copy_variation2.tmp
182Size of source file => int(1500)
183Size of destination file => int(1500)
184
185-- Iteration 14 --
186Copy operation => bool(true)
187Existence of destination file => bool(true)
188Destination file name => %s/^copy_variation2.tmp
189Size of source file => int(1500)
190Size of destination file => int(1500)
191
192-- Iteration 15 --
193Copy operation => bool(true)
194Existence of destination file => bool(true)
195Destination file name => %s/{copy_variation2.tmp
196Size of source file => int(1500)
197Size of destination file => int(1500)
198
199-- Iteration 16 --
200Copy operation =>
201Warning: copy(%s): %s
202bool(false)
203Existence of destination file => bool(false)
204
205-- Iteration 17 --
206Copy operation => bool(true)
207Existence of destination file => bool(true)
208Destination file name => %s/~copy_variation2.tmp
209Size of source file => int(1500)
210Size of destination file => int(1500)
211
212-- Iteration 18 --
213Copy operation => bool(true)
214Existence of destination file => bool(true)
215Destination file name => %s/$copy_variation2.tmp
216Size of source file => int(1500)
217Size of destination file => int(1500)
218*** Done ***
219