fopen_variation5.phpt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. --TEST--
  2. Test fopen() function : variation: use include path and stream context (absolute directories in path)
  3. --CREDITS--
  4. Dave Kelsey <d_kelsey@uk.ibm.com>
  5. --FILE--
  6. <?php
  7. //create the include directory structure
  8. $thisTestDir = basename(__FILE__, ".php") . ".dir";
  9. mkdir($thisTestDir);
  10. chdir($thisTestDir);
  11. $workingDir = "workdir";
  12. $filename = basename(__FILE__, ".php") . ".tmp";
  13. $scriptDir = __DIR__;
  14. $baseDir = getcwd();
  15. $secondFile = $baseDir."/dir2/".$filename;
  16. $firstFile = "../dir1/".$filename;
  17. $scriptFile = $scriptDir.'/'.$filename;
  18. $newdirs = array("dir1", "dir2", "dir3");
  19. $pathSep = ":";
  20. $newIncludePath = "";
  21. if(substr(PHP_OS, 0, 3) == 'WIN' ) {
  22. $pathSep = ";";
  23. }
  24. foreach($newdirs as $newdir) {
  25. mkdir($newdir);
  26. $newIncludePath .= $baseDir.'/'.$newdir.$pathSep;
  27. }
  28. mkdir($workingDir);
  29. chdir($workingDir);
  30. //define the files to go into these directories, create one in dir2
  31. echo "\n--- testing include path ---\n";
  32. set_include_path($newIncludePath);
  33. $modes = array("r", "r+", "rt");
  34. foreach($modes as $mode) {
  35. test_fopen($mode);
  36. }
  37. // remove the directory structure
  38. chdir($baseDir);
  39. rmdir($workingDir);
  40. foreach($newdirs as $newdir) {
  41. rmdir($newdir);
  42. }
  43. chdir("..");
  44. rmdir($thisTestDir);
  45. function test_fopen($mode) {
  46. global $scriptFile, $secondFile, $firstFile, $filename;
  47. // create a file in the middle directory
  48. $h = fopen($secondFile, "w");
  49. fwrite($h, "in dir2");
  50. fclose($h);
  51. echo "\n** testing with mode=$mode **\n";
  52. // should read dir2 file
  53. $h = fopen($filename, $mode, true);
  54. fpassthru($h);
  55. fclose($h);
  56. echo "\n";
  57. //create a file in dir1
  58. $h = fopen($firstFile, "w");
  59. fwrite($h, "in dir1");
  60. fclose($h);
  61. //should now read dir1 file
  62. $h = fopen($filename, $mode, true);
  63. fpassthru($h);
  64. fclose($h);
  65. echo "\n";
  66. // create a file in working directory
  67. $h = fopen($filename, "w");
  68. fwrite($h, "in working dir");
  69. fclose($h);
  70. //should still read dir1 file
  71. $h = fopen($filename, $mode, true);
  72. fpassthru($h);
  73. fclose($h);
  74. echo "\n";
  75. unlink($firstFile);
  76. unlink($secondFile);
  77. //should read the file in working dir
  78. $h = fopen($filename, $mode, true);
  79. fpassthru($h);
  80. fclose($h);
  81. echo "\n";
  82. // create a file in the script directory
  83. $h = fopen($scriptFile, "w");
  84. fwrite($h, "in script dir");
  85. fclose($h);
  86. //should read the file in script dir
  87. $h = fopen($filename, $mode, true);
  88. fpassthru($h);
  89. fclose($h);
  90. echo "\n";
  91. //cleanup
  92. unlink($filename);
  93. unlink($scriptFile);
  94. }
  95. ?>
  96. --EXPECT--
  97. --- testing include path ---
  98. ** testing with mode=r **
  99. in dir2
  100. in dir1
  101. in dir1
  102. in working dir
  103. in script dir
  104. ** testing with mode=r+ **
  105. in dir2
  106. in dir1
  107. in dir1
  108. in working dir
  109. in script dir
  110. ** testing with mode=rt **
  111. in dir2
  112. in dir1
  113. in dir1
  114. in working dir
  115. in script dir