1--TEST--
2Test realpath() with relative paths
3--FILE--
4<?php
5/* Prototype: string realpath ( string $path );
6   Description: Returns canonicalized absolute pathname
7*/
8
9echo "\n*** Testing basic functions of realpath() with files ***\n";
10
11/* creating directories and files */
12$file_path = dirname(__FILE__);
13mkdir("$file_path/realpath_basic/home/test/", 0777, true);
14
15$file_handle1 = fopen("$file_path/realpath_basic/home/test/realpath_basic.tmp", "w");
16$file_handle2 = fopen("$file_path/realpath_basic/home/realpath_basic.tmp", "w");
17$file_handle3 = fopen("$file_path/realpath_basic/realpath_basic.tmp", "w");
18fclose($file_handle1);
19fclose($file_handle2);
20fclose($file_handle3);
21
22echo "\n*** Testing realpath() on filenames ***\n";
23$filenames = array (
24  /* filenames resulting in valid paths */
25  "./realpath_basic/home/realpath_basic.tmp",
26  "./realpath_basic/realpath_basic.tmp",
27  "./realpath_basic//home/test//../test/./realpath_basic.tmp",
28  "./realpath_basic/home//../././realpath_basic.tmp",
29
30  /* filenames with invalid path */
31  // checking for binary safe
32  "./realpath_basicx000/home/realpath_basic.tmp",
33
34  ".///realpath_basic/home//..//././test//realpath_basic.tmp",
35  "./realpath_basic/home/../home/../test/..realpath_basic.tmp"
36);
37
38chdir("$file_path/..");
39chdir($file_path);
40
41$counter = 1;
42/* loop through $files to read the filepath of $file in the above array */
43foreach($filenames as $file) {
44  echo "\n-- Iteration $counter --\n";
45  var_dump( realpath($file) );
46  $counter++;
47}
48
49echo "Done\n";
50?>
51--CLEAN--
52<?php
53$name_prefix = dirname(__FILE__)."/realpath_basic";
54unlink("$name_prefix/home/test/realpath_basic.tmp");
55unlink("$name_prefix/home/realpath_basic.tmp");
56unlink("$name_prefix/realpath_basic.tmp");
57rmdir("$name_prefix/home/test/");
58rmdir("$name_prefix/home/");
59rmdir("$name_prefix/");
60?>
61--EXPECTF--
62*** Testing basic functions of realpath() with files ***
63
64*** Testing realpath() on filenames ***
65
66-- Iteration 1 --
67string(%d) "%srealpath_basic%shome%srealpath_basic.tmp"
68
69-- Iteration 2 --
70string(%d) "%srealpath_basic%srealpath_basic.tmp"
71
72-- Iteration 3 --
73string(%d) "%srealpath_basic%shome%stest%srealpath_basic.tmp"
74
75-- Iteration 4 --
76string(%d) "%srealpath_basic%srealpath_basic.tmp"
77
78-- Iteration 5 --
79bool(false)
80
81-- Iteration 6 --
82bool(false)
83
84-- Iteration 7 --
85bool(false)
86Done
87