1--TEST-- 2basename 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--SKIPIF-- 6<?php 7if (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 23 /* simple paths with trailing slashes */ 24 array("bar\\"), 25 array("\\bar\\"), 26 array("\\foo\\bar\\"), 27 array("foo\\bar\\"), 28 array("\\bar\\"), 29 30 /* paths with suffix removal */ 31 array("bar.zip", ".zip"), 32 array("bar.zip", "bar.zip"), 33 array("\\foo\\bar.zip", ".zip"), 34 array("foo\\bar.zip", ".zip"), 35 array("\\bar.zip", ".zip"), 36 37 /* paths with suffix and trailing slashes with suffix removal*/ 38 array("bar.zip\\", ".zip"), 39 array("\\bar.zip\\", ".zip"), 40 array("\\foo\\bar.zip\\", ".zip"), 41 array("foo\\bar.zip\\", ".zip"), 42 array("\\bar.zip\\", ".zip"), 43 44 /* paths with basename only suffix, with suffix removal*/ 45 array("\\.zip", ".zip"), 46 array(".zip", ".zip"), 47 array("\\foo\\.zip", ".zip"), 48 49 /* paths with basename only suffix & trailing slashes, with suffix removal*/ 50 array(".zip\\", ".zip"), 51 array("\\foo\\.zip\\", ".zip"), 52 array("foo\\.zip\\", ".zip"), 53); 54 55$file_path_variations = array ( 56 /* paths with shortcut home dir char, with suffix variation */ 57 array("C:\\temp\\bar"), 58 array("C:\\temp\\bar", ""), 59 array("C:\\temp\\bar", NULL), 60 array("C:\\temp\\bar", ' '), 61 array("C:\\temp\\bar.tar", ".tar"), 62 array("C:\\temp\\bar.tar", "~"), 63 array("C:\\temp\\bar.tar\\", "~"), 64 array("C:\\temp\\bar.tar\\", ""), 65 array("C:\\temp\\bar.tar", NULL), 66 array("C:\\temp\\bar.tar", ''), 67 array("C:\\temp\\bar.tar", " "), 68 69 /* paths with numeric strings */ 70 array("10.5"), 71 array("10.5", ".5"), 72 array("10.5", "10.5"), 73 array("10"), 74 array("105", "5"), 75 array("/10.5"), 76 array("10.5\\"), 77 array("10/10.zip"), 78 array("0"), 79 array('0'), 80 81 /* paths and suffix given as same */ 82 array("bar.zip", "bar.zip"), 83 array("\\bar.zip", "\\bar.zip"), 84 array("\\bar.zip\\", "\\bar.zip\\"), 85 array(" ", " "), 86 array(' ', ' '), 87 array(NULL, NULL), 88 89 /* path with spaces */ 90 array(" "), 91 array(' '), 92 93 /* empty paths */ 94 array(""), 95 array(''), 96 array(NULL) 97); 98 99function check_basename( $path_arrays ) { 100 $loop_counter = 1; 101 foreach ($path_arrays as $path) { 102 echo "\n--Iteration $loop_counter--\n"; $loop_counter++; 103 if( 1 == count($path) ) { // no suffix provided 104 var_dump( basename($path[0]) ); 105 } else { // path as well as suffix provided, 106 var_dump( basename($path[0], $path[1]) ); 107 } 108 } 109} 110 111echo "*** Testing basic operations ***\n"; 112check_basename( $file_paths ); 113 114echo "\n*** Testing possible variations in path and suffix ***\n"; 115check_basename( $file_path_variations ); 116 117echo "Done\n"; 118?> 119--EXPECT-- 120*** Testing basic operations *** 121 122--Iteration 1-- 123string(3) "bar" 124 125--Iteration 2-- 126string(3) "bar" 127 128--Iteration 3-- 129string(3) "bar" 130 131--Iteration 4-- 132string(3) "bar" 133 134--Iteration 5-- 135string(3) "bar" 136 137--Iteration 6-- 138string(3) "bar" 139 140--Iteration 7-- 141string(3) "bar" 142 143--Iteration 8-- 144string(3) "bar" 145 146--Iteration 9-- 147string(3) "bar" 148 149--Iteration 10-- 150string(3) "bar" 151 152--Iteration 11-- 153string(7) "bar.zip" 154 155--Iteration 12-- 156string(3) "bar" 157 158--Iteration 13-- 159string(3) "bar" 160 161--Iteration 14-- 162string(3) "bar" 163 164--Iteration 15-- 165string(3) "bar" 166 167--Iteration 16-- 168string(3) "bar" 169 170--Iteration 17-- 171string(3) "bar" 172 173--Iteration 18-- 174string(3) "bar" 175 176--Iteration 19-- 177string(3) "bar" 178 179--Iteration 20-- 180string(4) ".zip" 181 182--Iteration 21-- 183string(4) ".zip" 184 185--Iteration 22-- 186string(4) ".zip" 187 188--Iteration 23-- 189string(4) ".zip" 190 191--Iteration 24-- 192string(4) ".zip" 193 194--Iteration 25-- 195string(4) ".zip" 196 197*** Testing possible variations in path and suffix *** 198 199--Iteration 1-- 200string(3) "bar" 201 202--Iteration 2-- 203string(3) "bar" 204 205--Iteration 3-- 206string(3) "bar" 207 208--Iteration 4-- 209string(3) "bar" 210 211--Iteration 5-- 212string(3) "bar" 213 214--Iteration 6-- 215string(7) "bar.tar" 216 217--Iteration 7-- 218string(7) "bar.tar" 219 220--Iteration 8-- 221string(7) "bar.tar" 222 223--Iteration 9-- 224string(7) "bar.tar" 225 226--Iteration 10-- 227string(7) "bar.tar" 228 229--Iteration 11-- 230string(7) "bar.tar" 231 232--Iteration 12-- 233string(4) "10.5" 234 235--Iteration 13-- 236string(2) "10" 237 238--Iteration 14-- 239string(4) "10.5" 240 241--Iteration 15-- 242string(2) "10" 243 244--Iteration 16-- 245string(2) "10" 246 247--Iteration 17-- 248string(4) "10.5" 249 250--Iteration 18-- 251string(4) "10.5" 252 253--Iteration 19-- 254string(6) "10.zip" 255 256--Iteration 20-- 257string(1) "0" 258 259--Iteration 21-- 260string(1) "0" 261 262--Iteration 22-- 263string(7) "bar.zip" 264 265--Iteration 23-- 266string(7) "bar.zip" 267 268--Iteration 24-- 269string(7) "bar.zip" 270 271--Iteration 25-- 272string(1) " " 273 274--Iteration 26-- 275string(1) " " 276 277--Iteration 27-- 278string(0) "" 279 280--Iteration 28-- 281string(1) " " 282 283--Iteration 29-- 284string(1) " " 285 286--Iteration 30-- 287string(0) "" 288 289--Iteration 31-- 290string(0) "" 291 292--Iteration 32-- 293string(0) "" 294Done 295