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