summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/copy_variation6.phpt
blob: 2e7ffd64d407aa6583ca3df591676fb10c01b647 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
--TEST--
Test copy() function: usage variations - copy empty file across dirs
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
  die("skip Do not run on Windows");
?>
--FILE--
<?php
/* Prototype: bool copy ( string $source, string $dest );
   Description: Makes a copy of the file source to dest.
     Returns TRUE on success or FALSE on failure.
*/

/* Test copy() function: Trying to create copy of source file
     into different destination dir paths given in various notations */

echo "*** Test copy() function: copying file across directories ***\n";
$base_dir = __DIR__."/copy_variation6";
mkdir($base_dir);

$sub_dir = $base_dir."/copy_variation6_sub";
mkdir($sub_dir);

$dirname_with_blank = $sub_dir."/copy variation6";
mkdir($dirname_with_blank);

$src_file_name = __DIR__."/copy_variation6.tmp";
fclose( fopen($src_file_name, "w") );

echo "Size of source file => ";
var_dump( filesize($src_file_name) );
clearstatcache();

$dests = array(
  $base_dir."/copy_copy_variation6.tmp",
  $base_dir."/copy_variation6_sub/copy_copy_variation6.tmp",
  "$sub_dir/copy_copy_variation6.tmp",
  "$sub_dir/../copy_copy_variation6.tmp",
  "$sub_dir/../copy_variation6_sub/copy_copy_variation6.tmp",
  "$sub_dir/..///../copy_copy_variation6.tmp",
  "$sub_dir/..///../*",
  "$dirname_with_blank/copy_copy_variation6.tmp"
);

echo "\n-- Now applying copy() on source file to create copies --";
$count = 1;
foreach($dests as $dest) {
  echo "\n-- Iteration $count --\n";

  echo "Copy operation => ";
  var_dump( copy($src_file_name, $dest) );

  echo "Existence of destination file => ";
  var_dump( file_exists($dest) );

  echo "Destination file name is => ";
  print($dest);
  echo "\n";

  echo "Size of source file => ";
  var_dump( filesize($src_file_name) );
  clearstatcache();

  echo "Size of destination file => ";
  var_dump( filesize($dest) );
  clearstatcache();

  unlink("$dest");

  $count++;
}

unlink($src_file_name);
rmdir($dirname_with_blank);
rmdir($sub_dir);
rmdir($base_dir);

echo "*** Done ***\n";
?>
--EXPECTF--
*** Test copy() function: copying file across directories ***
Size of source file => int(0)

-- Now applying copy() on source file to create copies --
-- Iteration 1 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name is => %s/copy_variation6/copy_copy_variation6.tmp
Size of source file => int(0)
Size of destination file => int(0)

-- Iteration 2 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name is => %s/copy_variation6/copy_variation6_sub/copy_copy_variation6.tmp
Size of source file => int(0)
Size of destination file => int(0)

-- Iteration 3 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name is => %s/copy_variation6/copy_variation6_sub/copy_copy_variation6.tmp
Size of source file => int(0)
Size of destination file => int(0)

-- Iteration 4 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name is => %s/copy_variation6/copy_variation6_sub/../copy_copy_variation6.tmp
Size of source file => int(0)
Size of destination file => int(0)

-- Iteration 5 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name is => %s/copy_variation6/copy_variation6_sub/../copy_variation6_sub/copy_copy_variation6.tmp
Size of source file => int(0)
Size of destination file => int(0)

-- Iteration 6 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name is => %s/copy_variation6/copy_variation6_sub/..///../copy_copy_variation6.tmp
Size of source file => int(0)
Size of destination file => int(0)

-- Iteration 7 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name is => %s/copy_variation6/copy_variation6_sub/..///../*
Size of source file => int(0)
Size of destination file => int(0)

-- Iteration 8 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name is => %s/copy_variation6/copy_variation6_sub/copy variation6/copy_copy_variation6.tmp
Size of source file => int(0)
Size of destination file => int(0)
*** Done ***