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