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