fopen_variation14.phpt 4.3 KB

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