test cleanups
[plcapi.git] / tests / 1ParsingBugsTest.php
1 <?php
2 /**
3  * NB: do not let your IDE fool you. The correct encoding for this file is NOT UTF8.
4  */
5 include_once __DIR__ . '/../lib/xmlrpc.inc';
6 include_once __DIR__ . '/../lib/xmlrpcs.inc';
7
8 include_once __DIR__ . '/parse_args.php';
9
10 include_once __DIR__ . '/PolyfillTestCase.php';
11
12 use PHPUnit\Runner\BaseTestRunner;
13
14 /**
15  * Tests involving parsing of xml and handling of xmlrpc values
16  */
17 class ParsingBugsTests extends PhpXmlRpc_PolyfillTestCase
18 {
19     public $args = array();
20
21     protected function set_up()
22     {
23         $this->args = argParser::getArgs();
24         if ($this->args['DEBUG'] == 1)
25             ob_start();
26     }
27
28     protected function tear_down()
29     {
30         if ($this->args['DEBUG'] != 1)
31             return;
32         $out = ob_get_clean();
33         $status = $this->getStatus();
34         if ($status == BaseTestRunner::STATUS_ERROR
35             || $status == BaseTestRunner::STATUS_FAILURE) {
36             echo $out;
37         }
38     }
39
40     protected function newMsg($methodName, $params = array())
41     {
42         $msg = new xmlrpcmsg($methodName, $params);
43         $msg->setDebug($this->args['DEBUG']);
44         return $msg;
45     }
46
47     public function testMinusOneString()
48     {
49         $v = new xmlrpcval('-1');
50         $u = new xmlrpcval('-1', 'string');
51         $t = new xmlrpcval(-1, 'string');
52         $this->assertEquals($v->scalarval(), $u->scalarval());
53         $this->assertEquals($v->scalarval(), $t->scalarval());
54     }
55
56     /**
57      * This looks funny, and we might call it a bug. But we strive for 100 backwards compat...
58      */
59     public function testMinusOneInt()
60     {
61         $u = new xmlrpcval();
62         $v = new xmlrpcval(-1);
63         $this->assertEquals($u->scalarval(), $v->scalarval());
64     }
65
66     public function testUnicodeInMemberName()
67     {
68         $str = "G" . chr(252) . "nter, El" . chr(232) . "ne";
69         $v = array($str => new xmlrpcval(1));
70         $r = new xmlrpcresp(new xmlrpcval($v, 'struct'));
71         $r = $r->serialize();
72         $m = $this->newMsg('dummy');
73         $r = $m->parseResponse($r);
74         $v = $r->value();
75         $this->assertEquals(true, $v->structmemexists($str));
76     }
77
78     public function testUnicodeInErrorString()
79     {
80         $response = utf8_encode(
81             '<?xml version="1.0"?>
82 <!-- $Id -->
83 <!-- found by G. Giunta, covers what happens when lib receives UTF8 chars in response text and comments -->
84 <!-- ' . chr(224) . chr(252) . chr(232) . '&#224;&#252;&#232; -->
85 <methodResponse>
86 <fault>
87 <value>
88 <struct>
89 <member>
90 <name>faultCode</name>
91 <value><int>888</int></value>
92 </member>
93 <member>
94 <name>faultString</name>
95 <value><string>' . chr(224) . chr(252) . chr(232) . '&#224;&#252;&#232;</string></value>
96 </member>
97 </struct>
98 </value>
99 </fault>
100 </methodResponse>');
101         $m = $this->newMsg('dummy');
102         $r = $m->parseResponse($response);
103         $v = $r->faultString();
104         $this->assertEquals(chr(224) . chr(252) . chr(232) . chr(224) . chr(252) . chr(232), $v);
105     }
106
107     public function testValidNumbers()
108     {
109         $m = $this->newMsg('dummy');
110         $fp =
111             '<?xml version="1.0"?>
112 <methodResponse>
113 <params>
114 <param>
115 <value>
116 <struct>
117 <member>
118 <name>integer1</name>
119 <value><int>01</int></value>
120 </member>
121 <member>
122 <name>integer2</name>
123 <value><int>+1</int></value>
124 </member>
125 <member>
126 <name>integer3</name>
127 <value><i4>1</i4></value>
128 </member>
129 <member>
130 <name>float1</name>
131 <value><double>01.10</double></value>
132 </member>
133 <member>
134 <name>float2</name>
135 <value><double>+1.10</double></value>
136 </member>
137 <member>
138 <name>float3</name>
139 <value><double>-1.10e2</double></value>
140 </member>
141 </struct>
142 </value>
143 </param>
144 </params>
145 </methodResponse>';
146         $r = $m->parseResponse($fp);
147         $v = $r->value();
148         $s = $v->structmem('integer1');
149         $t = $v->structmem('integer2');
150         $u = $v->structmem('integer3');
151         $x = $v->structmem('float1');
152         $y = $v->structmem('float2');
153         $z = $v->structmem('float3');
154         $this->assertEquals(1, $s->scalarval());
155         $this->assertEquals(1, $t->scalarval());
156         $this->assertEquals(1, $u->scalarval());
157
158         $this->assertEquals(1.1, $x->scalarval());
159         $this->assertEquals(1.1, $y->scalarval());
160         $this->assertEquals(-110.0, $z->scalarval());
161     }
162
163     public function testI8()
164     {
165         if (PHP_INT_SIZE == 4 ) {
166             $this->markTestSkipped('Can not test i8 as php is compiled in 32 bit mode');
167             return;
168         }
169
170         $m = $this->newMsg('dummy');
171         $fp =
172             '<?xml version="1.0"?>
173 <methodResponse>
174 <params>
175 <param>
176 <value>
177 <struct>
178 <member>
179 <name>integer1</name>
180 <value><i8>1</i8></value>
181 </member>
182 </struct>
183 </value>
184 </param>
185 </params>
186 </methodResponse>';
187         $r = $m->parseResponse($fp);
188         $v = $r->value();
189         $s = $v->structmem('integer1');
190         $this->assertEquals(1, $s->scalarval());
191     }
192
193     public function testAddScalarToStruct()
194     {
195         $v = new xmlrpcval(array('a' => 'b'), 'struct');
196         // use @ operator in case error_log gets on screen
197         $r = @$v->addscalar('c');
198         $this->assertEquals(0, $r);
199     }
200
201     public function testAddStructToStruct()
202     {
203         $v = new xmlrpcval(array('a' => new xmlrpcval('b')), 'struct');
204         $r = $v->addstruct(array('b' => new xmlrpcval('c')));
205         $this->assertEquals(2, $v->structsize());
206         $this->assertEquals(1, $r);
207         $r = $v->addstruct(array('b' => new xmlrpcval('b')));
208         $this->assertEquals(2, $v->structsize());
209     }
210
211     public function testAddArrayToArray()
212     {
213         $v = new xmlrpcval(array(new xmlrpcval('a'), new xmlrpcval('b')), 'array');
214         $r = $v->addarray(array(new xmlrpcval('b'), new xmlrpcval('c')));
215         $this->assertEquals(4, $v->arraysize());
216         $this->assertEquals(1, $r);
217     }
218
219     public function testEncodeArray()
220     {
221         $r = range(1, 100);
222         $v = php_xmlrpc_encode($r);
223         $this->assertEquals('array', $v->kindof());
224     }
225
226     public function testEncodeRecursive()
227     {
228         $v = php_xmlrpc_encode(php_xmlrpc_encode('a simple string'));
229         $this->assertEquals('scalar', $v->kindof());
230     }
231
232     public function testBrokenRequests()
233     {
234         $s = new xmlrpc_server();
235         // omitting the 'params' tag: not tolerated by the lib anymore
236         $f = '<?xml version="1.0"?>
237 <methodCall>
238 <methodName>system.methodHelp</methodName>
239 <param>
240 <value><string>system.methodHelp</string></value>
241 </param>
242 </methodCall>';
243         $r = $s->parserequest($f);
244         $this->assertEquals(15, $r->faultCode());
245         // omitting a 'param' tag
246         $f = '<?xml version="1.0"?>
247 <methodCall>
248 <methodName>system.methodHelp</methodName>
249 <params>
250 <value><string>system.methodHelp</string></value>
251 </params>
252 </methodCall>';
253         $r = $s->parserequest($f);
254         $this->assertEquals(15, $r->faultCode());
255         // omitting a 'value' tag
256         $f = '<?xml version="1.0"?>
257 <methodCall>
258 <methodName>system.methodHelp</methodName>
259 <params>
260 <param><string>system.methodHelp</string></param>
261 </params>
262 </methodCall>';
263         $r = $s->parserequest($f);
264         $this->assertEquals(15, $r->faultCode());
265     }
266
267     public function testBrokenResponses()
268     {
269         $m = $this->newMsg('dummy');
270         // omitting the 'params' tag: no more tolerated by the lib...
271         $f = '<?xml version="1.0"?>
272 <methodResponse>
273 <param>
274 <value><string>system.methodHelp</string></value>
275 </param>
276 </methodResponse>';
277         $r = $m->parseResponse($f);
278         $this->assertEquals(2, $r->faultCode());
279         // omitting the 'param' tag: no more tolerated by the lib...
280         $f = '<?xml version="1.0"?>
281 <methodResponse>
282 <params>
283 <value><string>system.methodHelp</string></value>
284 </params>
285 </methodResponse>';
286         $r = $m->parseResponse($f);
287         $this->assertEquals(2, $r->faultCode());
288         // omitting a 'value' tag: KO
289         $f = '<?xml version="1.0"?>
290 <methodResponse>
291 <params>
292 <param><string>system.methodHelp</string></param>
293 </params>
294 </methodResponse>';
295         $r = $m->parseResponse($f);
296         $this->assertEquals(2, $r->faultCode());
297     }
298
299     public function testBuggyHttp()
300     {
301         $s = $this->newMsg('dummy');
302         $f = 'HTTP/1.1 100 Welcome to the jungle
303
304 HTTP/1.0 200 OK
305 X-Content-Marx-Brothers: Harpo
306         Chico and Groucho
307 Content-Length: who knows?
308
309
310
311 <?xml version="1.0"?>
312 <!-- First of all, let\'s check out if the lib properly handles a commented </methodResponse> tag... -->
313 <methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
314 <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow
315
316
317 and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
318 <script type="text\javascript">document.write(\'Hello, my name is added nag, I\\\'m happy to serve your content for free\');</script>
319  ';
320         $r = $s->parseResponse($f);
321         $v = $r->value();
322         $s = $v->structmem('content');
323         $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s->scalarval());
324     }
325
326     public function testStringBug()
327     {
328         $s = $this->newMsg('dummy');
329         $f = '<?xml version="1.0"?>
330 <!-- $Id -->
331 <!-- found by 2z69xks7bpy001@sneakemail.com, amongst others
332  covers what happens when there\'s character data after </string>
333  and before </value> -->
334 <methodResponse>
335 <params>
336 <param>
337 <value>
338 <struct>
339 <member>
340 <name>success</name>
341 <value>
342 <boolean>1</boolean>
343 </value>
344 </member>
345 <member>
346 <name>sessionID</name>
347 <value>
348 <string>S300510007I</string>
349 </value>
350 </member>
351 </struct>
352 </value>
353 </param>
354 </params>
355 </methodResponse> ';
356         $r = $s->parseResponse($f);
357         $v = $r->value();
358         $s = $v->structmem('sessionID');
359         $this->assertEquals('S300510007I', $s->scalarval());
360     }
361
362     public function testWhiteSpace()
363     {
364         $s = $this->newMsg('dummy');
365         $f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
366 <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow
367
368
369 and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
370 ';
371         $r = $s->parseResponse($f);
372         $v = $r->value();
373         $s = $v->structmem('content');
374         $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s->scalarval());
375     }
376
377     public function testDoubleDataInArrayTag()
378     {
379         $s = $this->newMsg('dummy');
380         $f = '<?xml version="1.0"?><methodResponse><params><param><value><array>
381 <data></data>
382 <data></data>
383 </array></value></param></params></methodResponse>
384 ';
385         $r = $s->parseResponse($f);
386         $v = $r->faultCode();
387         $this->assertEquals(2, $v);
388         $f = '<?xml version="1.0"?><methodResponse><params><param><value><array>
389 <data><value>Hello world</value></data>
390 <data></data>
391 </array></value></param></params></methodResponse>
392 ';
393         $r = $s->parseResponse($f);
394         $v = $r->faultCode();
395         $this->assertEquals(2, $v);
396     }
397
398     public function testDoubleStuffInValueTag()
399     {
400         $s = $this->newMsg('dummy');
401         $f = '<?xml version="1.0"?><methodResponse><params><param><value>
402 <string>hello world</string>
403 <array><data></data></array>
404 </value></param></params></methodResponse>
405 ';
406         $r = $s->parseResponse($f);
407         $v = $r->faultCode();
408         $this->assertEquals(2, $v);
409         $f = '<?xml version="1.0"?><methodResponse><params><param><value>
410 <string>hello</string>
411 <string>world</string>
412 </value></param></params></methodResponse>
413 ';
414         $r = $s->parseResponse($f);
415         $v = $r->faultCode();
416         $this->assertEquals(2, $v);
417         $f = '<?xml version="1.0"?><methodResponse><params><param><value>
418 <string>hello</string>
419 <struct><member><name>hello><value>world</value></member></struct>
420 </value></param></params></methodResponse>
421 ';
422         $r = $s->parseResponse($f);
423         $v = $r->faultCode();
424         $this->assertEquals(2, $v);
425     }
426
427     public function testAutodecodeResponse()
428     {
429         $s = $this->newMsg('dummy');
430         $f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
431 <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow
432
433
434 and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
435 ';
436         $r = $s->parseResponse($f, true, 'phpvals');
437         $v = $r->value();
438         $s = $v['content'];
439         $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s);
440     }
441
442     public function testNoDecodeResponse()
443     {
444         $s = $this->newMsg('dummy');
445         $f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
446 <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow
447
448
449 and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>';
450         $r = $s->parseResponse($f, true, 'xml');
451         $v = $r->value();
452         $this->assertEquals($f, $v);
453     }
454
455     public function testAutoCoDec()
456     {
457         $data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00');
458         $data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1);
459         $data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2);
460         //$keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
461         $v1 = php_xmlrpc_encode($data, array('auto_dates'));
462         $v2 = php_xmlrpc_decode_xml($v1->serialize());
463         $this->assertEquals($v1, $v2);
464         $r1 = new PhpXmlRpc\Response($v1);
465         $r2 = php_xmlrpc_decode_xml($r1->serialize());
466         $r2->serialize(); // needed to set internal member payload
467         $this->assertEquals($r1, $r2);
468         $m1 = new PhpXmlRpc\Request('hello dolly', array($v1));
469         $m2 = php_xmlrpc_decode_xml($m1->serialize());
470         $m2->serialize(); // needed to set internal member payload
471         $this->assertEquals($m1, $m2);
472     }
473
474     public function testUTF8Request()
475     {
476         $sendstring = 'κόσμε'; // Greek word 'kosme'. NB: NOT a valid ISO8859 string!
477         $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
478         \PhpXmlRpc\PhpXmlRpc::importGlobals();
479         $f = new xmlrpcval($sendstring, 'string');
480         $v = $f->serialize();
481         $this->assertEquals("<value><string>&#954;&#8057;&#963;&#956;&#949;</string></value>\n", $v);
482         $GLOBALS['xmlrpc_internalencoding'] = 'ISO-8859-1';
483         \PhpXmlRpc\PhpXmlRpc::importGlobals();
484     }
485
486     public function testUTF8Response()
487     {
488         $string = chr(224) . chr(252) . chr(232);
489
490         $s = $this->newMsg('dummy');
491         $f = "HTTP/1.1 200 OK\r\nContent-type: text/xml; charset=UTF-8\r\n\r\n" . '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
492 <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>' . utf8_encode($string) . '</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
493 ';
494         $r = $s->parseResponse($f, false, 'phpvals');
495         $v = $r->value();
496         $v = $v['content'];
497         $this->assertEquals($string, $v);
498
499         $f = '<?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
500 <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>' . utf8_encode($string) . '</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
501 ';
502         $r = $s->parseResponse($f, false, 'phpvals');
503         $v = $r->value();
504         $v = $v['content'];
505         $this->assertEquals($string, $v);
506
507         $r = php_xmlrpc_decode_xml($f);
508         $v = $r->value();
509         $v = $v->structmem('content')->scalarval();
510         $this->assertEquals($string, $v);
511     }
512
513     public function testLatin1Response()
514     {
515         $string = chr(224) . chr(252) . chr(232);
516
517         $s = $this->newMsg('dummy');
518         $f = "HTTP/1.1 200 OK\r\nContent-type: text/xml; charset=ISO-8859-1\r\n\r\n" . '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
519 <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>' . $string . '</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
520 ';
521         $r = $s->parseResponse($f, false, 'phpvals');
522         $v = $r->value();
523         $v = $v['content'];
524         $this->assertEquals($string, $v);
525
526         $f = '<?xml version="1.0" encoding="ISO-8859-1"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
527 <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>' . $string . '</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
528 ';
529         $r = $s->parseResponse($f, false, 'phpvals');
530         $v = $r->value();
531         $v = $v['content'];
532         $this->assertEquals($string, $v);
533
534         $r = php_xmlrpc_decode_xml($f);
535         $v = $r->value();
536         $v = $v->structmem('content')->scalarval();
537         $this->assertEquals($string, $v);
538     }
539
540     public function testUTF8IntString()
541     {
542         $v = new xmlrpcval(100, 'int');
543         $s = $v->serialize('UTF-8');
544         $this->assertequals("<value><int>100</int></value>\n", $s);
545     }
546
547     public function testStringInt()
548     {
549         $v = new xmlrpcval('hello world', 'int');
550         $s = $v->serialize();
551         $this->assertequals("<value><int>0</int></value>\n", $s);
552     }
553
554     public function testStructMemExists()
555     {
556         $v = php_xmlrpc_encode(array('hello' => 'world'));
557         $b = $v->structmemexists('hello');
558         $this->assertequals(true, $b);
559         $b = $v->structmemexists('world');
560         $this->assertequals(false, $b);
561     }
562
563     public function testNilvalue()
564     {
565         // default case: we do not accept nil values received
566         $v = new xmlrpcval('hello', 'null');
567         $r = new xmlrpcresp($v);
568         $s = $r->serialize();
569         $m = $this->newMsg('dummy');
570         $r = $m->parseresponse($s);
571         $this->assertequals(2, $r->faultCode());
572         // enable reception of nil values
573         $GLOBALS['xmlrpc_null_extension'] = true;
574         \PhpXmlRpc\PhpXmlRpc::importGlobals();
575         $r = $m->parseresponse($s);
576         $v = $r->value();
577         $this->assertequals('null', $v->scalartyp());
578         // test with the apache version: EX:NIL
579         $GLOBALS['xmlrpc_null_apache_encoding'] = true;
580         \PhpXmlRpc\PhpXmlRpc::importGlobals();
581         // serialization
582         $v = new xmlrpcval('hello', 'null');
583         $s = $v->serialize();
584         $this->assertequals(1, preg_match('#<value><ex:nil/></value>#', $s));
585         // deserialization
586         $r = new xmlrpcresp($v);
587         $s = $r->serialize();
588         $r = $m->parseresponse($s);
589         $v = $r->value();
590         $this->assertequals('null', $v->scalartyp());
591         $GLOBALS['xmlrpc_null_extension'] = false;
592         \PhpXmlRpc\PhpXmlRpc::importGlobals();
593         $r = $m->parseresponse($s);
594         $this->assertequals(2, $r->faultCode());
595     }
596
597     public function testLocale()
598     {
599         $locale = setlocale(LC_NUMERIC, 0);
600         /// @todo on php 5.3/win setting locale to german does not seem to set decimal separator to comma...
601         if (setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false) {
602             $v = new xmlrpcval(1.1, 'double');
603             if (strpos($v->scalarval(), ',') == 1) {
604                 $r = $v->serialize();
605                 $this->assertequals(false, strpos($r, ','));
606                 setlocale(LC_NUMERIC, $locale);
607             } else {
608                 setlocale(LC_NUMERIC, $locale);
609                 $this->markTestSkipped('did not find a locale which sets decimal separator to comma');
610             }
611         } else {
612             $this->markTestSkipped('did not find a locale which sets decimal separator to comma');
613         }
614     }
615
616     public function testArrayAccess()
617     {
618         $v1 = new xmlrpcval(array(new xmlrpcval('one'), new xmlrpcval('two')), 'array');
619         $this->assertequals(1, count($v1));
620         $out = array('me' => array(), 'mytype' => 2, '_php_class' => null);
621
622         foreach($v1 as $key => $val)
623         {
624             $this->assertArrayHasKey($key, $out);
625             $expected = $out[$key];
626             if (gettype($expected) == 'array') {
627                 $this->assertequals('array', gettype($val));
628             } else {
629                 $this->assertequals($expected, $val);
630             }
631         }
632
633         $v2 = new \PhpXmlRpc\Value(array(new \PhpXmlRpc\Value('one'), new \PhpXmlRpc\Value('two')), 'array');
634         $this->assertequals(2, count($v2));
635         $out = array(array('key' => 0, 'value'  => 'object'), array('key' => 1, 'value'  => 'object'));
636         $i = 0;
637         foreach($v2 as $key => $val)
638         {
639             $expected = $out[$i];
640             $this->assertequals($expected['key'], $key);
641             $this->assertequals($expected['value'], gettype($val));
642             $i++;
643         }
644     }
645
646     function testBigXML()
647     {
648         // nb: make sure that  the serialized xml corresponding to this is > 10MB in size
649         $data = array();
650         for ($i = 0; $i < 500000; $i++ ) {
651             $data[] = 'hello world';
652         }
653
654         $encoder = new \PhpXmlRpc\Encoder();
655         $val = $encoder->encode($data);
656         $req = new \PhpXmlRpc\Request('test', array($val));
657         $xml = $req->serialize();
658         $parser = new \PhpXmlRpc\Helper\XMLParser();
659         $parser->parse($xml);
660
661         $this->assertequals(0, $parser->_xh['isf']);
662     }
663 }