realpath_basic-win32.phpt 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. --TEST--
  2. Test realpath() function: basic functionality
  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. echo "\n*** Testing basic functions of realpath() with files ***\n";
  15. /* creating directories and files */
  16. $file_path = dirname(__FILE__);
  17. mkdir("$file_path/realpath_basic/home/test/", 0777, true);
  18. $file_handle1 = fopen("$file_path/realpath_basic/home/test/realpath_basic.tmp", "w");
  19. $file_handle2 = fopen("$file_path/realpath_basic/home/realpath_basic.tmp", "w");
  20. $file_handle3 = fopen("$file_path/realpath_basic/realpath_basic.tmp", "w");
  21. fclose($file_handle1);
  22. fclose($file_handle2);
  23. fclose($file_handle3);
  24. echo "\n*** Testing realpath() on filenames ***\n";
  25. $filenames = array (
  26. /* filenames resulting in valid paths */
  27. "$file_path/realpath_basic/home/realpath_basic.tmp",
  28. "$file_path/realpath_basic/realpath_basic.tmp/",
  29. "$file_path/realpath_basic//home/test//../test/./realpath_basic.tmp",
  30. "$file_path/realpath_basic/home//../././realpath_basic.tmp//",
  31. // checking for binary safe
  32. b"$file_path/realpath_basic/home/realpath_basic.tmp",
  33. /* filenames with invalid path */
  34. "$file_path///realpath_basic/home//..//././test//realpath_basic.tmp",
  35. "$file_path/realpath_basic/home/../home/../test/../..realpath_basic.tmp"
  36. );
  37. $counter = 1;
  38. /* loop through $files to read the filepath of $file in the above array */
  39. foreach($filenames as $file) {
  40. echo "\n-- Iteration $counter --\n";
  41. var_dump( realpath($file) );
  42. $counter++;
  43. }
  44. echo "Done\n";
  45. ?>
  46. --CLEAN--
  47. <?php
  48. $name_prefix = dirname(__FILE__)."/realpath_basic";
  49. unlink("$name_prefix/home/test/realpath_basic.tmp");
  50. unlink("$name_prefix/home/realpath_basic.tmp");
  51. unlink("$name_prefix/realpath_basic.tmp");
  52. rmdir("$name_prefix/home/test/");
  53. rmdir("$name_prefix/home/");
  54. rmdir("$name_prefix/");
  55. ?>
  56. --EXPECTF--
  57. *** Testing basic functions of realpath() with files ***
  58. *** Testing realpath() on filenames ***
  59. -- Iteration 1 --
  60. string(%d) "%s\realpath_basic\home\realpath_basic.tmp"
  61. -- Iteration 2 --
  62. bool(false)
  63. -- Iteration 3 --
  64. string(%d) "%s\realpath_basic\home\test\realpath_basic.tmp"
  65. -- Iteration 4 --
  66. bool(false)
  67. -- Iteration 5 --
  68. string(%d) "%s\realpath_basic\home\realpath_basic.tmp"
  69. -- Iteration 6 --
  70. bool(false)
  71. -- Iteration 7 --
  72. bool(false)
  73. Done