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

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

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