1--TEST--
2Test fopen() function : variation: file uri, no use include path
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--SKIPIF--
6<?php
7if(substr(PHP_OS, 0, 3) != "WIN")
8  die("skip Run only on 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
18echo "*** Testing fopen() : variation ***\n";
19
20// fopen with interesting windows paths.
21$testDir = 'fopen14.tmpDir';
22$absTestDir = getcwd().'/'.$testDir;
23$file = "fopen_variation14.tmp";
24$unixifiedDir = '/'.substr(str_replace('\\','/',$absTestDir),3);
25$absFile = $absTestDir.'/'.$file;
26
27mkdir($testDir);
28
29$files = array("file://$testDir\\$file",
30               "file://$testDir/$file",
31               "file://./$testDir/$file",
32               "file://.\\$testDir\\$file",
33               "file://$absTestDir/$file",
34               "file://$absTestDir\\$file",
35               "file://$unixifiedDir/$file"
36);
37
38runtest($files);
39
40chdir($testDir);
41$files = array("file://../$testDir/$file",
42               "file://..\\$testDir\\$file",
43               "file://$absTestDir/$file",
44               "file://$absTestDir\\$file",
45               "file://$unixifiedDir/$file"
46);
47runtest($files);
48chdir("..");
49rmdir($testDir);
50
51function runtest($fileURIs) {
52   global $absFile;
53   $iteration = 0;
54   foreach($fileURIs as $fileURI) {
55      echo "--- READ: $fileURI ---\n";
56
57      $readData = "read:$iteration";
58      $writeData = "write:$iteration";
59
60      // create the file and test read
61      $h = fopen($absFile, 'w');
62      fwrite($h, $readData);
63      fclose($h);
64
65      $h = fopen($fileURI, 'r');
66      if ($h !== false) {
67         if (fread($h, 4096) != $readData) {
68            echo "contents not correct\n";
69         }
70         else {
71            echo "test passed\n";
72         }
73         fclose($h);
74      }
75      unlink($absFile);
76
77      echo "--- WRITE: $fileURI ---\n";
78      // create the file to test write
79      $h = fopen($fileURI, 'w');
80      if ($h !== false) {
81	      fwrite($h, $writeData);
82	      fclose($h);
83
84	      $h = fopen($absFile, 'r');
85	      if ($h !== false) {
86	         if (fread($h, 4096) != $writeData) {
87	            echo "contents not correct\n";
88	         }
89	         else {
90	            echo "test passed\n";
91	         }
92	         fclose($h);
93	      }
94	      unlink($absFile);
95	   }
96   }
97}
98
99
100?>
101===DONE===
102--EXPECTF--
103*** Testing fopen() : variation ***
104--- READ: file://fopen14.tmpDir\fopen_variation14.tmp ---
105
106Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir\fopen_variation14.tmp in %s on line %d
107
108Warning: fopen(file://fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
109--- WRITE: file://fopen14.tmpDir\fopen_variation14.tmp ---
110
111Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir\fopen_variation14.tmp in %s on line %d
112
113Warning: fopen(file://fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
114--- READ: file://fopen14.tmpDir/fopen_variation14.tmp ---
115
116Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
117
118Warning: fopen(file://fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
119--- WRITE: file://fopen14.tmpDir/fopen_variation14.tmp ---
120
121Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
122
123Warning: fopen(file://fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
124--- READ: file://./fopen14.tmpDir/fopen_variation14.tmp ---
125
126Warning: fopen(): remote host file access not supported, file://./fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
127
128Warning: fopen(file://./fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
129--- WRITE: file://./fopen14.tmpDir/fopen_variation14.tmp ---
130
131Warning: fopen(): remote host file access not supported, file://./fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
132
133Warning: fopen(file://./fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
134--- READ: file://.\fopen14.tmpDir\fopen_variation14.tmp ---
135
136Warning: fopen(): remote host file access not supported, file://.\fopen14.tmpDir\fopen_variation14.tmp in %s on line %d
137
138Warning: fopen(file://.\fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
139--- WRITE: file://.\fopen14.tmpDir\fopen_variation14.tmp ---
140
141Warning: fopen(): remote host file access not supported, file://.\fopen14.tmpDir\fopen_variation14.tmp in %s on line %d
142
143Warning: fopen(file://.\fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
144--- READ: file://%s/fopen14.tmpDir/fopen_variation14.tmp ---
145test passed
146--- WRITE: file://%s/fopen14.tmpDir/fopen_variation14.tmp ---
147test passed
148--- READ: file://%s/fopen14.tmpDir\fopen_variation14.tmp ---
149test passed
150--- WRITE: file://%s/fopen14.tmpDir\fopen_variation14.tmp ---
151test passed
152--- READ: file:///%s/fopen14.tmpDir/fopen_variation14.tmp ---
153test passed
154--- WRITE: file:///%s/fopen14.tmpDir/fopen_variation14.tmp ---
155test passed
156--- READ: file://../fopen14.tmpDir/fopen_variation14.tmp ---
157
158Warning: fopen(): remote host file access not supported, file://../fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
159
160Warning: fopen(file://../fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
161--- WRITE: file://../fopen14.tmpDir/fopen_variation14.tmp ---
162
163Warning: fopen(): remote host file access not supported, file://../fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
164
165Warning: fopen(file://../fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
166--- READ: file://..\fopen14.tmpDir\fopen_variation14.tmp ---
167
168Warning: fopen(): remote host file access not supported, file://..\fopen14.tmpDir\fopen_variation14.tmp in %s on line %d
169
170Warning: fopen(file://..\fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
171--- WRITE: file://..\fopen14.tmpDir\fopen_variation14.tmp ---
172
173Warning: fopen(): remote host file access not supported, file://..\fopen14.tmpDir\fopen_variation14.tmp in %s on line %d
174
175Warning: fopen(file://..\fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
176--- READ: file://%s/fopen14.tmpDir/fopen_variation14.tmp ---
177test passed
178--- WRITE: file://%s/fopen14.tmpDir/fopen_variation14.tmp ---
179test passed
180--- READ: file://%s/fopen14.tmpDir\fopen_variation14.tmp ---
181test passed
182--- WRITE: file://%s/fopen14.tmpDir\fopen_variation14.tmp ---
183test passed
184--- READ: file:///%s/fopen14.tmpDir/fopen_variation14.tmp ---
185test passed
186--- WRITE: file:///%s/fopen14.tmpDir/fopen_variation14.tmp ---
187test passed
188===DONE===
189