chdir_basic.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. --TEST--
  2. Test chdir() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype : bool chdir(string $directory)
  6. * Description: Change the current directory
  7. * Source code: ext/standard/dir.c
  8. */
  9. /*
  10. * Test basic functionality of chdir() with absolute and relative paths
  11. */
  12. echo "*** Testing chdir() : basic functionality ***\n";
  13. $base_dir_path = dirname(__FILE__);
  14. $level1_one_dir_name = "level1_one";
  15. $level1_one_dir_path = "$base_dir_path/$level1_one_dir_name";
  16. $level1_two_dir_name = "level1_two";
  17. $level1_two_dir_path = "$base_dir_path/$level1_one_dir_name/$level1_two_dir_name";
  18. // create directories
  19. mkdir($level1_one_dir_path);
  20. mkdir($level1_two_dir_path);
  21. echo "\n-- Testing chdir() with absolute path: --\n";
  22. chdir($base_dir_path);
  23. var_dump(chdir($level1_one_dir_path));
  24. var_dump(getcwd());
  25. echo "\n-- Testing chdir() with relative paths: --\n";
  26. var_dump(chdir($level1_two_dir_name));
  27. var_dump(getcwd());
  28. ?>
  29. ===DONE===
  30. --CLEAN--
  31. <?php
  32. $file_path = dirname(__FILE__);
  33. rmdir("$file_path/level1_one/level1_two");
  34. rmdir("$file_path/level1_one");
  35. ?>
  36. --EXPECTF--
  37. *** Testing chdir() : basic functionality ***
  38. -- Testing chdir() with absolute path: --
  39. bool(true)
  40. string(%d) "%slevel1_one"
  41. -- Testing chdir() with relative paths: --
  42. bool(true)
  43. string(%d) "%slevel1_one%elevel1_two"
  44. ===DONE===