basename-win32.phpt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. --TEST--
  2. basename
  3. --CREDITS--
  4. Dave Kelsey <d_kelsey@uk.ibm.com>
  5. --SKIPIF--
  6. <?php
  7. if (substr(PHP_OS, 0, 3) != 'WIN') {
  8. die('skip Windows only basename tests');
  9. }
  10. ?>
  11. --FILE--
  12. <?php
  13. /*
  14. * Function is implemented in ext/standard/string.c
  15. */
  16. $file_paths = array (
  17. /* simple paths */
  18. array("bar"),
  19. array("\\foo\\bar"),
  20. array("foo\\bar"),
  21. array("\\bar"),
  22. /* simple paths with trailing slashes */
  23. array("bar\\"),
  24. array("\\bar\\"),
  25. array("\\foo\\bar\\"),
  26. array("foo\\bar\\"),
  27. array("\\bar\\"),
  28. /* paths with suffix removal */
  29. array("bar.zip", ".zip"),
  30. array("bar.zip", "bar.zip"),
  31. array("\\foo\\bar.zip", ".zip"),
  32. array("foo\\bar.zip", ".zip"),
  33. array("\\bar.zip", ".zip"),
  34. /* paths with suffix and trailing slashes with suffix removal*/
  35. array("bar.zip\\", ".zip"),
  36. array("\\bar.zip\\", ".zip"),
  37. array("\\foo\\bar.zip\\", ".zip"),
  38. array("foo\\bar.zip\\", ".zip"),
  39. array("\\bar.zip\\", ".zip"),
  40. /* paths with basename only suffix, with suffix removal*/
  41. array("\\.zip", ".zip"),
  42. array(".zip", ".zip"),
  43. array("\\foo\\.zip", ".zip"),
  44. /* paths with basename only suffix & trailing slashes, with suffix removal*/
  45. array(".zip\\", ".zip"),
  46. array("\\foo\\.zip\\", ".zip"),
  47. array("foo\\.zip\\", ".zip"),
  48. );
  49. $file_path_variations = array (
  50. /* paths with shortcut home dir char, with suffix variation */
  51. array("C:\\temp\\bar"),
  52. array("C:\\temp\\bar", ""),
  53. array("C:\\temp\\bar", ' '),
  54. array("C:\\temp\\bar.tar", ".tar"),
  55. array("C:\\temp\\bar.tar", "~"),
  56. array("C:\\temp\\bar.tar\\", "~"),
  57. array("C:\\temp\\bar.tar\\", ""),
  58. array("C:\\temp\\bar.tar", ''),
  59. array("C:\\temp\\bar.tar", " "),
  60. /* paths with numeric strings */
  61. array("10.5"),
  62. array("10.5", ".5"),
  63. array("10.5", "10.5"),
  64. array("10"),
  65. array("105", "5"),
  66. array("/10.5"),
  67. array("10.5\\"),
  68. array("10/10.zip"),
  69. array("0"),
  70. array('0'),
  71. /* paths and suffix given as same */
  72. array("bar.zip", "bar.zip"),
  73. array("\\bar.zip", "\\bar.zip"),
  74. array("\\bar.zip\\", "\\bar.zip\\"),
  75. array(" ", " "),
  76. array(' ', ' '),
  77. /* path with spaces */
  78. array(" "),
  79. array(' '),
  80. /* empty paths */
  81. array(""),
  82. array(''),
  83. );
  84. function check_basename( $path_arrays ) {
  85. $loop_counter = 1;
  86. foreach ($path_arrays as $path) {
  87. echo "\n--Iteration $loop_counter--\n"; $loop_counter++;
  88. if( 1 == count($path) ) { // no suffix provided
  89. var_dump( basename($path[0]) );
  90. } else { // path as well as suffix provided,
  91. var_dump( basename($path[0], $path[1]) );
  92. }
  93. }
  94. }
  95. echo "*** Testing basic operations ***\n";
  96. check_basename( $file_paths );
  97. echo "\n*** Testing possible variations in path and suffix ***\n";
  98. check_basename( $file_path_variations );
  99. echo "Done\n";
  100. ?>
  101. --EXPECT--
  102. *** Testing basic operations ***
  103. --Iteration 1--
  104. string(3) "bar"
  105. --Iteration 2--
  106. string(3) "bar"
  107. --Iteration 3--
  108. string(3) "bar"
  109. --Iteration 4--
  110. string(3) "bar"
  111. --Iteration 5--
  112. string(3) "bar"
  113. --Iteration 6--
  114. string(3) "bar"
  115. --Iteration 7--
  116. string(3) "bar"
  117. --Iteration 8--
  118. string(3) "bar"
  119. --Iteration 9--
  120. string(3) "bar"
  121. --Iteration 10--
  122. string(3) "bar"
  123. --Iteration 11--
  124. string(7) "bar.zip"
  125. --Iteration 12--
  126. string(3) "bar"
  127. --Iteration 13--
  128. string(3) "bar"
  129. --Iteration 14--
  130. string(3) "bar"
  131. --Iteration 15--
  132. string(3) "bar"
  133. --Iteration 16--
  134. string(3) "bar"
  135. --Iteration 17--
  136. string(3) "bar"
  137. --Iteration 18--
  138. string(3) "bar"
  139. --Iteration 19--
  140. string(3) "bar"
  141. --Iteration 20--
  142. string(4) ".zip"
  143. --Iteration 21--
  144. string(4) ".zip"
  145. --Iteration 22--
  146. string(4) ".zip"
  147. --Iteration 23--
  148. string(4) ".zip"
  149. --Iteration 24--
  150. string(4) ".zip"
  151. --Iteration 25--
  152. string(4) ".zip"
  153. *** Testing possible variations in path and suffix ***
  154. --Iteration 1--
  155. string(3) "bar"
  156. --Iteration 2--
  157. string(3) "bar"
  158. --Iteration 3--
  159. string(3) "bar"
  160. --Iteration 4--
  161. string(3) "bar"
  162. --Iteration 5--
  163. string(7) "bar.tar"
  164. --Iteration 6--
  165. string(7) "bar.tar"
  166. --Iteration 7--
  167. string(7) "bar.tar"
  168. --Iteration 8--
  169. string(7) "bar.tar"
  170. --Iteration 9--
  171. string(7) "bar.tar"
  172. --Iteration 10--
  173. string(4) "10.5"
  174. --Iteration 11--
  175. string(2) "10"
  176. --Iteration 12--
  177. string(4) "10.5"
  178. --Iteration 13--
  179. string(2) "10"
  180. --Iteration 14--
  181. string(2) "10"
  182. --Iteration 15--
  183. string(4) "10.5"
  184. --Iteration 16--
  185. string(4) "10.5"
  186. --Iteration 17--
  187. string(6) "10.zip"
  188. --Iteration 18--
  189. string(1) "0"
  190. --Iteration 19--
  191. string(1) "0"
  192. --Iteration 20--
  193. string(7) "bar.zip"
  194. --Iteration 21--
  195. string(7) "bar.zip"
  196. --Iteration 22--
  197. string(7) "bar.zip"
  198. --Iteration 23--
  199. string(1) " "
  200. --Iteration 24--
  201. string(1) " "
  202. --Iteration 25--
  203. string(1) " "
  204. --Iteration 26--
  205. string(1) " "
  206. --Iteration 27--
  207. string(0) ""
  208. --Iteration 28--
  209. string(0) ""
  210. Done