copy_variation8.phpt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. --TEST--
  2. Test copy() function: usage variations - copying links across dirs
  3. --SKIPIF--
  4. <?php
  5. if(substr(PHP_OS, 0, 3) == "WIN")
  6. die("skip Invalid for 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. /* Trying to copy the links across dir paths given in various notations
  15. and dirs having limited access */
  16. echo "*** Testing copy() function: copying links across different directories ***\n";
  17. $file_path = dirname(__FILE__);
  18. $base_dir = $file_path."/copy_variation8";
  19. mkdir($base_dir);
  20. $sub_dir = $base_dir."/copy_variation8_sub";
  21. mkdir($sub_dir);
  22. $dirname_with_blank = $sub_dir."/copy variation6";
  23. mkdir($dirname_with_blank);
  24. $file = $file_path."/copy_variation8.tmp";
  25. fclose( fopen($file, "w") );
  26. $symlink = $file_path."/copy_variation8_symlink.tmp";
  27. $hardlink = $file_path."/copy_variation8_hardlink.tmp";
  28. symlink($file, $symlink); //creating symlink
  29. link($file, $hardlink); //creating hardlink
  30. $dests = array(
  31. $base_dir."/copy_copy_variation8.tmp",
  32. $base_dir."/copy_variation8_sub/copy_copy_variation8.tmp",
  33. "$sub_dir/copy_copy_variation8.tmp",
  34. "$sub_dir/../copy_copy_variation8.tmp",
  35. "$sub_dir/../copy_variation8_sub/copy_copy_variation8.tmp",
  36. "$sub_dir/..///../copy_copy_variation8.tmp",
  37. "$sub_dir/..///../*",
  38. "$dirname_with_blank/copy_copy_variation8.tmp"
  39. );
  40. $count = 1;
  41. foreach($dests as $dest) {
  42. echo "\n-- Iteration $count --\n";
  43. echo "- With symlink -\n";
  44. var_dump( copy($symlink, $dest) );
  45. var_dump( file_exists($dest) );
  46. var_dump( is_link($dest) ); //expected: bool(false)
  47. var_dump( is_file($dest) ); //expected: bool(true)
  48. clearstatcache();
  49. unlink("$dest");
  50. echo "- With hardlink -\n";
  51. var_dump( copy($hardlink, $dest) );
  52. var_dump( file_exists($dest) );
  53. var_dump( is_link($dest) ); //expected: bool(flase)
  54. var_dump( is_file($dest) ); //expected: bool(true)
  55. clearstatcache();
  56. unlink("$dest");
  57. $count++;
  58. }
  59. unlink($symlink);
  60. unlink($hardlink);
  61. unlink($file);
  62. rmdir($dirname_with_blank);
  63. rmdir($sub_dir);
  64. rmdir($base_dir);
  65. echo "*** Done ***\n";
  66. ?>
  67. --EXPECTF--
  68. *** Testing copy() function: copying links across different directories ***
  69. -- Iteration 1 --
  70. - With symlink -
  71. bool(true)
  72. bool(true)
  73. bool(false)
  74. bool(true)
  75. - With hardlink -
  76. bool(true)
  77. bool(true)
  78. bool(false)
  79. bool(true)
  80. -- Iteration 2 --
  81. - With symlink -
  82. bool(true)
  83. bool(true)
  84. bool(false)
  85. bool(true)
  86. - With hardlink -
  87. bool(true)
  88. bool(true)
  89. bool(false)
  90. bool(true)
  91. -- Iteration 3 --
  92. - With symlink -
  93. bool(true)
  94. bool(true)
  95. bool(false)
  96. bool(true)
  97. - With hardlink -
  98. bool(true)
  99. bool(true)
  100. bool(false)
  101. bool(true)
  102. -- Iteration 4 --
  103. - With symlink -
  104. bool(true)
  105. bool(true)
  106. bool(false)
  107. bool(true)
  108. - With hardlink -
  109. bool(true)
  110. bool(true)
  111. bool(false)
  112. bool(true)
  113. -- Iteration 5 --
  114. - With symlink -
  115. bool(true)
  116. bool(true)
  117. bool(false)
  118. bool(true)
  119. - With hardlink -
  120. bool(true)
  121. bool(true)
  122. bool(false)
  123. bool(true)
  124. -- Iteration 6 --
  125. - With symlink -
  126. bool(true)
  127. bool(true)
  128. bool(false)
  129. bool(true)
  130. - With hardlink -
  131. bool(true)
  132. bool(true)
  133. bool(false)
  134. bool(true)
  135. -- Iteration 7 --
  136. - With symlink -
  137. bool(true)
  138. bool(true)
  139. bool(false)
  140. bool(true)
  141. - With hardlink -
  142. bool(true)
  143. bool(true)
  144. bool(false)
  145. bool(true)
  146. -- Iteration 8 --
  147. - With symlink -
  148. bool(true)
  149. bool(true)
  150. bool(false)
  151. bool(true)
  152. - With hardlink -
  153. bool(true)
  154. bool(true)
  155. bool(false)
  156. bool(true)
  157. *** Done ***