gzopen_variation4.phpt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. --TEST--
  2. Test gzopen() function : variation: use include path (relative directories in path)
  3. --EXTENSIONS--
  4. zlib
  5. --FILE--
  6. <?php
  7. echo "*** Testing gzopen() : usage variation ***\n";
  8. $testName = 'gzopen_variation4';
  9. require_once('reading_include_path.inc');
  10. //define the files to go into these directories, create one in dir2
  11. echo "\n--- testing include path ---\n";
  12. set_include_path($newIncludePath);
  13. $modes = array("r", "r+", "rt");
  14. foreach($modes as $mode) {
  15. test_gzopen($mode);
  16. }
  17. // remove the directory structure
  18. chdir($baseDir);
  19. rmdir($workingDir);
  20. foreach($newdirs as $newdir) {
  21. rmdir($newdir);
  22. }
  23. chdir("..");
  24. rmdir($thisTestDir);
  25. function test_gzopen($mode) {
  26. global $scriptFile, $secondFile, $firstFile, $filename;
  27. // create a file in the middle directory
  28. $h = gzopen($secondFile, "w");
  29. gzwrite($h, "This is a file in dir2");
  30. gzclose($h);
  31. echo "\n** testing with mode=$mode **\n";
  32. // should read dir2 file
  33. $h = gzopen($filename, $mode, true);
  34. if ($h) {
  35. gzpassthru($h);
  36. gzclose($h);
  37. echo "\n";
  38. }
  39. //create a file in dir1
  40. $h = gzopen($firstFile, "w");
  41. gzwrite($h, "This is a file in dir1");
  42. gzclose($h);
  43. //should now read dir1 file
  44. $h = gzopen($filename, $mode, true);
  45. if ($h) {
  46. gzpassthru($h);
  47. gzclose($h);
  48. echo "\n";
  49. }
  50. // create a file in working directory
  51. $h = gzopen($filename, "w");
  52. gzwrite($h, "This is a file in working dir");
  53. gzclose($h);
  54. //should still read dir1 file
  55. $h = gzopen($filename, $mode, true);
  56. if ($h) {
  57. gzpassthru($h);
  58. gzclose($h);
  59. echo "\n";
  60. }
  61. unlink($firstFile);
  62. unlink($secondFile);
  63. //should read the file in working dir
  64. $h = gzopen($filename, $mode, true);
  65. if ($h) {
  66. gzpassthru($h);
  67. gzclose($h);
  68. echo "\n";
  69. }
  70. // create a file in the script directory
  71. $h = gzopen($scriptFile, "w");
  72. gzwrite($h, "This is a file in script dir");
  73. gzclose($h);
  74. //should read the file in script dir
  75. $h = gzopen($filename, $mode, true);
  76. if ($h) {
  77. gzpassthru($h);
  78. gzclose($h);
  79. echo "\n";
  80. }
  81. //cleanup
  82. unlink($filename);
  83. unlink($scriptFile);
  84. }
  85. ?>
  86. --EXPECTF--
  87. *** Testing gzopen() : usage variation ***
  88. --- testing include path ---
  89. ** testing with mode=r **
  90. This is a file in dir2
  91. This is a file in dir1
  92. This is a file in dir1
  93. This is a file in working dir
  94. This is a file in script dir
  95. ** testing with mode=r+ **
  96. Warning: gzopen(): Cannot open a zlib stream for reading and writing at the same time! in %s on line %d
  97. Warning: gzopen(): Cannot open a zlib stream for reading and writing at the same time! in %s on line %d
  98. Warning: gzopen(): Cannot open a zlib stream for reading and writing at the same time! in %s on line %d
  99. Warning: gzopen(): Cannot open a zlib stream for reading and writing at the same time! in %s on line %d
  100. Warning: gzopen(): Cannot open a zlib stream for reading and writing at the same time! in %s on line %d
  101. ** testing with mode=rt **
  102. This is a file in dir2
  103. This is a file in dir1
  104. This is a file in dir1
  105. This is a file in working dir
  106. This is a file in script dir