1--TEST--
2Test realpath() function: usage variation
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6    die('skip only on Windows');
7}
8?>
9--FILE--
10<?php
11/* Prototype: string realpath ( string $path );
12   Description: Returns canonicalized absolute pathname
13*/
14
15require dirname(__FILE__).'/file.inc';
16
17echo "*** Testing realpath(): usage variations ***\n";
18$name_prefix = dirname(__FILE__);
19$filename = "$name_prefix/realpath_variation_私はガラスを食べられます/home/tests/realpath_variation_私はガラスを食べられます.tmp";
20mkdir("$name_prefix/realpath_variation_私はガラスを食べられます/home/tests/", 0777, true);
21
22echo "\n*** Testing realpath() with filename stored inside a object ***\n";
23// create a temp file
24$file_handle = fopen($filename, "w");
25fclose($file_handle);
26
27// creating object with members as filename
28class object_temp {
29  public $filename;
30  function __construct($file) {
31    $this->filename = $file;
32  }
33}
34$obj1 = new object_temp("$name_prefix/realpath_variation_私はガラスを食べられます/../././realpath_variation_私はガラスを食べられます/home/tests/realpath_variation_私はガラスを食べられます.tmp");
35$obj2 = new object_temp("$name_prefix/realpath_variation_私はガラスを食べられます/home/..///realpath_variation_私はガラスを食べられます.tmp");
36
37var_dump( realpath($obj1->filename) );
38var_dump( realpath($obj2->filename) );
39
40echo "\n*** Testing realpath() with filename stored in an array ***\n";
41$file_arr = array (
42  "$name_prefix////realpath_variation_私はガラスを食べられます/home/tests/realpath_variation_私はガラスを食べられます.tmp",
43  "$name_prefix/./realpath_variation_私はガラスを食べられます/home/../home//tests//..//..//..//home//realpath_variation_私はガラスを食べられます.tmp/"
44);
45
46var_dump( realpath($file_arr[0]) );
47var_dump( realpath($file_arr[1]) );
48
49echo "\n*** Testing realpath() with filename as empty string, NULL and single space ***\n";
50$file_string = array (
51  /* filename as spaces */
52  " ",
53  ' ',
54
55  /* empty filename */
56  "",
57  '',
58  NULL,
59  null
60 );
61for($loop_counter = 0; $loop_counter < count($file_string); $loop_counter++) {
62  echo "-- Iteration";
63  echo $loop_counter + 1;
64  echo " --\n";
65  var_dump( realpath($file_string[$loop_counter]) );
66}
67
68echo "Done\n";
69?>
70--CLEAN--
71<?php
72$name_prefix = dirname(__FILE__)."/realpath_variation_私はガラスを食べられます";
73unlink("$name_prefix/home/tests/realpath_variation_私はガラスを食べられます.tmp");
74rmdir("$name_prefix/home/tests/");
75rmdir("$name_prefix/home/");
76rmdir("$name_prefix/");
77?>
78--EXPECTF--
79*** Testing realpath(): usage variations ***
80
81*** Testing realpath() with filename stored inside a object ***
82string(%d) "%s\realpath_variation_私はガラスを食べられます\home\tests\realpath_variation_私はガラスを食べられます.tmp"
83bool(false)
84
85*** Testing realpath() with filename stored in an array ***
86string(%d) "%s\realpath_variation_私はガラスを食べられます\home\tests\realpath_variation_私はガラスを食べられます.tmp"
87bool(false)
88
89*** Testing realpath() with filename as empty string, NULL and single space ***
90-- Iteration1 --
91bool(false)
92-- Iteration2 --
93bool(false)
94-- Iteration3 --
95string(%d) "%s"
96-- Iteration4 --
97string(%d) "%s"
98-- Iteration5 --
99string(%d) "%s"
100-- Iteration6 --
101string(%d) "%s"
102Done
103