dirname_basic.phpt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. --TEST--
  2. Test dirname() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype: string dirname ( string $path );
  6. Description: Returns directory name component of path.
  7. */
  8. $file_paths = array (
  9. /* simple paths */
  10. "bar",
  11. "/foo/bar",
  12. "foo/bar",
  13. "/bar",
  14. "bar/",
  15. "/bar/",
  16. "/foo/bar/",
  17. "foo/bar/",
  18. "/bar/",
  19. /* path with only files and trailing slashes*/
  20. "/foo/bar.gz",
  21. "foo/bar.gz",
  22. "bar.gz",
  23. "bar.gz/",
  24. "/bar.gz",
  25. "/bar.gz/",
  26. "/foo/bar.gz/",
  27. "foo/bar.gz/",
  28. "/bar.gz/",
  29. /* path with file extension and trailing slashes */
  30. "/.gz",
  31. ".gz",
  32. "/foo/.gz",
  33. ".gz/",
  34. "/foo/.gz/",
  35. "foo/.gz/",
  36. /* paths with binary value to check if the function is binary safe*/
  37. "foo".chr(0)."bar",
  38. "/foo".chr(0)."bar/",
  39. "/foo".chr(0)."bar",
  40. "foo".chr(0)."bar/",
  41. "/foo".chr(0)."bar/t.gz"
  42. );
  43. function check_dirname( $paths ) {
  44. $loop_counter = 0;
  45. $noOfPaths = count($paths);
  46. for( ; $loop_counter < $noOfPaths; $loop_counter++ ) {
  47. echo "\n--Iteration ";
  48. echo $loop_counter + 1;
  49. echo " --\n";
  50. var_dump( dirname($paths[$loop_counter]) );
  51. }
  52. }
  53. echo "*** Testing basic operations ***\n";
  54. check_dirname( $file_paths );
  55. echo "Done\n";
  56. ?>
  57. --EXPECTREGEX--
  58. \*\*\* Testing basic operations \*\*\*
  59. --Iteration 1 --
  60. string\(1\) "."
  61. --Iteration 2 --
  62. string\(4\) "(\\|\/)foo"
  63. --Iteration 3 --
  64. string\(3\) "foo"
  65. --Iteration 4 --
  66. string\(1\) "(\\|\/)"
  67. --Iteration 5 --
  68. string\(1\) "."
  69. --Iteration 6 --
  70. string\(1\) "(\\|\/)"
  71. --Iteration 7 --
  72. string\(4\) "(\\|\/)foo"
  73. --Iteration 8 --
  74. string\(3\) "foo"
  75. --Iteration 9 --
  76. string\(1\) "(\\|\/)"
  77. --Iteration 10 --
  78. string\(4\) "(\\|\/)foo"
  79. --Iteration 11 --
  80. string\(3\) "foo"
  81. --Iteration 12 --
  82. string\(1\) "."
  83. --Iteration 13 --
  84. string\(1\) "."
  85. --Iteration 14 --
  86. string\(1\) "(\\|\/)"
  87. --Iteration 15 --
  88. string\(1\) "(\\|\/)"
  89. --Iteration 16 --
  90. string\(4\) "(\\|\/)foo"
  91. --Iteration 17 --
  92. string\(3\) "foo"
  93. --Iteration 18 --
  94. string\(1\) "(\\|\/)"
  95. --Iteration 19 --
  96. string\(1\) "(\\|\/)"
  97. --Iteration 20 --
  98. string\(1\) "."
  99. --Iteration 21 --
  100. string\(4\) "(\\|\/)foo"
  101. --Iteration 22 --
  102. string\(1\) "."
  103. --Iteration 23 --
  104. string\(4\) "(\\|\/)foo"
  105. --Iteration 24 --
  106. string\(3\) "foo"
  107. --Iteration 25 --
  108. string\(1\) "."
  109. --Iteration 26 --
  110. string\(1\) "(\\|\/)"
  111. --Iteration 27 --
  112. string\(1\) "(\\|\/)"
  113. --Iteration 28 --
  114. string\(1\) "."
  115. --Iteration 29 --
  116. string\(8\) "(\\|\/)foo\x00bar"
  117. Done