copy_variation16.phpt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. --TEST--
  2. Test copy() function: usage variations - copy data file across dirs
  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: Trying to create copy of source file
  15. into different destination dir paths given in various notations */
  16. echo "*** Testing copy() function: copying data file across directories ***\n";
  17. $base_dir = dirname(__FILE__)."/copy_variation16";
  18. mkdir($base_dir);
  19. $sub_dir = $base_dir."/copy_variation16_sub";
  20. mkdir($sub_dir);
  21. $dirname_with_blank = $sub_dir."/copy variation16";
  22. mkdir($dirname_with_blank);
  23. $src_file_name = dirname(__FILE__)."/copy_variation16.tmp";
  24. $file_handle = fopen($src_file_name, "w");
  25. fwrite($file_handle, str_repeat("Hello world, this is 2007 year ...\n", 100));
  26. fclose($file_handle);
  27. echo "- Size of source file => ";
  28. var_dump( filesize($src_file_name) );
  29. clearstatcache();
  30. $dests = array(
  31. $base_dir."/copy_copy_variation16.tmp",
  32. $base_dir."/copy_variation16_sub/copy_copy_variation16.tmp",
  33. "$sub_dir/copy_copy_variation16.tmp",
  34. "$sub_dir/../copy_copy_variation16.tmp",
  35. "$sub_dir/../copy_variation16_sub/copy_copy_variation16.tmp",
  36. "$sub_dir/..///../copy_copy_variation16.tmp",
  37. "$sub_dir/..///../*",
  38. "$dirname_with_blank/copy_copy_variation16.tmp"
  39. );
  40. echo "\n--- Now applying copy() on source file to create copies ---";
  41. $count = 1;
  42. foreach($dests as $dest) {
  43. echo "\n-- Iteration $count --\n";
  44. echo "Size of source file => ";
  45. var_dump( filesize($src_file_name) );
  46. echo "Copy operation => ";
  47. var_dump( copy($src_file_name, $dest) );
  48. echo "Existence of destination file => ";
  49. var_dump( file_exists($dest) );
  50. echo "Destination file name is => ";
  51. print($dest);
  52. echo "\n";
  53. echo "Size of destination file => ";
  54. var_dump( filesize($dest) );
  55. clearstatcache();
  56. unlink("$dest");
  57. $count++;
  58. }
  59. unlink($src_file_name);
  60. rmdir($dirname_with_blank);
  61. rmdir($sub_dir);
  62. rmdir($base_dir);
  63. echo "*** Done ***\n";
  64. ?>
  65. --EXPECTF--
  66. *** Testing copy() function: copying data file across directories ***
  67. - Size of source file => int(3500)
  68. --- Now applying copy() on source file to create copies ---
  69. -- Iteration 1 --
  70. Size of source file => int(3500)
  71. Copy operation => bool(true)
  72. Existence of destination file => bool(true)
  73. Destination file name is => %s/copy_variation16/copy_copy_variation16.tmp
  74. Size of destination file => int(3500)
  75. -- Iteration 2 --
  76. Size of source file => int(3500)
  77. Copy operation => bool(true)
  78. Existence of destination file => bool(true)
  79. Destination file name is => %s/copy_variation16/copy_variation16_sub/copy_copy_variation16.tmp
  80. Size of destination file => int(3500)
  81. -- Iteration 3 --
  82. Size of source file => int(3500)
  83. Copy operation => bool(true)
  84. Existence of destination file => bool(true)
  85. Destination file name is => %s/copy_variation16/copy_variation16_sub/copy_copy_variation16.tmp
  86. Size of destination file => int(3500)
  87. -- Iteration 4 --
  88. Size of source file => int(3500)
  89. Copy operation => bool(true)
  90. Existence of destination file => bool(true)
  91. Destination file name is => %s/copy_variation16/copy_variation16_sub/../copy_copy_variation16.tmp
  92. Size of destination file => int(3500)
  93. -- Iteration 5 --
  94. Size of source file => int(3500)
  95. Copy operation => bool(true)
  96. Existence of destination file => bool(true)
  97. Destination file name is => %s/copy_variation16/copy_variation16_sub/../copy_variation16_sub/copy_copy_variation16.tmp
  98. Size of destination file => int(3500)
  99. -- Iteration 6 --
  100. Size of source file => int(3500)
  101. Copy operation => bool(true)
  102. Existence of destination file => bool(true)
  103. Destination file name is => %s/copy_variation16/copy_variation16_sub/..///../copy_copy_variation16.tmp
  104. Size of destination file => int(3500)
  105. -- Iteration 7 --
  106. Size of source file => int(3500)
  107. Copy operation => bool(true)
  108. Existence of destination file => bool(true)
  109. Destination file name is => %s/copy_variation16/copy_variation16_sub/..///../*
  110. Size of destination file => int(3500)
  111. -- Iteration 8 --
  112. Size of source file => int(3500)
  113. Copy operation => bool(true)
  114. Existence of destination file => bool(true)
  115. Destination file name is => %s/copy_variation16/copy_variation16_sub/copy variation16/copy_copy_variation16.tmp
  116. Size of destination file => int(3500)
  117. *** Done ***