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