Annotation of embedaddon/php/ext/mbstring/tests/mb_substitute_character_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test mb_substitute_character() function : usage variation
3: --SKIPIF--
4: <?php
5: extension_loaded('mbstring') or die('skip');
6: function_exists('mb_substitute_character') or die("skip mb_substitute_character() is not available in this build");
7: ?>
8: --FILE--
9: <?php
10: /* Prototype : mixed mb_substitute_character([mixed substchar])
11: * Description: Sets the current substitute_character or returns the current substitute_character
12: * Source code: ext/mbstring/mbstring.c
13: * Alias to functions:
14: */
15:
16: echo "*** Testing mb_substitute_character() : usage variation ***\n";
17:
18: // Define error handler
19: function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
20: if (error_reporting() != 0) {
21: // report non-silenced errors
22: echo "Error: $err_no - $err_msg, $filename($linenum)\n";
23: }
24: }
25: set_error_handler('test_error_handler');
26:
27: // Initialise function arguments not being substituted (if any)
28:
29: //get an unset variable
30: $unset_var = 10;
31: unset ($unset_var);
32:
33: // define some classes
34: class classWithToString
35: {
36: public function __toString() {
37: return "Class A object";
38: }
39: }
40:
41: class classWithoutToString
42: {
43: }
44:
45: // heredoc string
46: $heredoc = <<<EOT
47: hello world
48: EOT;
49:
50: // get a resource variable
51: $fp = fopen(__FILE__, "r");
52:
53: // add arrays
54: $index_array = array (1, 2, 3);
55: $assoc_array = array ('one' => 1, 'two' => 2);
56:
57: //array of values to iterate over
58: $inputs = array(
59:
60: // int data
61: 'int 0' => 0,
62: 'int 1' => 1,
63: 'int 12345' => 12345,
64: 'int -12345' => -2345,
65:
66: // float data
67: 'float 10.5' => 10.5,
68: 'float -10.5' => -10.5,
69: 'float 12.3456789000e10' => 12.3456789000e10,
70: 'float -12.3456789000e10' => -12.3456789000e10,
71: 'float .5' => .5,
72:
73: // array data
74: 'empty array' => array(),
75: 'int indexed array' => $index_array,
76: 'associative array' => $assoc_array,
77: 'nested arrays' => array('foo', $index_array, $assoc_array),
78:
79: // null data
80: 'uppercase NULL' => NULL,
81: 'lowercase null' => null,
82:
83: // boolean data
84: 'lowercase true' => true,
85: 'lowercase false' =>false,
86: 'uppercase TRUE' =>TRUE,
87: 'uppercase FALSE' =>FALSE,
88:
89: // empty data
90: 'empty string DQ' => "",
91: 'empty string SQ' => '',
92:
93: // string data
94: 'string DQ' => "string",
95: 'string SQ' => 'string',
96: 'mixed case string' => "sTrInG",
97: 'heredoc' => $heredoc,
98:
99: // object data
100: 'instance of classWithToString' => new classWithToString(),
101: 'instance of classWithoutToString' => new classWithoutToString(),
102:
103: // undefined data
104: 'undefined var' => @$undefined_var,
105:
106: // unset data
107: 'unset var' => @$unset_var,
108: );
109:
110: // loop through each element of the array for substchar
111:
112: mb_internal_encoding('utf-8');
113: foreach($inputs as $key =>$value) {
114: echo "\n--$key--\n";
115: var_dump( mb_substitute_character($value) );
116: };
117:
118: fclose($fp);
119:
120: ?>
121: ===DONE===
122: --EXPECTF--
123: *** Testing mb_substitute_character() : usage variation ***
124:
125: --int 0--
126: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
127: bool(false)
128:
129: --int 1--
130: bool(true)
131:
132: --int 12345--
133: bool(true)
134:
135: --int -12345--
136: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
137: bool(false)
138:
139: --float 10.5--
140: bool(true)
141:
142: --float -10.5--
143: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
144: bool(false)
145:
146: --float 12.3456789000e10--
147: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
148: bool(false)
149:
150: --float -12.3456789000e10--
151: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
152: bool(false)
153:
154: --float .5--
155: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
156: bool(false)
157:
158: --empty array--
159: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
160: bool(false)
161:
162: --int indexed array--
163: bool(true)
164:
165: --associative array--
166: bool(true)
167:
168: --nested arrays--
169: bool(true)
170:
171: --uppercase NULL--
172: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
173: bool(false)
174:
175: --lowercase null--
176: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
177: bool(false)
178:
179: --lowercase true--
180: bool(true)
181:
182: --lowercase false--
183: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
184: bool(false)
185:
186: --uppercase TRUE--
187: bool(true)
188:
189: --uppercase FALSE--
190: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
191: bool(false)
192:
193: --empty string DQ--
194: bool(true)
195:
196: --empty string SQ--
197: bool(true)
198:
199: --string DQ--
200: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
201: bool(false)
202:
203: --string SQ--
204: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
205: bool(false)
206:
207: --mixed case string--
208: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
209: bool(false)
210:
211: --heredoc--
212: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
213: bool(false)
214:
215: --instance of classWithToString--
216: Error: 8 - Object of class classWithToString could not be converted to int, %s(%d)
217: bool(true)
218:
219: --instance of classWithoutToString--
220: Error: 8 - Object of class classWithoutToString could not be converted to int, %s(%d)
221: bool(true)
222:
223: --undefined var--
224: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
225: bool(false)
226:
227: --unset var--
228: Error: 2 - mb_substitute_character(): Unknown character., %s(%d)
229: bool(false)
230: ===DONE===
231:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>