Annotation of embedaddon/php/ext/mbstring/tests/mb_encode_mimeheader_variation2.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test mb_encode_mimeheader() function : usage variations - Pass different data types to $charset arg
! 3: --SKIPIF--
! 4: <?php
! 5: extension_loaded('mbstring') or die('skip');
! 6: function_exists('mb_encode_mimeheader') or die("skip mb_encode_mimeheader() is not available in this build");
! 7: ?>
! 8: --FILE--
! 9: <?php
! 10: /* Prototype : string mb_encode_mimeheader
! 11: * (string $str [, string $charset [, string $transfer_encoding [, string $linefeed [, int $indent]]]])
! 12: * Description: Converts the string to MIME "encoded-word" in the format of =?charset?(B|Q)?encoded_string?=
! 13: * Source code: ext/mbstring/mbstring.c
! 14: */
! 15:
! 16: /*
! 17: * Pass different data types to $charset argument to see how mb_encode_mimeheader() behaves
! 18: */
! 19:
! 20: echo "*** Testing mb_encode_mimeheader() : usage variations ***\n";
! 21:
! 22: mb_internal_encoding('utf-8');
! 23:
! 24: // Initialise function arguments not being substituted
! 25: $str = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC');
! 26: $transfer_encoding = 'B';
! 27: $linefeed = "\r\n";
! 28: $indent = 2;
! 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 "UTF-8";
! 39: }
! 40: }
! 41:
! 42: // heredoc string
! 43: $heredoc = <<<EOT
! 44: utf-8
! 45: EOT;
! 46:
! 47: // get a resource variable
! 48: $fp = fopen(__FILE__, "r");
! 49:
! 50: // unexpected values to be passed to $charset 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*/ "utf-8",
! 82: 'utf-8',
! 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 mb_encode_mimeheader()
! 99: $iterator = 1;
! 100: foreach($inputs as $input) {
! 101: echo "\n-- Iteration $iterator --\n";
! 102: var_dump( mb_encode_mimeheader($str, $input, $transfer_encoding, $linefeed, $indent));
! 103: $iterator++;
! 104: };
! 105:
! 106: fclose($fp);
! 107:
! 108: echo "Done";
! 109: ?>
! 110: --EXPECTF--
! 111: *** Testing mb_encode_mimeheader() : usage variations ***
! 112:
! 113: -- Iteration 1 --
! 114:
! 115: Warning: mb_encode_mimeheader(): Unknown encoding "0" in %s on line %d
! 116: bool(false)
! 117:
! 118: -- Iteration 2 --
! 119:
! 120: Warning: mb_encode_mimeheader(): Unknown encoding "1" in %s on line %d
! 121: bool(false)
! 122:
! 123: -- Iteration 3 --
! 124:
! 125: Warning: mb_encode_mimeheader(): Unknown encoding "12345" in %s on line %d
! 126: bool(false)
! 127:
! 128: -- Iteration 4 --
! 129:
! 130: Warning: mb_encode_mimeheader(): Unknown encoding "-2345" in %s on line %d
! 131: bool(false)
! 132:
! 133: -- Iteration 5 --
! 134:
! 135: Warning: mb_encode_mimeheader(): Unknown encoding "10.5" in %s on line %d
! 136: bool(false)
! 137:
! 138: -- Iteration 6 --
! 139:
! 140: Warning: mb_encode_mimeheader(): Unknown encoding "-10.5" in %s on line %d
! 141: bool(false)
! 142:
! 143: -- Iteration 7 --
! 144:
! 145: Warning: mb_encode_mimeheader(): Unknown encoding "123456789000" in %s on line %d
! 146: bool(false)
! 147:
! 148: -- Iteration 8 --
! 149:
! 150: Warning: mb_encode_mimeheader(): Unknown encoding "1.23456789E-9" in %s on line %d
! 151: bool(false)
! 152:
! 153: -- Iteration 9 --
! 154:
! 155: Warning: mb_encode_mimeheader(): Unknown encoding "0.5" in %s on line %d
! 156: bool(false)
! 157:
! 158: -- Iteration 10 --
! 159:
! 160: Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
! 161: bool(false)
! 162:
! 163: -- Iteration 11 --
! 164:
! 165: Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
! 166: bool(false)
! 167:
! 168: -- Iteration 12 --
! 169:
! 170: Warning: mb_encode_mimeheader(): Unknown encoding "1" in %s on line %d
! 171: bool(false)
! 172:
! 173: -- Iteration 13 --
! 174:
! 175: Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
! 176: bool(false)
! 177:
! 178: -- Iteration 14 --
! 179:
! 180: Warning: mb_encode_mimeheader(): Unknown encoding "1" in %s on line %d
! 181: bool(false)
! 182:
! 183: -- Iteration 15 --
! 184:
! 185: Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
! 186: bool(false)
! 187:
! 188: -- Iteration 16 --
! 189:
! 190: Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
! 191: bool(false)
! 192:
! 193: -- Iteration 17 --
! 194:
! 195: Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
! 196: bool(false)
! 197:
! 198: -- Iteration 18 --
! 199: string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
! 200:
! 201: -- Iteration 19 --
! 202: string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
! 203:
! 204: -- Iteration 20 --
! 205: string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
! 206:
! 207: -- Iteration 21 --
! 208: string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
! 209:
! 210: -- Iteration 22 --
! 211:
! 212: Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
! 213: bool(false)
! 214:
! 215: -- Iteration 23 --
! 216:
! 217: Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
! 218: bool(false)
! 219:
! 220: -- Iteration 24 --
! 221:
! 222: Warning: mb_encode_mimeheader() expects parameter 2 to be string, resource given in %s on line %d
! 223: NULL
! 224: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>