Annotation of embedaddon/php/ext/mbstring/tests/mb_stripos_variation4.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test mb_stripos() function : usage variations - pass different data types as $encoding arg
                      3: --SKIPIF--
                      4: <?php
                      5: extension_loaded('mbstring') or die('skip');
                      6: function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build");
                      7: ?>
                      8: --FILE--
                      9: <?php
                     10: /* Prototype  : int mb_stripos(string haystack, string needle [, int offset [, string encoding]])
                     11:  * Description: Finds position of first occurrence of a string within another, case insensitive 
                     12:  * Source code: ext/mbstring/mbstring.c
                     13:  * Alias to functions: 
                     14:  */
                     15: 
                     16: /*
                     17:  * Pass mb_stripos different data types as $encoding arg to test behaviour
                     18:  * Where possible 'UTF-8' has been entered as a string value
                     19:  */
                     20: 
                     21: echo "*** Testing mb_stripos() : usage variations ***\n";
                     22: 
                     23: // Initialise function arguments not being substituted
                     24: $haystack = b'string_val';
                     25: $needle = b'VaL';
                     26: $offset = 0;
                     27: 
                     28: //get an unset variable
                     29: $unset_var = 10;
                     30: unset ($unset_var);
                     31: 
                     32: // get a class
                     33: class classA
                     34: {
                     35:   public function __toString() {
                     36:     return "UTF-8";
                     37:   }
                     38: }
                     39: 
                     40: // heredoc string
                     41: $heredoc = <<<EOT
                     42: UTF-8
                     43: EOT;
                     44: 
                     45: // get a resource variable
                     46: $fp = fopen(__FILE__, "r");
                     47: 
                     48: // unexpected values to be passed to $input argument
                     49: $inputs = array(
                     50: 
                     51:        // int data
                     52: /*1*/  0,
                     53:        1,
                     54:        12345,
                     55:        -2345,
                     56: 
                     57:        // float data
                     58: /*5*/  10.5,
                     59:        -10.5,
                     60:        12.3456789000e10,
                     61:        12.3456789000E-10,
                     62:        .5,
                     63: 
                     64:        // null data
                     65: /*10*/ NULL,
                     66:        null,
                     67: 
                     68:        // boolean data
                     69: /*12*/ true,
                     70:        false,
                     71:        TRUE,
                     72:        FALSE,
                     73:        
                     74:        // empty data
                     75: /*16*/ "",
                     76:        '',
                     77: 
                     78:        // string data
                     79: /*18*/ "UTF-8",
                     80:        'UTF-8',
                     81:        $heredoc,
                     82:        
                     83:        // object data
                     84: /*21*/ new classA(),
                     85: 
                     86:        // undefined data
                     87: /*22*/ @$undefined_var,
                     88: 
                     89:        // unset data
                     90: /*23*/ @$unset_var,
                     91: 
                     92:        // resource variable
                     93: /*24*/ $fp
                     94: );
                     95: 
                     96: // loop through each element of $inputs to check the behavior of mb_stripos()
                     97: $iterator = 1;
                     98: foreach($inputs as $input) {
                     99:   echo "\n-- Iteration $iterator --\n";
                    100:   var_dump( mb_stripos($haystack, $needle, $offset, $input));
                    101:   $iterator++;
                    102: };
                    103: 
                    104: fclose($fp);
                    105: 
                    106: echo "Done";
                    107: ?>
                    108: 
                    109: --EXPECTF--
                    110: *** Testing mb_stripos() : usage variations ***
                    111: 
                    112: -- Iteration 1 --
                    113: 
                    114: Warning: mb_stripos(): Unknown encoding "0" in %s on line %d
                    115: bool(false)
                    116: 
                    117: -- Iteration 2 --
                    118: 
                    119: Warning: mb_stripos(): Unknown encoding "1" in %s on line %d
                    120: bool(false)
                    121: 
                    122: -- Iteration 3 --
                    123: 
                    124: Warning: mb_stripos(): Unknown encoding "12345" in %s on line %d
                    125: bool(false)
                    126: 
                    127: -- Iteration 4 --
                    128: 
                    129: Warning: mb_stripos(): Unknown encoding "-2345" in %s on line %d
                    130: bool(false)
                    131: 
                    132: -- Iteration 5 --
                    133: 
                    134: Warning: mb_stripos(): Unknown encoding "10.5" in %s on line %d
                    135: bool(false)
                    136: 
                    137: -- Iteration 6 --
                    138: 
                    139: Warning: mb_stripos(): Unknown encoding "-10.5" in %s on line %d
                    140: bool(false)
                    141: 
                    142: -- Iteration 7 --
                    143: 
                    144: Warning: mb_stripos(): Unknown encoding "123456789000" in %s on line %d
                    145: bool(false)
                    146: 
                    147: -- Iteration 8 --
                    148: 
                    149: Warning: mb_stripos(): Unknown encoding "1.23456789E-9" in %s on line %d
                    150: bool(false)
                    151: 
                    152: -- Iteration 9 --
                    153: 
                    154: Warning: mb_stripos(): Unknown encoding "0.5" in %s on line %d
                    155: bool(false)
                    156: 
                    157: -- Iteration 10 --
                    158: 
                    159: Warning: mb_stripos(): Unknown encoding "" in %s on line %d
                    160: bool(false)
                    161: 
                    162: -- Iteration 11 --
                    163: 
                    164: Warning: mb_stripos(): Unknown encoding "" in %s on line %d
                    165: bool(false)
                    166: 
                    167: -- Iteration 12 --
                    168: 
                    169: Warning: mb_stripos(): Unknown encoding "1" in %s on line %d
                    170: bool(false)
                    171: 
                    172: -- Iteration 13 --
                    173: 
                    174: Warning: mb_stripos(): Unknown encoding "" in %s on line %d
                    175: bool(false)
                    176: 
                    177: -- Iteration 14 --
                    178: 
                    179: Warning: mb_stripos(): Unknown encoding "1" in %s on line %d
                    180: bool(false)
                    181: 
                    182: -- Iteration 15 --
                    183: 
                    184: Warning: mb_stripos(): Unknown encoding "" in %s on line %d
                    185: bool(false)
                    186: 
                    187: -- Iteration 16 --
                    188: 
                    189: Warning: mb_stripos(): Unknown encoding "" in %s on line %d
                    190: bool(false)
                    191: 
                    192: -- Iteration 17 --
                    193: 
                    194: Warning: mb_stripos(): Unknown encoding "" in %s on line %d
                    195: bool(false)
                    196: 
                    197: -- Iteration 18 --
                    198: int(7)
                    199: 
                    200: -- Iteration 19 --
                    201: int(7)
                    202: 
                    203: -- Iteration 20 --
                    204: int(7)
                    205: 
                    206: -- Iteration 21 --
                    207: int(7)
                    208: 
                    209: -- Iteration 22 --
                    210: 
                    211: Warning: mb_stripos(): Unknown encoding "" in %s on line %d
                    212: bool(false)
                    213: 
                    214: -- Iteration 23 --
                    215: 
                    216: Warning: mb_stripos(): Unknown encoding "" in %s on line %d
                    217: bool(false)
                    218: 
                    219: -- Iteration 24 --
                    220: 
                    221: Warning: mb_stripos() expects parameter 4 to be string, resource given in %s on line %d
                    222: bool(false)
                    223: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>