Annotation of embedaddon/php/ext/iconv/tests/iconv_mime_decode_variation3.phpt, revision 1.1.1.1

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

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