fopen_variation15.phpt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. /* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
  13. * Description: Open a file or a URL and return a file pointer
  14. * Source code: ext/standard/file.c
  15. * Alias to functions:
  16. */
  17. echo "*** Testing fopen() : variation ***\n";
  18. // fopen with interesting windows paths.
  19. $includePathDir = getcwd().'/fopen15.includeDir';
  20. $testDir = 'fopen15.tmpDir';
  21. $absTestDir = getcwd().'/'.$testDir;
  22. $file = "fopen_variation15.tmp";
  23. $absFile = $absTestDir.'/'.$file;
  24. mkdir($testDir);
  25. mkdir($includePathDir);
  26. set_include_path($includePathDir);
  27. $files = array("file://$testDir/$file",
  28. "file://./$testDir/$file",
  29. "file://$absTestDir/$file"
  30. );
  31. runtest($files);
  32. chdir($testDir);
  33. $files = array("file://../$testDir/$file",
  34. "file://$absTestDir/$file"
  35. );
  36. runtest($files);
  37. chdir("..");
  38. rmdir($testDir);
  39. rmdir($includePathDir);
  40. function runtest($fileURIs) {
  41. global $absFile;
  42. $iteration = 0;
  43. foreach($fileURIs as $fileURI) {
  44. echo "--- READ: $fileURI ---\n";
  45. $readData = "read:$iteration";
  46. $writeData = "write:$iteration";
  47. // create the file and test read
  48. $h = fopen($absFile, 'w');
  49. fwrite($h, $readData);
  50. fclose($h);
  51. $h = fopen($fileURI, 'r', true);
  52. if ($h !== false) {
  53. if (fread($h, 4096) != $readData) {
  54. echo "contents not correct\n";
  55. }
  56. else {
  57. echo "test passed\n";
  58. }
  59. fclose($h);
  60. }
  61. unlink($absFile);
  62. echo "--- WRITE: $fileURI ---\n";
  63. // create the file to test write
  64. $h = fopen($fileURI, 'w', true);
  65. if ($h !== false) {
  66. fwrite($h, $writeData);
  67. fclose($h);
  68. $h = fopen($absFile, 'r');
  69. if ($h !== false) {
  70. if (fread($h, 4096) != $writeData) {
  71. echo "contents not correct\n";
  72. }
  73. else {
  74. echo "test passed\n";
  75. }
  76. fclose($h);
  77. }
  78. unlink($absFile);
  79. }
  80. }
  81. }
  82. ?>
  83. ===DONE===
  84. --EXPECTF--
  85. *** Testing fopen() : variation ***
  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://./fopen15.tmpDir/fopen_variation15.tmp ---
  93. Warning: fopen(): remote host file access not supported, file://./fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
  94. Warning: fopen(file://./fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
  95. --- WRITE: file://./fopen15.tmpDir/fopen_variation15.tmp ---
  96. Warning: fopen(): remote host file access not supported, file://./fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
  97. Warning: fopen(file://./fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
  98. --- READ: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
  99. test passed
  100. --- WRITE: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
  101. test passed
  102. --- READ: file://../fopen15.tmpDir/fopen_variation15.tmp ---
  103. Warning: fopen(): remote host file access not supported, file://../fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
  104. Warning: fopen(file://../fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
  105. --- WRITE: file://../fopen15.tmpDir/fopen_variation15.tmp ---
  106. Warning: fopen(): remote host file access not supported, file://../fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
  107. Warning: fopen(file://../fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
  108. --- READ: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
  109. test passed
  110. --- WRITE: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
  111. test passed
  112. ===DONE===