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