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 = __DIR__;
13mkdir("$file_path/realpath_basic3/home/test/", 0777, true);
14
15$file_handle1 = fopen("$file_path/realpath_basic3/home/test/realpath_basic3.tmp", "w");
16$file_handle2 = fopen("$file_path/realpath_basic3/home/realpath_basic3.tmp", "w");
17$file_handle3 = fopen("$file_path/realpath_basic3/realpath_basic3.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_basic3/home/realpath_basic3.tmp",
26  "./realpath_basic3/realpath_basic3.tmp",
27  "./realpath_basic3//home/test//../test/./realpath_basic3.tmp",
28  "./realpath_basic3/home//../././realpath_basic3.tmp",
29
30  /* filenames with invalid path */
31  // checking for binary safe
32  "./realpath_basic3x000/home/realpath_basic3.tmp",
33
34  ".///realpath_basic3/home//..//././test//realpath_basic3.tmp",
35  "./realpath_basic3/home/../home/../test/..realpath_basic3.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 = __DIR__."/realpath_basic3";
54unlink("$name_prefix/home/test/realpath_basic3.tmp");
55unlink("$name_prefix/home/realpath_basic3.tmp");
56unlink("$name_prefix/realpath_basic3.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_basic3%shome%srealpath_basic3.tmp"
68
69-- Iteration 2 --
70string(%d) "%srealpath_basic3%srealpath_basic3.tmp"
71
72-- Iteration 3 --
73string(%d) "%srealpath_basic3%shome%stest%srealpath_basic3.tmp"
74
75-- Iteration 4 --
76string(%d) "%srealpath_basic3%srealpath_basic3.tmp"
77
78-- Iteration 5 --
79bool(false)
80
81-- Iteration 6 --
82bool(false)
83
84-- Iteration 7 --
85bool(false)
86Done
87