1--TEST--
2basename
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--SKIPIF--
6<?php
7if (substr(PHP_OS, 0, 3) != 'WIN') {
8    die('skip Windows only basename tests');
9}
10?>
11--FILE--
12<?php
13/*
14 * Function is implemented in ext/standard/string.c
15 */
16$file_paths = array (
17  /* simple paths */
18  array("bar"),
19  array("\\foo\\bar"),
20  array("foo\\bar"),
21  array("\\bar"),
22
23  /* simple paths with trailing slashes */
24  array("bar\\"),
25  array("\\bar\\"),
26  array("\\foo\\bar\\"),
27  array("foo\\bar\\"),
28  array("\\bar\\"),
29
30  /* paths with suffix removal */
31  array("bar.zip", ".zip"),
32  array("bar.zip", "bar.zip"),
33  array("\\foo\\bar.zip", ".zip"),
34  array("foo\\bar.zip", ".zip"),
35  array("\\bar.zip", ".zip"),
36
37  /* paths with suffix and trailing slashes with suffix removal*/
38  array("bar.zip\\", ".zip"),
39  array("\\bar.zip\\", ".zip"),
40  array("\\foo\\bar.zip\\", ".zip"),
41  array("foo\\bar.zip\\", ".zip"),
42  array("\\bar.zip\\", ".zip"),
43
44  /* paths with basename only suffix, with suffix removal*/
45  array("\\.zip", ".zip"),
46  array(".zip", ".zip"),
47  array("\\foo\\.zip", ".zip"),
48
49  /* paths with basename only suffix & trailing slashes, with suffix removal*/
50  array(".zip\\", ".zip"),
51  array("\\foo\\.zip\\", ".zip"),
52  array("foo\\.zip\\", ".zip"),
53);
54
55$file_path_variations = array (
56  /* paths with shortcut home dir char, with suffix variation */
57  array("C:\\temp\\bar"),
58  array("C:\\temp\\bar", ""),
59  array("C:\\temp\\bar", ' '),
60  array("C:\\temp\\bar.tar", ".tar"),
61  array("C:\\temp\\bar.tar", "~"),
62  array("C:\\temp\\bar.tar\\", "~"),
63  array("C:\\temp\\bar.tar\\", ""),
64  array("C:\\temp\\bar.tar", ''),
65  array("C:\\temp\\bar.tar", " "),
66
67  /* paths with numeric strings */
68  array("10.5"),
69  array("10.5", ".5"),
70  array("10.5", "10.5"),
71  array("10"),
72  array("105", "5"),
73  array("/10.5"),
74  array("10.5\\"),
75  array("10/10.zip"),
76  array("0"),
77  array('0'),
78
79  /* paths and suffix given as same */
80  array("bar.zip", "bar.zip"),
81  array("\\bar.zip", "\\bar.zip"),
82  array("\\bar.zip\\", "\\bar.zip\\"),
83  array(" ", " "),
84  array(' ', ' '),
85
86  /* path with spaces */
87  array(" "),
88  array(' '),
89
90  /* empty paths */
91  array(""),
92  array(''),
93);
94
95function check_basename( $path_arrays ) {
96   $loop_counter = 1;
97   foreach ($path_arrays as $path) {
98     echo "\n--Iteration $loop_counter--\n"; $loop_counter++;
99     if( 1 == count($path) ) { // no suffix provided
100       var_dump( basename($path[0]) );
101     } else { // path as well as suffix provided,
102       var_dump( basename($path[0], $path[1]) );
103     }
104   }
105}
106
107echo "*** Testing basic operations ***\n";
108check_basename( $file_paths );
109
110echo "\n*** Testing possible variations in path and suffix ***\n";
111check_basename( $file_path_variations );
112
113echo "Done\n";
114?>
115--EXPECT--
116*** Testing basic operations ***
117
118--Iteration 1--
119string(3) "bar"
120
121--Iteration 2--
122string(3) "bar"
123
124--Iteration 3--
125string(3) "bar"
126
127--Iteration 4--
128string(3) "bar"
129
130--Iteration 5--
131string(3) "bar"
132
133--Iteration 6--
134string(3) "bar"
135
136--Iteration 7--
137string(3) "bar"
138
139--Iteration 8--
140string(3) "bar"
141
142--Iteration 9--
143string(3) "bar"
144
145--Iteration 10--
146string(3) "bar"
147
148--Iteration 11--
149string(7) "bar.zip"
150
151--Iteration 12--
152string(3) "bar"
153
154--Iteration 13--
155string(3) "bar"
156
157--Iteration 14--
158string(3) "bar"
159
160--Iteration 15--
161string(3) "bar"
162
163--Iteration 16--
164string(3) "bar"
165
166--Iteration 17--
167string(3) "bar"
168
169--Iteration 18--
170string(3) "bar"
171
172--Iteration 19--
173string(3) "bar"
174
175--Iteration 20--
176string(4) ".zip"
177
178--Iteration 21--
179string(4) ".zip"
180
181--Iteration 22--
182string(4) ".zip"
183
184--Iteration 23--
185string(4) ".zip"
186
187--Iteration 24--
188string(4) ".zip"
189
190--Iteration 25--
191string(4) ".zip"
192
193*** Testing possible variations in path and suffix ***
194
195--Iteration 1--
196string(3) "bar"
197
198--Iteration 2--
199string(3) "bar"
200
201--Iteration 3--
202string(3) "bar"
203
204--Iteration 4--
205string(3) "bar"
206
207--Iteration 5--
208string(7) "bar.tar"
209
210--Iteration 6--
211string(7) "bar.tar"
212
213--Iteration 7--
214string(7) "bar.tar"
215
216--Iteration 8--
217string(7) "bar.tar"
218
219--Iteration 9--
220string(7) "bar.tar"
221
222--Iteration 10--
223string(4) "10.5"
224
225--Iteration 11--
226string(2) "10"
227
228--Iteration 12--
229string(4) "10.5"
230
231--Iteration 13--
232string(2) "10"
233
234--Iteration 14--
235string(2) "10"
236
237--Iteration 15--
238string(4) "10.5"
239
240--Iteration 16--
241string(4) "10.5"
242
243--Iteration 17--
244string(6) "10.zip"
245
246--Iteration 18--
247string(1) "0"
248
249--Iteration 19--
250string(1) "0"
251
252--Iteration 20--
253string(7) "bar.zip"
254
255--Iteration 21--
256string(7) "bar.zip"
257
258--Iteration 22--
259string(7) "bar.zip"
260
261--Iteration 23--
262string(1) " "
263
264--Iteration 24--
265string(1) " "
266
267--Iteration 25--
268string(1) " "
269
270--Iteration 26--
271string(1) " "
272
273--Iteration 27--
274string(0) ""
275
276--Iteration 28--
277string(0) ""
278Done
279