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