fopen_variation15.phpt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. --TEST--
  2. Test fopen() function : variation: file uri, use include path = true
  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. echo "*** Testing fopen() : variation ***\n";
  13. // fopen with interesting windows paths.
  14. $includePathDir = getcwd().'/fopen15.includeDir';
  15. $testDir = 'fopen15.tmpDir';
  16. $absTestDir = getcwd().'/'.$testDir;
  17. $file = "fopen_variation15.tmp";
  18. $absFile = $absTestDir.'/'.$file;
  19. mkdir($testDir);
  20. mkdir($includePathDir);
  21. set_include_path($includePathDir);
  22. $files = array("file://$testDir/$file",
  23. "file://./$testDir/$file",
  24. "file://$absTestDir/$file"
  25. );
  26. runtest($files);
  27. chdir($testDir);
  28. $files = array("file://../$testDir/$file",
  29. "file://$absTestDir/$file"
  30. );
  31. runtest($files);
  32. chdir("..");
  33. rmdir($testDir);
  34. rmdir($includePathDir);
  35. function runtest($fileURIs) {
  36. global $absFile;
  37. $iteration = 0;
  38. foreach($fileURIs as $fileURI) {
  39. echo "--- READ: $fileURI ---\n";
  40. $readData = "read:$iteration";
  41. $writeData = "write:$iteration";
  42. // create the file and test read
  43. $h = fopen($absFile, 'w');
  44. fwrite($h, $readData);
  45. fclose($h);
  46. $h = fopen($fileURI, 'r', true);
  47. if ($h !== false) {
  48. if (fread($h, 4096) != $readData) {
  49. echo "contents not correct\n";
  50. }
  51. else {
  52. echo "test passed\n";
  53. }
  54. fclose($h);
  55. }
  56. unlink($absFile);
  57. echo "--- WRITE: $fileURI ---\n";
  58. // create the file to test write
  59. $h = fopen($fileURI, 'w', true);
  60. if ($h !== false) {
  61. fwrite($h, $writeData);
  62. fclose($h);
  63. $h = fopen($absFile, 'r');
  64. if ($h !== false) {
  65. if (fread($h, 4096) != $writeData) {
  66. echo "contents not correct\n";
  67. }
  68. else {
  69. echo "test passed\n";
  70. }
  71. fclose($h);
  72. }
  73. unlink($absFile);
  74. }
  75. }
  76. }
  77. ?>
  78. --EXPECTF--
  79. *** Testing fopen() : variation ***
  80. --- READ: file://fopen15.tmpDir/fopen_variation15.tmp ---
  81. Warning: fopen(): Remote host file access not supported, file://fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
  82. Warning: fopen(file://fopen15.tmpDir/fopen_variation15.tmp): Failed to open stream: no suitable wrapper could be found in %s on line %d
  83. --- WRITE: file://fopen15.tmpDir/fopen_variation15.tmp ---
  84. Warning: fopen(): Remote host file access not supported, file://fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
  85. Warning: fopen(file://fopen15.tmpDir/fopen_variation15.tmp): Failed to open stream: no suitable wrapper could be found in %s on line %d
  86. --- READ: file://./fopen15.tmpDir/fopen_variation15.tmp ---
  87. Warning: fopen(): Remote host file access not supported, file://./fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
  88. Warning: fopen(file://./fopen15.tmpDir/fopen_variation15.tmp): Failed to open stream: no suitable wrapper could be found in %s on line %d
  89. --- WRITE: file://./fopen15.tmpDir/fopen_variation15.tmp ---
  90. Warning: fopen(): Remote host file access not supported, file://./fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
  91. Warning: fopen(file://./fopen15.tmpDir/fopen_variation15.tmp): Failed to open stream: no suitable wrapper could be found in %s on line %d
  92. --- READ: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
  93. test passed
  94. --- WRITE: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
  95. test passed
  96. --- READ: file://../fopen15.tmpDir/fopen_variation15.tmp ---
  97. Warning: fopen(): Remote host file access not supported, file://../fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
  98. Warning: fopen(file://../fopen15.tmpDir/fopen_variation15.tmp): Failed to open stream: no suitable wrapper could be found in %s on line %d
  99. --- WRITE: file://../fopen15.tmpDir/fopen_variation15.tmp ---
  100. Warning: fopen(): Remote host file access not supported, file://../fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
  101. Warning: fopen(file://../fopen15.tmpDir/fopen_variation15.tmp): Failed to open stream: no suitable wrapper could be found in %s on line %d
  102. --- READ: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
  103. test passed
  104. --- WRITE: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
  105. test passed