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