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