Annotation of embedaddon/php/ext/standard/tests/file/tempnam_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test tempnam() function: usage variations - various absolute and relative paths
3: --SKIPIF--
4: <?php
5: if(substr(PHP_OS, 0, 3) == "WIN")
6: die("skip Do not run on Windows");
7: ?>
8: --FILE--
9: <?php
10: /* Prototype: string tempnam ( string $dir, string $prefix );
11: Description: Create file with unique file name.
12: */
13:
14: /* Creating unique files in various dirs by passing relative paths to $dir arg */
15:
16: echo "*** Testing tempnam() with absolute and relative paths ***\n";
17: $dir_name = dirname(__FILE__)."/tempnam_variation2";
18: mkdir($dir_name);
19: $dir_path = $dir_name."/tempnam_variation2_sub";
20: mkdir($dir_path);
21:
22: $old_dir_path = getcwd();
23: chdir(dirname(__FILE__));
24:
25: $dir_paths = array(
26: // absolute paths
27: "$dir_path",
28: "$dir_path/",
29: "$dir_path/..",
30: "$dir_path//../",
31: "$dir_path/../.././tempnam_variation2",
32: "$dir_path/..///tempnam_variation2_sub//..//../tempnam_variation2",
33: "$dir_path/BADDIR",
34:
35:
36: // relative paths
37: ".",
38: "tempname_variation2",
39: "tempname_variation2/",
40: "tempnam_variation2/tempnam_variation2_sub",
41: "tempnam_variation2//tempnam_variation2_sub",
42: "./tempnam_variation2/../tempnam_variation2/tempnam_variation2_sub",
43: "BADDIR",
44: );
45:
46: for($i = 0; $i<count($dir_paths); $i++) {
47: $j = $i+1;
48: echo "\n-- Iteration $j --\n";
49: $file_name = tempnam($dir_paths[$i], "tempnam_variation2.tmp");
50:
51: if( file_exists($file_name) ){
52:
53: echo "File name is => ";
54: print(realpath($file_name));
55: echo "\n";
56:
57: echo "File permissions are => ";
58: printf("%o", fileperms($file_name) );
59: echo "\n";
60:
61: echo "File created in => ";
62: $file_dir = dirname($file_name);
63: $dir_req = $dir_paths[$i];
64:
65: if (realpath($file_dir) == realpath(sys_get_temp_dir())) {
66: echo "temp dir\n";
67: }
68: else if ($file_dir == realpath($dir_req)) {
69: echo "directory specified\n";
70: }
71: else {
72: echo "unknown location\n";
73: }
74:
75:
76: }
77: else {
78: echo "-- File is not created --";
79: }
80:
81: unlink($file_name);
82: }
83:
84: chdir($old_dir_path);
85: rmdir($dir_path);
86: rmdir($dir_name);
87:
88: echo "\n*** Done ***\n";
89: ?>
90: --EXPECTF--
91: *** Testing tempnam() with absolute and relative paths ***
92:
93: -- Iteration 1 --
94: File name is => %s/tempnam_variation2/tempnam_variation2_sub/tempnam_variation2.tmp%s
95: File permissions are => 100600
96: File created in => directory specified
97:
98: -- Iteration 2 --
99: File name is => %s/tempnam_variation2/tempnam_variation2_sub/tempnam_variation2.tmp%s
100: File permissions are => 100600
101: File created in => directory specified
102:
103: -- Iteration 3 --
104: File name is => %s/tempnam_variation2/tempnam_variation2.tmp%s
105: File permissions are => 100600
106: File created in => directory specified
107:
108: -- Iteration 4 --
109: File name is => %s/tempnam_variation2/tempnam_variation2.tmp%s
110: File permissions are => 100600
111: File created in => directory specified
112:
113: -- Iteration 5 --
114: File name is => %s/tempnam_variation2/tempnam_variation2.tmp%s
115: File permissions are => 100600
116: File created in => directory specified
117:
118: -- Iteration 6 --
119: File name is => %s/tempnam_variation2/tempnam_variation2.tmp%s
120: File permissions are => 100600
121: File created in => directory specified
122:
123: -- Iteration 7 --
124: File name is => %s/tempnam_variation2.tmp%s
125: File permissions are => 100600
126: File created in => temp dir
127:
128: -- Iteration 8 --
129: File name is => %s/tempnam_variation2.tmp%s
130: File permissions are => 100600
131: File created in => directory specified
132:
133: -- Iteration 9 --
134: File name is => %s/tempnam_variation2.tmp%s
135: File permissions are => 100600
136: File created in => temp dir
137:
138: -- Iteration 10 --
139: File name is => %s/tempnam_variation2.tmp%s
140: File permissions are => 100600
141: File created in => temp dir
142:
143: -- Iteration 11 --
144: File name is => %s/tempnam_variation2/tempnam_variation2_sub/tempnam_variation2.tmp%s
145: File permissions are => 100600
146: File created in => directory specified
147:
148: -- Iteration 12 --
149: File name is => %s/tempnam_variation2/tempnam_variation2_sub/tempnam_variation2.tmp%s
150: File permissions are => 100600
151: File created in => directory specified
152:
153: -- Iteration 13 --
154: File name is => %s/tempnam_variation2/tempnam_variation2_sub/tempnam_variation2.tmp%s
155: File permissions are => 100600
156: File created in => directory specified
157:
158: -- Iteration 14 --
159: File name is => %s/tempnam_variation2.tmp%s
160: File permissions are => 100600
161: File created in => temp dir
162:
163: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>