1--TEST--
2Test scandir() function : usage variations - different relative paths
3--FILE--
4<?php
5/* Prototype  : array scandir(string $dir [, int $sorting_order [, resource $context]])
6 * Description: List files & directories inside the specified path
7 * Source code: ext/standard/dir.c
8 */
9
10/*
11 * Test scandir() with relative paths as $dir argument
12 */
13
14echo "*** Testing scandir() : usage variations ***\n";
15
16// include for create_files/delete_files functions
17include (dirname(__FILE__) . '/../file/file.inc');
18
19$base_dir_path = dirname(__FILE__);
20
21$level_one_dir_path = "$base_dir_path/level_one";
22$level_two_dir_path = "$level_one_dir_path/level_two";
23
24// create directories and files
25mkdir($level_one_dir_path);
26create_files($level_one_dir_path, 2, 'numeric', 0755, 1, 'w', 'level_one', 1);
27mkdir($level_two_dir_path);
28create_files($level_two_dir_path, 2, 'numeric', 0755, 1, 'w', 'level_two', 1);
29
30echo "\n-- \$path = './level_one': --\n";
31var_dump(chdir($base_dir_path));
32var_dump(scandir('./level_one'));
33
34echo "\n-- \$path = 'level_one/level_two': --\n";
35var_dump(chdir($base_dir_path));
36var_dump(scandir('level_one/level_two'));
37
38echo "\n-- \$path = '..': --\n";
39var_dump(chdir($level_two_dir_path));
40var_dump(scandir('..'));
41
42echo "\n-- \$path = 'level_two', '.': --\n";
43var_dump(chdir($level_two_dir_path));
44var_dump(scandir('.'));
45
46echo "\n-- \$path = '../': --\n";
47var_dump(chdir($level_two_dir_path));
48var_dump(scandir('../'));
49
50echo "\n-- \$path = './': --\n";
51var_dump(chdir($level_two_dir_path));
52var_dump(scandir('./'));
53
54echo "\n-- \$path = '../../'level_one': --\n";
55var_dump(chdir($level_two_dir_path));
56var_dump(scandir('../../level_one'));
57
58@delete_files($level_one_dir_path, 2, 'level_one');
59@delete_files($level_two_dir_path, 2, 'level_two');
60?>
61===DONE===
62--CLEAN--
63<?php
64$dir_path = dirname(__FILE__);
65rmdir("$dir_path/level_one/level_two");
66rmdir("$dir_path/level_one");
67?>
68--EXPECTF--
69*** Testing scandir() : usage variations ***
70
71-- $path = './level_one': --
72bool(true)
73array(5) {
74  [0]=>
75  string(1) "."
76  [1]=>
77  string(2) ".."
78  [2]=>
79  string(14) "level_one1.tmp"
80  [3]=>
81  string(14) "level_one2.tmp"
82  [4]=>
83  string(9) "level_two"
84}
85
86-- $path = 'level_one/level_two': --
87bool(true)
88array(4) {
89  [0]=>
90  string(1) "."
91  [1]=>
92  string(2) ".."
93  [2]=>
94  string(14) "level_two1.tmp"
95  [3]=>
96  string(14) "level_two2.tmp"
97}
98
99-- $path = '..': --
100bool(true)
101array(5) {
102  [0]=>
103  string(1) "."
104  [1]=>
105  string(2) ".."
106  [2]=>
107  string(14) "level_one1.tmp"
108  [3]=>
109  string(14) "level_one2.tmp"
110  [4]=>
111  string(9) "level_two"
112}
113
114-- $path = 'level_two', '.': --
115bool(true)
116array(4) {
117  [0]=>
118  string(1) "."
119  [1]=>
120  string(2) ".."
121  [2]=>
122  string(14) "level_two1.tmp"
123  [3]=>
124  string(14) "level_two2.tmp"
125}
126
127-- $path = '../': --
128bool(true)
129array(5) {
130  [0]=>
131  string(1) "."
132  [1]=>
133  string(2) ".."
134  [2]=>
135  string(14) "level_one1.tmp"
136  [3]=>
137  string(14) "level_one2.tmp"
138  [4]=>
139  string(9) "level_two"
140}
141
142-- $path = './': --
143bool(true)
144array(4) {
145  [0]=>
146  string(1) "."
147  [1]=>
148  string(2) ".."
149  [2]=>
150  string(14) "level_two1.tmp"
151  [3]=>
152  string(14) "level_two2.tmp"
153}
154
155-- $path = '../../'level_one': --
156bool(true)
157array(5) {
158  [0]=>
159  string(1) "."
160  [1]=>
161  string(2) ".."
162  [2]=>
163  string(14) "level_one1.tmp"
164  [3]=>
165  string(14) "level_one2.tmp"
166  [4]=>
167  string(9) "level_two"
168}
169===DONE===
170