realpath_basic3.phpt 2.2 KB

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