Annotation of embedaddon/php/ext/standard/tests/file/fopen_variation5.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test fopen() function : variation: use include path and stream context (absolute directories in path)
3: --CREDITS--
4: Dave Kelsey <d_kelsey@uk.ibm.com>
5: --FILE--
6: <?php
7: /* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
8: * Description: Open a file or a URL and return a file pointer
9: * Source code: ext/standard/file.c
10: * Alias to functions:
11: */
12:
13:
14:
15: //create the include directory structure
16: $thisTestDir = basename(__FILE__, ".php") . ".dir";
17: mkdir($thisTestDir);
18: chdir($thisTestDir);
19:
20: $workingDir = "workdir";
21: $filename = basename(__FILE__, ".php") . ".tmp";
22: $scriptDir = dirname(__FILE__);
23: $baseDir = getcwd();
24: $secondFile = $baseDir."/dir2/".$filename;
25: $firstFile = "../dir1/".$filename;
26: $scriptFile = $scriptDir.'/'.$filename;
27:
28: $newdirs = array("dir1", "dir2", "dir3");
29: $pathSep = ":";
30: $newIncludePath = "";
31: if(substr(PHP_OS, 0, 3) == 'WIN' ) {
32: $pathSep = ";";
33: }
34: foreach($newdirs as $newdir) {
35: mkdir($newdir);
36: $newIncludePath .= $baseDir.'/'.$newdir.$pathSep;
37: }
38: mkdir($workingDir);
39: chdir($workingDir);
40:
41: //define the files to go into these directories, create one in dir2
42: echo "\n--- testing include path ---\n";
43: set_include_path($newIncludePath);
44: $modes = array("r", "r+", "rt");
45: foreach($modes as $mode) {
46: test_fopen($mode);
47: }
48: restore_include_path();
49:
50: // remove the directory structure
51: chdir($baseDir);
52: rmdir($workingDir);
53: foreach($newdirs as $newdir) {
54: rmdir($newdir);
55: }
56:
57: chdir("..");
58: rmdir($thisTestDir);
59:
60:
61: function test_fopen($mode) {
62: global $scriptFile, $secondFile, $firstFile, $filename;
63:
64: // create a file in the middle directory
65: $h = fopen($secondFile, "w");
66: fwrite($h, (binary) "in dir2");
67: fclose($h);
68:
69: echo "\n** testing with mode=$mode **\n";
70: // should read dir2 file
71: $h = fopen($filename, $mode, true);
72: fpassthru($h);
73: fclose($h);
74: echo "\n";
75:
76: //create a file in dir1
77: $h = fopen($firstFile, "w");
78: fwrite($h, (binary) "in dir1");
79: fclose($h);
80:
81: //should now read dir1 file
82: $h = fopen($filename, $mode, true);
83: fpassthru($h);
84: fclose($h);
85: echo "\n";
86:
87: // create a file in working directory
88: $h = fopen($filename, "w");
89: fwrite($h, (binary) "in working dir");
90: fclose($h);
91:
92: //should still read dir1 file
93: $h = fopen($filename, $mode, true);
94: fpassthru($h);
95: fclose($h);
96: echo "\n";
97:
98: unlink($firstFile);
99: unlink($secondFile);
100:
101: //should read the file in working dir
102: $h = fopen($filename, $mode, true);
103: fpassthru($h);
104: fclose($h);
105: echo "\n";
106:
107: // create a file in the script directory
108: $h = fopen($scriptFile, "w");
109: fwrite($h, (binary) "in script dir");
110: fclose($h);
111:
112: //should read the file in script dir
113: $h = fopen($filename, $mode, true);
114: fpassthru($h);
115: fclose($h);
116: echo "\n";
117:
118: //cleanup
119: unlink($filename);
120: unlink($scriptFile);
121:
122: }
123:
124: ?>
125: ===DONE===
126: --EXPECTF--
127:
128: --- testing include path ---
129:
130: ** testing with mode=r **
131: in dir2
132: in dir1
133: in dir1
134: in working dir
135: in script dir
136:
137: ** testing with mode=r+ **
138: in dir2
139: in dir1
140: in dir1
141: in working dir
142: in script dir
143:
144: ** testing with mode=rt **
145: in dir2
146: in dir1
147: in dir1
148: in working dir
149: in script dir
150: ===DONE===
151:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>