realpath_variation-win32.phpt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. --TEST--
  2. Test realpath() function: usage variation
  3. --SKIPIF--
  4. <?php
  5. if (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. require dirname(__FILE__).'/file.inc';
  15. echo "*** Testing realpath(): usage variations ***\n";
  16. $name_prefix = dirname(__FILE__);
  17. $filename = "$name_prefix/realpath_variation/home/tests/realpath_variation.tmp";
  18. mkdir("$name_prefix/realpath_variation/home/tests/", 0777, true);
  19. echo "\n*** Testing realpath() with filename stored inside a object ***\n";
  20. // create a temp file
  21. $file_handle = fopen($filename, "w");
  22. fclose($file_handle);
  23. // creating object with members as filename
  24. class object_temp {
  25. public $filename;
  26. function object_temp($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. var_dump( realpath($obj1->filename) );
  33. var_dump( realpath($obj2->filename) );
  34. echo "\n*** Testing realpath() with filename stored in an array ***\n";
  35. $file_arr = array (
  36. "$name_prefix////realpath_variation/home/tests/realpath_variation.tmp",
  37. "$name_prefix/./realpath_variation/home/../home//tests//..//..//..//home//realpath_variation.tmp/"
  38. );
  39. var_dump( realpath($file_arr[0]) );
  40. var_dump( realpath($file_arr[1]) );
  41. echo "\n*** Testing realpath() with filename as empty string, NULL and single space ***\n";
  42. $file_string = array (
  43. /* filename as spaces */
  44. " ",
  45. ' ',
  46. /* empty filename */
  47. "",
  48. '',
  49. NULL,
  50. null
  51. );
  52. for($loop_counter = 0; $loop_counter < count($file_string); $loop_counter++) {
  53. echo "-- Iteration";
  54. echo $loop_counter + 1;
  55. echo " --\n";
  56. var_dump( realpath($file_string[$loop_counter]) );
  57. }
  58. echo "Done\n";
  59. ?>
  60. --CLEAN--
  61. <?php
  62. $name_prefix = dirname(__FILE__)."/realpath_variation";
  63. unlink("$name_prefix/home/tests/realpath_variation.tmp");
  64. rmdir("$name_prefix/home/tests/");
  65. rmdir("$name_prefix/home/");
  66. rmdir("$name_prefix/");
  67. ?>
  68. --EXPECTF--
  69. *** Testing realpath(): usage variations ***
  70. *** Testing realpath() with filename stored inside a object ***
  71. string(%d) "%s\realpath_variation\home\tests\realpath_variation.tmp"
  72. bool(false)
  73. *** Testing realpath() with filename stored in an array ***
  74. string(%d) "%s\realpath_variation\home\tests\realpath_variation.tmp"
  75. bool(false)
  76. *** Testing realpath() with filename as empty string, NULL and single space ***
  77. -- Iteration1 --
  78. bool(false)
  79. -- Iteration2 --
  80. bool(false)
  81. -- Iteration3 --
  82. string(%d) "%s"
  83. -- Iteration4 --
  84. string(%d) "%s"
  85. -- Iteration5 --
  86. string(%d) "%s"
  87. -- Iteration6 --
  88. string(%d) "%s"
  89. Done