Annotation of embedaddon/php/ext/standard/tests/file/basename-win32.phpt, revision 1.1
1.1 ! misho 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: * proto string basename(string path [, string suffix])
! 15: * Function is implemented in ext/standard/string.c
! 16: */
! 17: $file_paths = array (
! 18: /* simple paths */
! 19: array("bar"),
! 20: array("\\foo\\bar"),
! 21: array("foo\\bar"),
! 22: array("\\bar"),
! 23:
! 24: /* simple paths with trailing slashes */
! 25: array("bar\\"),
! 26: array("\\bar\\"),
! 27: array("\\foo\\bar\\"),
! 28: array("foo\\bar\\"),
! 29: array("\\bar\\"),
! 30:
! 31: /* paths with suffix removal */
! 32: array("bar.zip", ".zip"),
! 33: array("bar.zip", "bar.zip"),
! 34: array("\\foo\\bar.zip", ".zip"),
! 35: array("foo\\bar.zip", ".zip"),
! 36: array("\\bar.zip", ".zip"),
! 37:
! 38: /* paths with suffix and trailing slashes with suffix removal*/
! 39: array("bar.zip\\", ".zip"),
! 40: array("\\bar.zip\\", ".zip"),
! 41: array("\\foo\\bar.zip\\", ".zip"),
! 42: array("foo\\bar.zip\\", ".zip"),
! 43: array("\\bar.zip\\", ".zip"),
! 44:
! 45: /* paths with basename only suffix, with suffix removal*/
! 46: array("\\.zip", ".zip"),
! 47: array(".zip", ".zip"),
! 48: array("\\foo\\.zip", ".zip"),
! 49:
! 50: /* paths with basename only suffix & trailing slashes, with suffix removal*/
! 51: array(".zip\\", ".zip"),
! 52: array("\\foo\\.zip\\", ".zip"),
! 53: array("foo\\.zip\\", ".zip"),
! 54: );
! 55:
! 56: $file_path_variations = array (
! 57: /* paths with shortcut home dir char, with suffix variation */
! 58: array("C:\\temp\\bar"),
! 59: array("C:\\temp\\bar", ""),
! 60: array("C:\\temp\\bar", NULL),
! 61: array("C:\\temp\\bar", ' '),
! 62: array("C:\\temp\\bar.tar", ".tar"),
! 63: array("C:\\temp\\bar.tar", "~"),
! 64: array("C:\\temp\\bar.tar\\", "~"),
! 65: array("C:\\temp\\bar.tar\\", ""),
! 66: array("C:\\temp\\bar.tar", NULL),
! 67: array("C:\\temp\\bar.tar", ''),
! 68: array("C:\\temp\\bar.tar", " "),
! 69:
! 70: /* paths with numeric strings */
! 71: array("10.5"),
! 72: array("10.5", ".5"),
! 73: array("10.5", "10.5"),
! 74: array("10"),
! 75: array("105", "5"),
! 76: array("/10.5"),
! 77: array("10.5\\"),
! 78: array("10/10.zip"),
! 79: array("0"),
! 80: array('0'),
! 81:
! 82: /* paths and suffix given as same */
! 83: array("bar.zip", "bar.zip"),
! 84: array("\\bar.zip", "\\bar.zip"),
! 85: array("\\bar.zip\\", "\\bar.zip\\"),
! 86: array(" ", " "),
! 87: array(' ', ' '),
! 88: array(NULL, NULL),
! 89:
! 90: /* path with spaces */
! 91: array(" "),
! 92: array(' '),
! 93:
! 94: /* empty paths */
! 95: array(""),
! 96: array(''),
! 97: array(NULL)
! 98: );
! 99:
! 100: function check_basename( $path_arrays ) {
! 101: $loop_counter = 1;
! 102: foreach ($path_arrays as $path) {
! 103: echo "\n--Iteration $loop_counter--\n"; $loop_counter++;
! 104: if( 1 == count($path) ) { // no suffix provided
! 105: var_dump( basename($path[0]) );
! 106: } else { // path as well as suffix provided,
! 107: var_dump( basename($path[0], $path[1]) );
! 108: }
! 109: }
! 110: }
! 111:
! 112: echo "*** Testing basic operations ***\n";
! 113: check_basename( $file_paths );
! 114:
! 115: echo "\n*** Testing possible variations in path and suffix ***\n";
! 116: check_basename( $file_path_variations );
! 117:
! 118: echo "\n*** Testing error conditions ***\n";
! 119: // zero arguments
! 120: var_dump( basename() );
! 121:
! 122: // more than expected no. of arguments
! 123: var_dump( basename("\\blah\\tmp\\bar.zip", ".zip", ".zip") );
! 124:
! 125: // passing invalid type arguments
! 126: $object = new stdclass;
! 127: var_dump( basename( array("string\\bar") ) );
! 128: var_dump( basename( array("string\\bar"), "bar" ) );
! 129: var_dump( basename( "bar", array("string\\bar") ) );
! 130: var_dump( basename( $object, "bar" ) );
! 131: var_dump( basename( $object ) );
! 132: var_dump( basename( $object, $object ) );
! 133: var_dump( basename( "bar", $object ) );
! 134:
! 135: echo "Done\n";
! 136: ?>
! 137: --EXPECTF--
! 138: *** Testing basic operations ***
! 139:
! 140: --Iteration 1--
! 141: string(3) "bar"
! 142:
! 143: --Iteration 2--
! 144: string(3) "bar"
! 145:
! 146: --Iteration 3--
! 147: string(3) "bar"
! 148:
! 149: --Iteration 4--
! 150: string(3) "bar"
! 151:
! 152: --Iteration 5--
! 153: string(3) "bar"
! 154:
! 155: --Iteration 6--
! 156: string(3) "bar"
! 157:
! 158: --Iteration 7--
! 159: string(3) "bar"
! 160:
! 161: --Iteration 8--
! 162: string(3) "bar"
! 163:
! 164: --Iteration 9--
! 165: string(3) "bar"
! 166:
! 167: --Iteration 10--
! 168: string(3) "bar"
! 169:
! 170: --Iteration 11--
! 171: string(7) "bar.zip"
! 172:
! 173: --Iteration 12--
! 174: string(3) "bar"
! 175:
! 176: --Iteration 13--
! 177: string(3) "bar"
! 178:
! 179: --Iteration 14--
! 180: string(3) "bar"
! 181:
! 182: --Iteration 15--
! 183: string(3) "bar"
! 184:
! 185: --Iteration 16--
! 186: string(3) "bar"
! 187:
! 188: --Iteration 17--
! 189: string(3) "bar"
! 190:
! 191: --Iteration 18--
! 192: string(3) "bar"
! 193:
! 194: --Iteration 19--
! 195: string(3) "bar"
! 196:
! 197: --Iteration 20--
! 198: string(4) ".zip"
! 199:
! 200: --Iteration 21--
! 201: string(4) ".zip"
! 202:
! 203: --Iteration 22--
! 204: string(4) ".zip"
! 205:
! 206: --Iteration 23--
! 207: string(4) ".zip"
! 208:
! 209: --Iteration 24--
! 210: string(4) ".zip"
! 211:
! 212: --Iteration 25--
! 213: string(4) ".zip"
! 214:
! 215: *** Testing possible variations in path and suffix ***
! 216:
! 217: --Iteration 1--
! 218: string(3) "bar"
! 219:
! 220: --Iteration 2--
! 221: string(3) "bar"
! 222:
! 223: --Iteration 3--
! 224: string(3) "bar"
! 225:
! 226: --Iteration 4--
! 227: string(3) "bar"
! 228:
! 229: --Iteration 5--
! 230: string(3) "bar"
! 231:
! 232: --Iteration 6--
! 233: string(7) "bar.tar"
! 234:
! 235: --Iteration 7--
! 236: string(7) "bar.tar"
! 237:
! 238: --Iteration 8--
! 239: string(7) "bar.tar"
! 240:
! 241: --Iteration 9--
! 242: string(7) "bar.tar"
! 243:
! 244: --Iteration 10--
! 245: string(7) "bar.tar"
! 246:
! 247: --Iteration 11--
! 248: string(7) "bar.tar"
! 249:
! 250: --Iteration 12--
! 251: string(4) "10.5"
! 252:
! 253: --Iteration 13--
! 254: string(2) "10"
! 255:
! 256: --Iteration 14--
! 257: string(4) "10.5"
! 258:
! 259: --Iteration 15--
! 260: string(2) "10"
! 261:
! 262: --Iteration 16--
! 263: string(2) "10"
! 264:
! 265: --Iteration 17--
! 266: string(4) "10.5"
! 267:
! 268: --Iteration 18--
! 269: string(4) "10.5"
! 270:
! 271: --Iteration 19--
! 272: string(6) "10.zip"
! 273:
! 274: --Iteration 20--
! 275: string(1) "0"
! 276:
! 277: --Iteration 21--
! 278: string(1) "0"
! 279:
! 280: --Iteration 22--
! 281: string(7) "bar.zip"
! 282:
! 283: --Iteration 23--
! 284: string(7) "bar.zip"
! 285:
! 286: --Iteration 24--
! 287: string(7) "bar.zip"
! 288:
! 289: --Iteration 25--
! 290: string(1) " "
! 291:
! 292: --Iteration 26--
! 293: string(1) " "
! 294:
! 295: --Iteration 27--
! 296: string(0) ""
! 297:
! 298: --Iteration 28--
! 299: string(1) " "
! 300:
! 301: --Iteration 29--
! 302: string(1) " "
! 303:
! 304: --Iteration 30--
! 305: string(0) ""
! 306:
! 307: --Iteration 31--
! 308: string(0) ""
! 309:
! 310: --Iteration 32--
! 311: string(0) ""
! 312:
! 313: *** Testing error conditions ***
! 314:
! 315: Warning: basename() expects at least 1 parameter, 0 given in %s on line %d
! 316: NULL
! 317:
! 318: Warning: basename() expects at most 2 parameters, 3 given in %s on line %d
! 319: NULL
! 320:
! 321: Warning: basename() expects parameter 1 to be string, array given in %s on line %d
! 322: NULL
! 323:
! 324: Warning: basename() expects parameter 1 to be string, array given in %s on line %d
! 325: NULL
! 326:
! 327: Warning: basename() expects parameter 2 to be string, array given in %s on line %d
! 328: NULL
! 329:
! 330: Warning: basename() expects parameter 1 to be string, object given in %s on line %d
! 331: NULL
! 332:
! 333: Warning: basename() expects parameter 1 to be string, object given in %s on line %d
! 334: NULL
! 335:
! 336: Warning: basename() expects parameter 1 to be string, object given in %s on line %d
! 337: NULL
! 338:
! 339: Warning: basename() expects parameter 2 to be string, object given in %s on line %d
! 340: NULL
! 341: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>