copy_variation2.phpt 6.7 KB

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