realpath_basic3.phpt 2.3 KB

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