1--TEST--
2Test dir() function : usage variations - relative valid and invalid paths
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip.. Not valid for Windows');
7}
8?>
9--FILE--
10<?php
11/*
12 * Checking the behavior of dir() function by passing directories which
13 * have valid and invalid relative path.
14 */
15
16echo "*** Testing dir() : checking with valid and invalid paths ***\n";
17
18/* create the temporary directories */
19
20$file_path = __DIR__;
21
22// directory dir_variation91 with one sub-directory sub_dir11 and sub-sub-directory sub_dir111
23$dir_path1 = $file_path."/dir_variation91";
24$sub_dir11 = $dir_path1."/sub_dir11";
25$sub_dir111 = $sub_dir11."/sub_dir111";
26
27// directory dir_variation92 with one sub-directory sub_dir21
28$dir_path2 = $file_path."/dir_variation92";
29$sub_dir21 = $dir_path2."/sub_dir21";
30
31@mkdir($dir_path1);
32@mkdir($dir_path2);
33@mkdir($sub_dir11);
34@mkdir($sub_dir111);
35@mkdir($sub_dir21);
36
37// open the directory with valid paths
38echo "\n-- With valid paths --\n";
39var_dump( dir("$dir_path1/sub_dir11/sub_dir111/..") );
40var_dump( dir("$dir_path2/sub_dir21/../../dir_variation91") );
41var_dump( dir("$dir_path2/sub_dir21/../../dir_variation91/sub_dir11/..") );
42var_dump( dir("$dir_path1/sub_dir11/sub_dir111/../../../dir_variation92/sub_dir21/..") );
43
44// open the directory with invalid path
45echo "\n-- With invalid paths --\n";
46var_dump( dir("$dir_path1/sub_dir12/sub_dir111/..") );
47var_dump( dir("$dir_path2/sub_dir21/../dir_variation91") );
48var_dump( dir("$dir_path2/sub_dir21/../../dir_variation91/sub_dir12/..") );
49var_dump( dir("$dir_path1/sub_dir11/sub_dir111/../../dir_variation92/sub_dir21/..") );
50
51echo "Done";
52?>
53--CLEAN--
54<?php
55$file_path = __DIR__;
56
57$dir_path1 = $file_path."/dir_variation91";
58$sub_dir11 = $dir_path1."/sub_dir11";
59$sub_dir111 = $sub_dir11."/sub_dir111";
60$dir_path2 = $file_path."/dir_variation92";
61$sub_dir21 = $dir_path2."/sub_dir21";
62
63rmdir($sub_dir21);
64rmdir($sub_dir111);
65rmdir($sub_dir11);
66rmdir($dir_path1);
67rmdir($dir_path2);
68?>
69--EXPECTF--
70*** Testing dir() : checking with valid and invalid paths ***
71
72-- With valid paths --
73object(Directory)#%d (2) {
74  ["path"]=>
75  string(%d) "%s/dir_variation91/sub_dir11/sub_dir111/.."
76  ["handle"]=>
77  resource(%d) of type (stream)
78}
79object(Directory)#%d (2) {
80  ["path"]=>
81  string(%d) "%s/dir_variation92/sub_dir21/../../dir_variation91"
82  ["handle"]=>
83  resource(%d) of type (stream)
84}
85object(Directory)#%d (2) {
86  ["path"]=>
87  string(%d) "%s/dir_variation92/sub_dir21/../../dir_variation91/sub_dir11/.."
88  ["handle"]=>
89  resource(%d) of type (stream)
90}
91object(Directory)#%d (2) {
92  ["path"]=>
93  string(%d) "%s/dir_variation91/sub_dir11/sub_dir111/../../../dir_variation92/sub_dir21/.."
94  ["handle"]=>
95  resource(%d) of type (stream)
96}
97
98-- With invalid paths --
99
100Warning: dir(%s/dir_variation91/sub_dir12/sub_dir111/..): Failed to open directory: %s in %s on line %d
101bool(false)
102
103Warning: dir(%s/dir_variation92/sub_dir21/../dir_variation91): Failed to open directory: %s in %s on line %d
104bool(false)
105
106Warning: dir(%s/dir_variation92/sub_dir21/../../dir_variation91/sub_dir12/..): Failed to open directory: %s in %s on line %d
107bool(false)
108
109Warning: dir(%s/dir_variation91/sub_dir11/sub_dir111/../../dir_variation92/sub_dir21/..): Failed to open directory: %s in %s on line %d
110bool(false)
111Done
112