Annotation of embedaddon/php/ext/standard/tests/file/file_put_contents_variation7.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test file_put_contents() function : usage variation - various absolute and relative paths
3: --CREDITS--
4: Dave Kelsey <d_kelsey@uk.ibm.com>
5: --FILE--
6: <?php
7: /* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]])
8: * Description: Write/Create a file with contents data and return the number of bytes written
9: * Source code: ext/standard/file.c
10: * Alias to functions:
11: */
12:
13: echo "*** Testing file_put_contents() : usage variation ***\n";
14:
15: $mainDir = "filePutContentsVar7.dir";
16: $subDir = "filePutContentsVar7Sub";
17: $absMainDir = dirname(__FILE__)."/".$mainDir;
18: mkdir($absMainDir);
19: $absSubDir = $absMainDir."/".$subDir;
20: mkdir($absSubDir);
21:
22: $old_dir_path = getcwd();
23: chdir(dirname(__FILE__));
24:
25:
26: // Note invalid dirs in p8 result in (The system cannot find the path specified.)
27: // rather than No Such File or Directory in php.net
28: $allDirs = array(
29: // absolute paths
30: "$absSubDir/",
31: "$absSubDir/../".$subDir,
32: "$absSubDir//.././".$subDir,
33: "$absSubDir/../../".$mainDir."/./".$subDir,
34: "$absSubDir/..///".$subDir."//..//../".$subDir,
35: "$absSubDir/BADDIR",
36:
37: // relative paths
38: $mainDir."/".$subDir,
39: $mainDir."//".$subDir,
40: $mainDir."///".$subDir,
41: "./".$mainDir."/../".$mainDir."/".$subDir,
42: "BADDIR",
43:
44: );
45:
46: $filename = 'FileGetContentsVar7.tmp';
47: $absFile = $absSubDir.'/'.$filename;
48: $data = "This was the written data";
49:
50: for($i = 0; $i<count($allDirs); $i++) {
51: $j = $i+1;
52: $dir = $allDirs[$i];
53: echo "\n-- Iteration $j --\n";
54: $res = file_put_contents($dir."/".$filename, ($data + $i));
55: if ($res !== false) {
56: $in = file_get_contents($absFile);
57: if ($in == ($data + $i)) {
58: echo "Data written correctly\n";
59: }
60: else {
61: echo "Data not written correctly or to correct place\n";
62: }
63: unlink($dir."/".$filename);
64: }
65: else {
66: echo "No data written\n";
67: }
68:
69: }
70:
71: chdir($old_dir_path);
72: rmdir($absSubDir);
73: rmdir($absMainDir);
74:
75: echo "\n*** Done ***\n";
76: ?>
77: --EXPECTF--
78: *** Testing file_put_contents() : usage variation ***
79:
80: -- Iteration 1 --
81: Data written correctly
82:
83: -- Iteration 2 --
84: Data written correctly
85:
86: -- Iteration 3 --
87: Data written correctly
88:
89: -- Iteration 4 --
90: Data written correctly
91:
92: -- Iteration 5 --
93:
94: Warning: file_put_contents(%sfilePutContentsVar7.dir/filePutContentsVar7Sub/..///filePutContentsVar7Sub//..//../filePutContentsVar7Sub/FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d
95: No data written
96:
97: -- Iteration 6 --
98:
99: Warning: file_put_contents(%sfilePutContentsVar7.dir/filePutContentsVar7Sub/BADDIR/FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d
100: No data written
101:
102: -- Iteration 7 --
103: Data written correctly
104:
105: -- Iteration 8 --
106: Data written correctly
107:
108: -- Iteration 9 --
109: Data written correctly
110:
111: -- Iteration 10 --
112: Data written correctly
113:
114: -- Iteration 11 --
115:
116: Warning: file_put_contents(BADDIR/FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d
117: No data written
118:
119: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>