Annotation of embedaddon/php/ext/standard/tests/file/file_get_contents_variation7.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test file_get_contents() function : variation - various absolute and relative paths
3: --CREDITS--
4: Dave Kelsey <d_kelsey@uk.ibm.com>
5: --FILE--
6: <?php
7: /* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
8: * Description: Read the entire file into a string
9: * Source code: ext/standard/file.c
10: * Alias to functions:
11: */
12:
13: echo "*** Testing file_get_contents() : variation ***\n";
14: $mainDir = "fileGetContentsVar7.dir";
15: $subDir = "fileGetContentsVar7Sub";
16: $absMainDir = dirname(__FILE__)."/".$mainDir;
17: mkdir($absMainDir);
18: $absSubDir = $absMainDir."/".$subDir;
19: mkdir($absSubDir);
20:
21: $old_dir_path = getcwd();
22: chdir(dirname(__FILE__));
23:
24: $allDirs = array(
25: // absolute paths
26: "$absSubDir/",
27: "$absSubDir/../".$subDir,
28: "$absSubDir//.././".$subDir,
29: "$absSubDir/../../".$mainDir."/./".$subDir,
30: "$absSubDir/..///".$subDir."//..//../".$subDir,
31: "$absSubDir/BADDIR",
32:
33: // relative paths
34: $mainDir."/".$subDir,
35: $mainDir."//".$subDir,
36: $mainDir."///".$subDir,
37: "./".$mainDir."/../".$mainDir."/".$subDir,
38: "BADDIR",
39:
40: );
41:
42: $filename = 'FileGetContentsVar7.tmp';
43: $absFile = $absSubDir.'/'.$filename;
44: $h = fopen($absFile,"w");
45: fwrite($h, "contents read");
46: fclose($h);
47:
48: for($i = 0; $i<count($allDirs); $i++) {
49: $j = $i+1;
50: $dir = $allDirs[$i];
51: echo "\n-- Iteration $j --\n";
52: var_dump(file_get_contents($dir."/".$filename));
53: }
54:
55: chdir($old_dir_path);
56: unlink($absFile);
57: rmdir($absSubDir);
58: rmdir($absMainDir);
59:
60: echo "\n*** Done ***\n";
61: ?>
62: --EXPECTF--
63: *** Testing file_get_contents() : variation ***
64:
65: -- Iteration 1 --
66: string(%d) "contents read"
67:
68: -- Iteration 2 --
69: string(%d) "contents read"
70:
71: -- Iteration 3 --
72: string(%d) "contents read"
73:
74: -- Iteration 4 --
75: string(%d) "contents read"
76:
77: -- Iteration 5 --
78:
79: Warning: file_get_contents(%sfileGetContentsVar7.dir/fileGetContentsVar7Sub/..///fileGetContentsVar7Sub//..//../fileGetContentsVar7Sub/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d
80: bool(false)
81:
82: -- Iteration 6 --
83:
84: Warning: file_get_contents(%sfileGetContentsVar7.dir/fileGetContentsVar7Sub/BADDIR/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d
85: bool(false)
86:
87: -- Iteration 7 --
88: string(%d) "contents read"
89:
90: -- Iteration 8 --
91: string(%d) "contents read"
92:
93: -- Iteration 9 --
94: string(%d) "contents read"
95:
96: -- Iteration 10 --
97: string(%d) "contents read"
98:
99: -- Iteration 11 --
100:
101: Warning: file_get_contents(BADDIR/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d
102: bool(false)
103:
104: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>