fopen_variation19.phpt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. --TEST--
  2. Test fopen() function : variation: test opening linked files
  3. --CREDITS--
  4. Dave Kelsey <d_kelsey@uk.ibm.com>
  5. --SKIPIF--
  6. <?php
  7. if(substr(PHP_OS, 0, 3) == "WIN")
  8. die("skip Not for Windows");
  9. ?>
  10. --FILE--
  11. <?php
  12. $tmpDir = 'fopenVar19.Dir';
  13. $realFilename = __FILE__.'.real';
  14. $sortFilename = __FILE__.'.soft';
  15. $hardFilename = __FILE__.'.hard';
  16. $linkOfLink = __FILE__.'.soft2';
  17. echo "*** Testing fopen() : variation ***\n";
  18. // start the test
  19. mkdir($tmpDir);
  20. chdir($tmpDir);
  21. $h = fopen($realFilename, "w");
  22. fwrite($h, "Hello World");
  23. fclose($h);
  24. symlink($realFilename, $sortFilename);
  25. symlink($sortFilename, $linkOfLink);
  26. link($realFilename, $hardFilename);
  27. echo "*** testing reading of links ***\n";
  28. echo "soft link:";
  29. readFile2($sortFilename);
  30. echo "hard link:";
  31. readFile2($hardFilename);
  32. echo "link of link:";
  33. readFile2($linkOfLink);
  34. echo "*** test appending to links ***\n";
  35. echo "soft link:";
  36. appendFile($sortFilename);
  37. echo "hard link:";
  38. appendFile($hardFilename);
  39. echo "link of link:";
  40. appendFile($linkOfLink);
  41. echo "*** test overwriting links ***\n";
  42. echo "soft link:";
  43. writeFile($sortFilename);
  44. echo "hard link:";
  45. writeFile($hardFilename);
  46. echo "link of link:";
  47. writeFile($linkOfLink);
  48. unlink($linkOfLink);
  49. unlink($sortFilename);
  50. unlink($hardFilename);
  51. unlink($realFilename);
  52. chdir("..");
  53. rmdir($tmpDir);
  54. function readFile2($file) {
  55. $h = fopen($file, 'r');
  56. fpassthru($h);
  57. fclose($h);
  58. echo "\n";
  59. }
  60. function appendFile($file) {
  61. $h = fopen($file, 'a+');
  62. fwrite($h, ' again!');
  63. fseek($h, 0);
  64. fpassthru($h);
  65. fclose($h);
  66. echo "\n";
  67. }
  68. function writeFile($file) {
  69. $h = fopen($file, 'w');
  70. fwrite($h, 'Goodbye World');
  71. fclose($h);
  72. readFile2($file);
  73. }
  74. ?>
  75. --EXPECT--
  76. *** Testing fopen() : variation ***
  77. *** testing reading of links ***
  78. soft link:Hello World
  79. hard link:Hello World
  80. link of link:Hello World
  81. *** test appending to links ***
  82. soft link:Hello World again!
  83. hard link:Hello World again! again!
  84. link of link:Hello World again! again! again!
  85. *** test overwriting links ***
  86. soft link:Goodbye World
  87. hard link:Goodbye World
  88. link of link:Goodbye World