Annotation of embedaddon/php/ext/standard/tests/strings/basename_basic.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test basename() function : basic functionality
3: --FILE--
4: <?php
5: /* Prototype: string basename ( string $path [, string $suffix] );
6: Description: Given a string containing a path to a file,
7: this function will return the base name of the file.
8: If the filename ends in suffix this will also be cut off.
9: */
10: $file_paths = array (
11: /* simple paths */
12: array("bar"),
13: array("/foo/bar"),
14: array("foo/bar"),
15: array("/bar"),
16:
17: /* simple paths with trailing slashes */
18: array("bar/"),
19: array("/bar/"),
20: array("/foo/bar/"),
21: array("foo/bar/"),
22: array("/bar/"),
23:
24: /* paths with suffix removal */
25: array("bar.gz", ".gz"),
26: array("bar.gz", "bar.gz"),
27: array("/foo/bar.gz", ".gz"),
28: array("foo/bar.gz", ".gz"),
29: array("/bar.gz", ".gz"),
30:
31: /* paths with suffix and trailing slashes with suffix removal*/
32: array("bar.gz/", ".gz"),
33: array("/bar.gz/", ".gz"),
34: array("/foo/bar.gz/", ".gz"),
35: array("foo/bar.gz/", ".gz"),
36: array("/bar.gz/", ".gz"),
37:
38: /* paths with basename only suffix, with suffix removal*/
39: array("/.gz", ".gz"),
40: array(".gz", ".gz"),
41: array("/foo/.gz", ".gz"),
42:
43: /* paths with basename only suffix & trailing slashes, with suffix removal*/
44: array(".gz/", ".gz"),
45: array("/foo/.gz/", ".gz"),
46: array("foo/.gz/", ".gz"),
47:
48: /* paths with binary value to check if the function is binary safe*/
49: array("foo".chr(0)."bar"),
50: array("/foo".chr(0)."bar"),
51: array("/foo".chr(0)."bar/"),
52: array("foo".chr(0)."bar/"),
53: array("foo".chr(0)."bar/test"),
54: array("/foo".chr(0)."bar/bar.gz", ".gz"),
55: array("/foo".chr(0)."bar/bar.gz")
56: );
57:
58: function check_basename( $path_arrays ) {
59: $loop_counter = 1;
60: foreach ($path_arrays as $path) {
61: echo "\n--Iteration $loop_counter--\n"; $loop_counter++;
62: if( 1 == count($path) ) { // no suffix provided
63: var_dump( basename($path[0]) );
64: } else { // path as well as suffix provided,
65: var_dump( basename($path[0], $path[1]) );
66: }
67: }
68: }
69:
70: echo "*** Testing basic operations ***\n";
71: check_basename( $file_paths );
72:
73: echo "Done\n";
74: ?>
75: --EXPECTF--
76: *** Testing basic operations ***
77:
78: --Iteration 1--
79: string(3) "bar"
80:
81: --Iteration 2--
82: string(3) "bar"
83:
84: --Iteration 3--
85: string(3) "bar"
86:
87: --Iteration 4--
88: string(3) "bar"
89:
90: --Iteration 5--
91: string(3) "bar"
92:
93: --Iteration 6--
94: string(3) "bar"
95:
96: --Iteration 7--
97: string(3) "bar"
98:
99: --Iteration 8--
100: string(3) "bar"
101:
102: --Iteration 9--
103: string(3) "bar"
104:
105: --Iteration 10--
106: string(3) "bar"
107:
108: --Iteration 11--
109: string(6) "bar.gz"
110:
111: --Iteration 12--
112: string(3) "bar"
113:
114: --Iteration 13--
115: string(3) "bar"
116:
117: --Iteration 14--
118: string(3) "bar"
119:
120: --Iteration 15--
121: string(3) "bar"
122:
123: --Iteration 16--
124: string(3) "bar"
125:
126: --Iteration 17--
127: string(3) "bar"
128:
129: --Iteration 18--
130: string(3) "bar"
131:
132: --Iteration 19--
133: string(3) "bar"
134:
135: --Iteration 20--
136: string(3) ".gz"
137:
138: --Iteration 21--
139: string(3) ".gz"
140:
141: --Iteration 22--
142: string(3) ".gz"
143:
144: --Iteration 23--
145: string(3) ".gz"
146:
147: --Iteration 24--
148: string(3) ".gz"
149:
150: --Iteration 25--
151: string(3) ".gz"
152:
153: --Iteration 26--
154: string(7) "foo bar"
155:
156: --Iteration 27--
157: string(7) "foo bar"
158:
159: --Iteration 28--
160: string(7) "foo bar"
161:
162: --Iteration 29--
163: string(7) "foo bar"
164:
165: --Iteration 30--
166: string(4) "test"
167:
168: --Iteration 31--
169: string(3) "bar"
170:
171: --Iteration 32--
172: string(6) "bar.gz"
173: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>