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