Annotation of embedaddon/php/ext/standard/tests/file/basename.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: basename
! 3: --CREDITS--
! 4: Dave Kelsey <d_kelsey@uk.ibm.com>
! 5: --FILE--
! 6: <?php
! 7: /*
! 8: * proto string basename(string path [, string suffix])
! 9: * Function is implemented in ext/standard/string.c
! 10: */
! 11: $file_paths = array (
! 12: /* simple paths */
! 13: array("bar"),
! 14: array("/foo/bar"),
! 15: array("foo/bar"),
! 16: array("/bar"),
! 17:
! 18: /* simple paths with trailing slashes */
! 19: array("bar/"),
! 20: array("/bar/"),
! 21: array("/foo/bar/"),
! 22: array("foo/bar/"),
! 23: array("/bar/"),
! 24:
! 25: /* paths with suffix removal */
! 26: array("bar.gz", ".gz"),
! 27: array("bar.gz", "bar.gz"),
! 28: array("/foo/bar.gz", ".gz"),
! 29: array("foo/bar.gz", ".gz"),
! 30: array("/bar.gz", ".gz"),
! 31:
! 32: /* paths with suffix and trailing slashes with suffix removal*/
! 33: array("bar.gz/", ".gz"),
! 34: array("/bar.gz/", ".gz"),
! 35: array("/foo/bar.gz/", ".gz"),
! 36: array("foo/bar.gz/", ".gz"),
! 37: array("/bar.gz/", ".gz"),
! 38:
! 39: /* paths with basename only suffix, with suffix removal*/
! 40: array("/.gz", ".gz"),
! 41: array(".gz", ".gz"),
! 42: array("/foo/.gz", ".gz"),
! 43:
! 44: /* paths with basename only suffix & trailing slashes, with suffix removal*/
! 45: array(".gz/", ".gz"),
! 46: array("/foo/.gz/", ".gz"),
! 47: array("foo/.gz/", ".gz"),
! 48:
! 49: /* paths with binary value to check if the function is binary safe*/
! 50: array("foo".chr(0)."bar"),
! 51: array("/foo".chr(0)."bar"),
! 52: array("/foo".chr(0)."bar/"),
! 53: array("foo".chr(0)."bar/"),
! 54: array("foo".chr(0)."bar/test"),
! 55: array("/foo".chr(0)."bar/bar.gz", ".gz"),
! 56: array("/foo".chr(0)."bar/bar.gz")
! 57: );
! 58:
! 59: $file_path_variations = array (
! 60: /* paths with shortcut home dir char, with suffix variation */
! 61: array("~/home/user/bar"),
! 62: array("~/home/user/bar", ""),
! 63: array("~/home/user/bar", NULL),
! 64: array("~/home/user/bar", ' '),
! 65: array("~/home/user/bar.tar", ".tar"),
! 66: array("~/home/user/bar.tar", "~"),
! 67: array("~/home/user/bar.tar/", "~"),
! 68: array("~/home/user/bar.tar/", ""),
! 69: array("~/home/user/bar.tar", NULL),
! 70: array("~/home/user/bar.tar", ''),
! 71: array("~/home/user/bar.tar", " "),
! 72:
! 73: /* paths with hostname:dir notation, with suffix variation */
! 74: array("hostname:/home/usr/bar.tar"),
! 75: array("hostname:/home/user/bar.tar", "home"),
! 76: array("hostname:/home/user/tbar.gz", "bar.gz"),
! 77: array("hostname:/home/user/tbar.gz", "/bar.gz"),
! 78: array("hostname:/home/user/tbar.gz", "/bar.gz/"),
! 79: array("hostname:/home/user/tbar.gz/", "/bar.gz/"),
! 80: array("hostname:/home/user/tbar.gz/", "/bar.gz/"),
! 81: array("hostname:/home/user/My Pics.gz/", "/bar.gz/"),
! 82: array("hostname:/home/user/My Pics.gz/", "Pics.gz/"),
! 83: array("hostname:/home/user/My Pics.gz/", "Pics.gz"),
! 84: array("hostname:/home/user/My Pics.gz/", ".gz"),
! 85: array("hostname:/home/user/My Pics.gz/"),
! 86: array("hostname:/home/user/My Pics.gz/", NULL),
! 87: array("hostname:/home/user/My Pics.gz/", ' '),
! 88: array("hostname:/home/user/My Pics.gz/", ''),
! 89: array("hostname:/home/user/My Pics.gz/", "My Pics.gz"),
! 90:
! 91: /* paths with numeirc strings */
! 92: array("10.5"),
! 93: array("10.5", ".5"),
! 94: array("10.5", "10.5"),
! 95: array("10"),
! 96: array("105", "5"),
! 97: array("/10.5"),
! 98: array("10.5/"),
! 99: array("10/10.gz"),
! 100: array("0"),
! 101: array('0'),
! 102:
! 103: /* paths and suffix given as same */
! 104: array("bar.gz", "bar.gz"),
! 105: array("/bar.gz", "/bar.gz"),
! 106: array("/bar.gz/", "/bar.gz/"),
! 107: array(" ", " "),
! 108: array(' ', ' '),
! 109: array(NULL, NULL),
! 110:
! 111: /* path with spaces */
! 112: array(" "),
! 113: array(' '),
! 114:
! 115: /* empty paths */
! 116: array(""),
! 117: array(''),
! 118: array(NULL)
! 119: );
! 120:
! 121: function check_basename( $path_arrays ) {
! 122: $loop_counter = 1;
! 123: foreach ($path_arrays as $path) {
! 124: echo "\n--Iteration $loop_counter--\n"; $loop_counter++;
! 125: if( 1 == count($path) ) { // no suffix provided
! 126: var_dump( basename($path[0]) );
! 127: } else { // path as well as suffix provided,
! 128: var_dump( basename($path[0], $path[1]) );
! 129: }
! 130: }
! 131: }
! 132:
! 133: echo "*** Testing basic operations ***\n";
! 134: check_basename( $file_paths );
! 135:
! 136: echo "\n*** Testing possible variations in path and suffix ***\n";
! 137: check_basename( $file_path_variations );
! 138:
! 139: echo "\n*** Testing error conditions ***\n";
! 140: // zero arguments
! 141: var_dump( basename() );
! 142:
! 143: // more than expected no. of arguments
! 144: var_dump( basename("/var/tmp/bar.gz", ".gz", ".gz") );
! 145:
! 146: // passing invalid type arguments
! 147: $object = new stdclass;
! 148: var_dump( basename( array("string/bar") ) );
! 149: var_dump( basename( array("string/bar"), "bar" ) );
! 150: var_dump( basename( "bar", array("string/bar") ) );
! 151: var_dump( basename( $object, "bar" ) );
! 152: var_dump( basename( $object ) );
! 153: var_dump( basename( $object, $object ) );
! 154: var_dump( basename( "bar", $object ) );
! 155:
! 156: echo "Done\n";
! 157: ?>
! 158: --EXPECTF--
! 159: *** Testing basic operations ***
! 160:
! 161: --Iteration 1--
! 162: string(3) "bar"
! 163:
! 164: --Iteration 2--
! 165: string(3) "bar"
! 166:
! 167: --Iteration 3--
! 168: string(3) "bar"
! 169:
! 170: --Iteration 4--
! 171: string(3) "bar"
! 172:
! 173: --Iteration 5--
! 174: string(3) "bar"
! 175:
! 176: --Iteration 6--
! 177: string(3) "bar"
! 178:
! 179: --Iteration 7--
! 180: string(3) "bar"
! 181:
! 182: --Iteration 8--
! 183: string(3) "bar"
! 184:
! 185: --Iteration 9--
! 186: string(3) "bar"
! 187:
! 188: --Iteration 10--
! 189: string(3) "bar"
! 190:
! 191: --Iteration 11--
! 192: string(6) "bar.gz"
! 193:
! 194: --Iteration 12--
! 195: string(3) "bar"
! 196:
! 197: --Iteration 13--
! 198: string(3) "bar"
! 199:
! 200: --Iteration 14--
! 201: string(3) "bar"
! 202:
! 203: --Iteration 15--
! 204: string(3) "bar"
! 205:
! 206: --Iteration 16--
! 207: string(3) "bar"
! 208:
! 209: --Iteration 17--
! 210: string(3) "bar"
! 211:
! 212: --Iteration 18--
! 213: string(3) "bar"
! 214:
! 215: --Iteration 19--
! 216: string(3) "bar"
! 217:
! 218: --Iteration 20--
! 219: string(3) ".gz"
! 220:
! 221: --Iteration 21--
! 222: string(3) ".gz"
! 223:
! 224: --Iteration 22--
! 225: string(3) ".gz"
! 226:
! 227: --Iteration 23--
! 228: string(3) ".gz"
! 229:
! 230: --Iteration 24--
! 231: string(3) ".gz"
! 232:
! 233: --Iteration 25--
! 234: string(3) ".gz"
! 235:
! 236: --Iteration 26--
! 237: string(7) "foo bar"
! 238:
! 239: --Iteration 27--
! 240: string(7) "foo bar"
! 241:
! 242: --Iteration 28--
! 243: string(7) "foo bar"
! 244:
! 245: --Iteration 29--
! 246: string(7) "foo bar"
! 247:
! 248: --Iteration 30--
! 249: string(4) "test"
! 250:
! 251: --Iteration 31--
! 252: string(3) "bar"
! 253:
! 254: --Iteration 32--
! 255: string(6) "bar.gz"
! 256:
! 257: *** Testing possible variations in path and suffix ***
! 258:
! 259: --Iteration 1--
! 260: string(3) "bar"
! 261:
! 262: --Iteration 2--
! 263: string(3) "bar"
! 264:
! 265: --Iteration 3--
! 266: string(3) "bar"
! 267:
! 268: --Iteration 4--
! 269: string(3) "bar"
! 270:
! 271: --Iteration 5--
! 272: string(3) "bar"
! 273:
! 274: --Iteration 6--
! 275: string(7) "bar.tar"
! 276:
! 277: --Iteration 7--
! 278: string(7) "bar.tar"
! 279:
! 280: --Iteration 8--
! 281: string(7) "bar.tar"
! 282:
! 283: --Iteration 9--
! 284: string(7) "bar.tar"
! 285:
! 286: --Iteration 10--
! 287: string(7) "bar.tar"
! 288:
! 289: --Iteration 11--
! 290: string(7) "bar.tar"
! 291:
! 292: --Iteration 12--
! 293: string(7) "bar.tar"
! 294:
! 295: --Iteration 13--
! 296: string(7) "bar.tar"
! 297:
! 298: --Iteration 14--
! 299: string(1) "t"
! 300:
! 301: --Iteration 15--
! 302: string(7) "tbar.gz"
! 303:
! 304: --Iteration 16--
! 305: string(7) "tbar.gz"
! 306:
! 307: --Iteration 17--
! 308: string(7) "tbar.gz"
! 309:
! 310: --Iteration 18--
! 311: string(7) "tbar.gz"
! 312:
! 313: --Iteration 19--
! 314: string(10) "My Pics.gz"
! 315:
! 316: --Iteration 20--
! 317: string(10) "My Pics.gz"
! 318:
! 319: --Iteration 21--
! 320: string(3) "My "
! 321:
! 322: --Iteration 22--
! 323: string(7) "My Pics"
! 324:
! 325: --Iteration 23--
! 326: string(10) "My Pics.gz"
! 327:
! 328: --Iteration 24--
! 329: string(10) "My Pics.gz"
! 330:
! 331: --Iteration 25--
! 332: string(10) "My Pics.gz"
! 333:
! 334: --Iteration 26--
! 335: string(10) "My Pics.gz"
! 336:
! 337: --Iteration 27--
! 338: string(10) "My Pics.gz"
! 339:
! 340: --Iteration 28--
! 341: string(4) "10.5"
! 342:
! 343: --Iteration 29--
! 344: string(2) "10"
! 345:
! 346: --Iteration 30--
! 347: string(4) "10.5"
! 348:
! 349: --Iteration 31--
! 350: string(2) "10"
! 351:
! 352: --Iteration 32--
! 353: string(2) "10"
! 354:
! 355: --Iteration 33--
! 356: string(4) "10.5"
! 357:
! 358: --Iteration 34--
! 359: string(4) "10.5"
! 360:
! 361: --Iteration 35--
! 362: string(5) "10.gz"
! 363:
! 364: --Iteration 36--
! 365: string(1) "0"
! 366:
! 367: --Iteration 37--
! 368: string(1) "0"
! 369:
! 370: --Iteration 38--
! 371: string(6) "bar.gz"
! 372:
! 373: --Iteration 39--
! 374: string(6) "bar.gz"
! 375:
! 376: --Iteration 40--
! 377: string(6) "bar.gz"
! 378:
! 379: --Iteration 41--
! 380: string(1) " "
! 381:
! 382: --Iteration 42--
! 383: string(1) " "
! 384:
! 385: --Iteration 43--
! 386: string(0) ""
! 387:
! 388: --Iteration 44--
! 389: string(1) " "
! 390:
! 391: --Iteration 45--
! 392: string(1) " "
! 393:
! 394: --Iteration 46--
! 395: string(0) ""
! 396:
! 397: --Iteration 47--
! 398: string(0) ""
! 399:
! 400: --Iteration 48--
! 401: string(0) ""
! 402:
! 403: *** Testing error conditions ***
! 404:
! 405: Warning: basename() expects at least 1 parameter, 0 given in %s on line %d
! 406: NULL
! 407:
! 408: Warning: basename() expects at most 2 parameters, 3 given in %s on line %d
! 409: NULL
! 410:
! 411: Warning: basename() expects parameter 1 to be string, array given in %s on line %d
! 412: NULL
! 413:
! 414: Warning: basename() expects parameter 1 to be string, array given in %s on line %d
! 415: NULL
! 416:
! 417: Warning: basename() expects parameter 2 to be string, array given in %s on line %d
! 418: NULL
! 419:
! 420: Warning: basename() expects parameter 1 to be string, object given in %s on line %d
! 421: NULL
! 422:
! 423: Warning: basename() expects parameter 1 to be string, object given in %s on line %d
! 424: NULL
! 425:
! 426: Warning: basename() expects parameter 1 to be string, object given in %s on line %d
! 427: NULL
! 428:
! 429: Warning: basename() expects parameter 2 to be string, object given in %s on line %d
! 430: NULL
! 431: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>