Annotation of embedaddon/php/ext/standard/tests/file/pathinfo_variaton.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test pathinfo() function: usage variations
! 3: --FILE--
! 4: <?php
! 5: /* Prototype: mixed pathinfo ( string $path [, int $options] );
! 6: Description: Returns information about a file path
! 7: */
! 8:
! 9: echo "*** Testing pathinfo() with miscelleneous input arguments ***\n";
! 10:
! 11: $fp = fopen(__FILE__, "r");
! 12: unset($fp);
! 13:
! 14: class object_temp {
! 15: public $url_var = "www.foo.com";
! 16: var $html_var = "/var/html/testdir/example.html";
! 17: var $dir_var = "/testdir/foo/test/";
! 18: public $file_var = "/foo//symlink.link";
! 19: var $number = 12345;
! 20: }
! 21: $obj = new object_temp();
! 22:
! 23: $path_arr = array (
! 24: "www.example.com",
! 25: "/testdir/foo//test/",
! 26: "../foo/test.link",
! 27: "./test/work/scratch/mydir/yourdir/ourdir/test1/test2/test3/test4/test5/test6/test.tmp",
! 28: 2.345
! 29: );
! 30:
! 31: $paths = array (
! 32: /* pathname containing numeric string */
! 33: 0,
! 34: 1234,
! 35: -1234,
! 36: 2.3456,
! 37:
! 38: /* pathname as boolean */
! 39: TRUE,
! 40: FALSE,
! 41:
! 42: /* pathname as an array */
! 43: "./array(1, 2)",
! 44: "array( array(), null)",
! 45:
! 46: /* pathname as object */
! 47: $obj,
! 48:
! 49: /* pathname as spaces */
! 50: " ",
! 51: ' ',
! 52:
! 53: /* empty pathname */
! 54: "",
! 55: '',
! 56:
! 57: /* pathname as NULL */
! 58: NULL,
! 59: null,
! 60:
! 61: /* filename as resource */
! 62: $fp,
! 63:
! 64: /* pathname as members of object */
! 65: $obj->url_var,
! 66: $obj->html_var,
! 67: $obj->dir_var,
! 68: $obj->file_var,
! 69: $obj->number,
! 70:
! 71: /* pathname as member of array */
! 72: $path_arr[0],
! 73: $path_arr[1],
! 74: $path_arr[2],
! 75: $path_arr[3],
! 76: $path_arr[4]
! 77: );
! 78:
! 79: $counter = 1;
! 80: /* loop through $paths to test each $path in the above array */
! 81: foreach($paths as $path) {
! 82: echo "-- Iteration $counter --\n";
! 83: var_dump( pathinfo($path) );
! 84: var_dump( pathinfo($path, PATHINFO_DIRNAME) );
! 85: var_dump( pathinfo($path, PATHINFO_BASENAME) );
! 86: var_dump( pathinfo($path, PATHINFO_EXTENSION) );
! 87: var_dump( pathinfo($path, PATHINFO_FILENAME) );
! 88: $counter++;
! 89: }
! 90:
! 91: echo "Done\n";
! 92: ?>
! 93: --EXPECTF--
! 94: *** Testing pathinfo() with miscelleneous input arguments ***
! 95:
! 96: Notice: Undefined variable: fp in %s on line %d
! 97: -- Iteration 1 --
! 98: array(3) {
! 99: ["dirname"]=>
! 100: string(1) "."
! 101: ["basename"]=>
! 102: string(1) "0"
! 103: ["filename"]=>
! 104: string(1) "0"
! 105: }
! 106: string(1) "."
! 107: string(1) "0"
! 108: string(0) ""
! 109: string(1) "0"
! 110: -- Iteration 2 --
! 111: array(3) {
! 112: ["dirname"]=>
! 113: string(1) "."
! 114: ["basename"]=>
! 115: string(4) "1234"
! 116: ["filename"]=>
! 117: string(4) "1234"
! 118: }
! 119: string(1) "."
! 120: string(4) "1234"
! 121: string(0) ""
! 122: string(4) "1234"
! 123: -- Iteration 3 --
! 124: array(3) {
! 125: ["dirname"]=>
! 126: string(1) "."
! 127: ["basename"]=>
! 128: string(5) "-1234"
! 129: ["filename"]=>
! 130: string(5) "-1234"
! 131: }
! 132: string(1) "."
! 133: string(5) "-1234"
! 134: string(0) ""
! 135: string(5) "-1234"
! 136: -- Iteration 4 --
! 137: array(4) {
! 138: ["dirname"]=>
! 139: string(1) "."
! 140: ["basename"]=>
! 141: string(6) "2.3456"
! 142: ["extension"]=>
! 143: string(4) "3456"
! 144: ["filename"]=>
! 145: string(1) "2"
! 146: }
! 147: string(1) "."
! 148: string(6) "2.3456"
! 149: string(4) "3456"
! 150: string(1) "2"
! 151: -- Iteration 5 --
! 152: array(3) {
! 153: ["dirname"]=>
! 154: string(1) "."
! 155: ["basename"]=>
! 156: string(1) "1"
! 157: ["filename"]=>
! 158: string(1) "1"
! 159: }
! 160: string(1) "."
! 161: string(1) "1"
! 162: string(0) ""
! 163: string(1) "1"
! 164: -- Iteration 6 --
! 165: array(2) {
! 166: ["basename"]=>
! 167: string(0) ""
! 168: ["filename"]=>
! 169: string(0) ""
! 170: }
! 171: string(0) ""
! 172: string(0) ""
! 173: string(0) ""
! 174: string(0) ""
! 175: -- Iteration 7 --
! 176: array(3) {
! 177: ["dirname"]=>
! 178: string(1) "."
! 179: ["basename"]=>
! 180: string(11) "array(1, 2)"
! 181: ["filename"]=>
! 182: string(11) "array(1, 2)"
! 183: }
! 184: string(1) "."
! 185: string(11) "array(1, 2)"
! 186: string(0) ""
! 187: string(11) "array(1, 2)"
! 188: -- Iteration 8 --
! 189: array(3) {
! 190: ["dirname"]=>
! 191: string(1) "."
! 192: ["basename"]=>
! 193: string(21) "array( array(), null)"
! 194: ["filename"]=>
! 195: string(21) "array( array(), null)"
! 196: }
! 197: string(1) "."
! 198: string(21) "array( array(), null)"
! 199: string(0) ""
! 200: string(21) "array( array(), null)"
! 201: -- Iteration 9 --
! 202:
! 203: Warning: pathinfo() expects parameter 1 to be string, object given in %s on line %d
! 204: NULL
! 205:
! 206: Warning: pathinfo() expects parameter 1 to be string, object given in %s on line %d
! 207: NULL
! 208:
! 209: Warning: pathinfo() expects parameter 1 to be string, object given in %s on line %d
! 210: NULL
! 211:
! 212: Warning: pathinfo() expects parameter 1 to be string, object given in %s on line %d
! 213: NULL
! 214:
! 215: Warning: pathinfo() expects parameter 1 to be string, object given in %s on line %d
! 216: NULL
! 217: -- Iteration 10 --
! 218: array(3) {
! 219: ["dirname"]=>
! 220: string(1) "."
! 221: ["basename"]=>
! 222: string(1) " "
! 223: ["filename"]=>
! 224: string(1) " "
! 225: }
! 226: string(1) "."
! 227: string(1) " "
! 228: string(0) ""
! 229: string(1) " "
! 230: -- Iteration 11 --
! 231: array(3) {
! 232: ["dirname"]=>
! 233: string(1) "."
! 234: ["basename"]=>
! 235: string(1) " "
! 236: ["filename"]=>
! 237: string(1) " "
! 238: }
! 239: string(1) "."
! 240: string(1) " "
! 241: string(0) ""
! 242: string(1) " "
! 243: -- Iteration 12 --
! 244: array(2) {
! 245: ["basename"]=>
! 246: string(0) ""
! 247: ["filename"]=>
! 248: string(0) ""
! 249: }
! 250: string(0) ""
! 251: string(0) ""
! 252: string(0) ""
! 253: string(0) ""
! 254: -- Iteration 13 --
! 255: array(2) {
! 256: ["basename"]=>
! 257: string(0) ""
! 258: ["filename"]=>
! 259: string(0) ""
! 260: }
! 261: string(0) ""
! 262: string(0) ""
! 263: string(0) ""
! 264: string(0) ""
! 265: -- Iteration 14 --
! 266: array(2) {
! 267: ["basename"]=>
! 268: string(0) ""
! 269: ["filename"]=>
! 270: string(0) ""
! 271: }
! 272: string(0) ""
! 273: string(0) ""
! 274: string(0) ""
! 275: string(0) ""
! 276: -- Iteration 15 --
! 277: array(2) {
! 278: ["basename"]=>
! 279: string(0) ""
! 280: ["filename"]=>
! 281: string(0) ""
! 282: }
! 283: string(0) ""
! 284: string(0) ""
! 285: string(0) ""
! 286: string(0) ""
! 287: -- Iteration 16 --
! 288: array(2) {
! 289: ["basename"]=>
! 290: string(0) ""
! 291: ["filename"]=>
! 292: string(0) ""
! 293: }
! 294: string(0) ""
! 295: string(0) ""
! 296: string(0) ""
! 297: string(0) ""
! 298: -- Iteration 17 --
! 299: array(4) {
! 300: ["dirname"]=>
! 301: string(1) "."
! 302: ["basename"]=>
! 303: string(11) "www.foo.com"
! 304: ["extension"]=>
! 305: string(3) "com"
! 306: ["filename"]=>
! 307: string(7) "www.foo"
! 308: }
! 309: string(1) "."
! 310: string(11) "www.foo.com"
! 311: string(3) "com"
! 312: string(7) "www.foo"
! 313: -- Iteration 18 --
! 314: array(4) {
! 315: ["dirname"]=>
! 316: string(17) "/var/html/testdir"
! 317: ["basename"]=>
! 318: string(12) "example.html"
! 319: ["extension"]=>
! 320: string(4) "html"
! 321: ["filename"]=>
! 322: string(7) "example"
! 323: }
! 324: string(17) "/var/html/testdir"
! 325: string(12) "example.html"
! 326: string(4) "html"
! 327: string(7) "example"
! 328: -- Iteration 19 --
! 329: array(3) {
! 330: ["dirname"]=>
! 331: string(12) "/testdir/foo"
! 332: ["basename"]=>
! 333: string(4) "test"
! 334: ["filename"]=>
! 335: string(4) "test"
! 336: }
! 337: string(12) "/testdir/foo"
! 338: string(4) "test"
! 339: string(0) ""
! 340: string(4) "test"
! 341: -- Iteration 20 --
! 342: array(4) {
! 343: ["dirname"]=>
! 344: string(4) "/foo"
! 345: ["basename"]=>
! 346: string(12) "symlink.link"
! 347: ["extension"]=>
! 348: string(4) "link"
! 349: ["filename"]=>
! 350: string(7) "symlink"
! 351: }
! 352: string(4) "/foo"
! 353: string(12) "symlink.link"
! 354: string(4) "link"
! 355: string(7) "symlink"
! 356: -- Iteration 21 --
! 357: array(3) {
! 358: ["dirname"]=>
! 359: string(1) "."
! 360: ["basename"]=>
! 361: string(5) "12345"
! 362: ["filename"]=>
! 363: string(5) "12345"
! 364: }
! 365: string(1) "."
! 366: string(5) "12345"
! 367: string(0) ""
! 368: string(5) "12345"
! 369: -- Iteration 22 --
! 370: array(4) {
! 371: ["dirname"]=>
! 372: string(1) "."
! 373: ["basename"]=>
! 374: string(15) "www.example.com"
! 375: ["extension"]=>
! 376: string(3) "com"
! 377: ["filename"]=>
! 378: string(11) "www.example"
! 379: }
! 380: string(1) "."
! 381: string(15) "www.example.com"
! 382: string(3) "com"
! 383: string(11) "www.example"
! 384: -- Iteration 23 --
! 385: array(3) {
! 386: ["dirname"]=>
! 387: string(12) "/testdir/foo"
! 388: ["basename"]=>
! 389: string(4) "test"
! 390: ["filename"]=>
! 391: string(4) "test"
! 392: }
! 393: string(12) "/testdir/foo"
! 394: string(4) "test"
! 395: string(0) ""
! 396: string(4) "test"
! 397: -- Iteration 24 --
! 398: array(4) {
! 399: ["dirname"]=>
! 400: string(6) "../foo"
! 401: ["basename"]=>
! 402: string(9) "test.link"
! 403: ["extension"]=>
! 404: string(4) "link"
! 405: ["filename"]=>
! 406: string(4) "test"
! 407: }
! 408: string(6) "../foo"
! 409: string(9) "test.link"
! 410: string(4) "link"
! 411: string(4) "test"
! 412: -- Iteration 25 --
! 413: array(4) {
! 414: ["dirname"]=>
! 415: string(76) "./test/work/scratch/mydir/yourdir/ourdir/test1/test2/test3/test4/test5/test6"
! 416: ["basename"]=>
! 417: string(8) "test.tmp"
! 418: ["extension"]=>
! 419: string(3) "tmp"
! 420: ["filename"]=>
! 421: string(4) "test"
! 422: }
! 423: string(76) "./test/work/scratch/mydir/yourdir/ourdir/test1/test2/test3/test4/test5/test6"
! 424: string(8) "test.tmp"
! 425: string(3) "tmp"
! 426: string(4) "test"
! 427: -- Iteration 26 --
! 428: array(4) {
! 429: ["dirname"]=>
! 430: string(1) "."
! 431: ["basename"]=>
! 432: string(5) "2.345"
! 433: ["extension"]=>
! 434: string(3) "345"
! 435: ["filename"]=>
! 436: string(1) "2"
! 437: }
! 438: string(1) "."
! 439: string(5) "2.345"
! 440: string(3) "345"
! 441: string(1) "2"
! 442: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>