Improve testsuite to make it easily executable by Travis
[plcapi.git] / test / testsuite.php
1 <?php
2
3 include(dirname(__FILE__).'/parse_args.php');
4
5 require_once('xmlrpc.inc');
6 require_once('xmlrpcs.inc');
7 require_once('xmlrpc_wrappers.inc');
8
9 require_once 'phpunit.php';
10 //require_once 'PHPUnit/TestDecorator.php';
11
12 // let testuite run for the needed time
13 if ((int)ini_get('max_execution_time') < 180)
14     ini_set('max_execution_time', 180);
15
16 $suite = new PHPUnit_TestSuite();
17
18 // array with list of failed tests
19 $failed_tests = array();
20
21 class LocalhostTests extends PHPUnit_TestCase
22 {
23     var $client = null;
24     var $method = 'http';
25     var $timeout = 10;
26     var $request_compression = null;
27     var $accepted_compression = '';
28
29     function fail($message = '')
30     {
31         PHPUnit_TestCase::fail($message);
32         // save in global var that this particular test has failed
33         // (but only if not called from subclass objects / multitests)
34         if (function_exists('debug_backtrace') && strtolower(get_class($this)) == 'localhosttests')
35         {
36             global $failed_tests;
37             $trace = debug_backtrace();
38             for ($i = 0; $i < count($trace); $i++)
39             {
40                 if (strpos($trace[$i]['function'], 'test') === 0)
41                 {
42                     $failed_tests[$trace[$i]['function']] = true;
43                     break;
44                 }
45             }
46         }
47     }
48
49     function setUp()
50     {
51         global $DEBUG, $LOCALSERVER, $URI;
52         $server = explode(':', $LOCALSERVER);
53         if(count($server) > 1)
54         {
55             $this->client=new xmlrpc_client($URI, $server[0], $server[1]);
56         }
57         else
58         {
59             $this->client=new xmlrpc_client($URI, $LOCALSERVER);
60         }
61         if($DEBUG)
62         {
63             $this->client->setDebug($DEBUG);
64         }
65         $this->client->request_compression = $this->request_compression;
66         $this->client->accepted_compression = $this->accepted_compression;
67     }
68
69     function send($msg, $errrorcode=0, $return_response=false)
70     {
71         $r = $this->client->send($msg, $this->timeout, $this->method);
72         // for multicall, return directly array of responses
73         if(is_array($r))
74         {
75             return $r;
76         }
77         $this->assertEquals($r->faultCode(), $errrorcode, 'Error '.$r->faultCode().' connecting to server: '.$r->faultString());
78         if(!$r->faultCode())
79         {
80             if($return_response)
81                 return $r;
82             else
83                 return $r->value();
84         }
85         else
86         {
87             return null;
88         }
89     }
90
91     function testString()
92     {
93         $sendstring="here are 3 \"entities\": < > & " .
94             "and here's a dollar sign: \$pretendvarname and a backslash too: " . chr(92) .
95             " - isn't that great? \\\"hackery\\\" at it's best " .
96             " also don't want to miss out on \$item[0]. ".
97             "The real weird stuff follows: CRLF here".chr(13).chr(10).
98             "a simple CR here".chr(13).
99             "a simple LF here".chr(10).
100             "and then LFCR".chr(10).chr(13).
101             "last but not least weird names: G".chr(252)."nter, El".chr(232)."ne, and an xml comment closing tag: -->";
102         $f=new xmlrpcmsg('examples.stringecho', array(
103             new xmlrpcval($sendstring, 'string')
104         ));
105         $v=$this->send($f);
106         if($v)
107         {
108             // when sending/receiving non-US-ASCII encoded strings, XML says cr-lf can be normalized.
109             // so we relax our tests...
110             $l1 = strlen($sendstring);
111             $l2 = strlen($v->scalarval());
112             if ($l1 == $l2)
113                 $this->assertEquals($sendstring, $v->scalarval());
114             else
115                 $this->assertEquals(str_replace(array("\r\n", "\r"), array("\n", "\n"), $sendstring), $v->scalarval());
116         }
117     }
118
119     function testAddingDoubles()
120     {
121         // note that rounding errors mean we
122         // keep precision to sensible levels here ;-)
123         $a=12.13; $b=-23.98;
124         $f=new xmlrpcmsg('examples.addtwodouble',array(
125             new xmlrpcval($a, 'double'),
126             new xmlrpcval($b, 'double')
127         ));
128         $v=$this->send($f);
129         if($v)
130         {
131             $this->assertEquals($a+$b,$v->scalarval());
132         }
133     }
134
135     function testAdding()
136     {
137         $f=new xmlrpcmsg('examples.addtwo',array(
138             new xmlrpcval(12, 'int'),
139             new xmlrpcval(-23, 'int')
140         ));
141         $v=$this->send($f);
142         if($v)
143         {
144             $this->assertEquals(12-23, $v->scalarval());
145         }
146     }
147
148     function testInvalidNumber()
149     {
150         $f=new xmlrpcmsg('examples.addtwo',array(
151             new xmlrpcval('fred', 'int'),
152             new xmlrpcval("\"; exec('ls')", 'int')
153         ));
154         $v=$this->send($f);
155         /// @todo a fault condition should be generated here
156         /// by the server, which we pick up on
157         if($v)
158         {
159             $this->assertEquals(0, $v->scalarval());
160         }
161     }
162
163     function testBoolean()
164     {
165         $f=new xmlrpcmsg('examples.invertBooleans', array(
166             new xmlrpcval(array(
167                 new xmlrpcval(true, 'boolean'),
168                 new xmlrpcval(false, 'boolean'),
169                 new xmlrpcval(1, 'boolean'),
170                 new xmlrpcval(0, 'boolean'),
171                 //new xmlrpcval('true', 'boolean'),
172                 //new xmlrpcval('false', 'boolean')
173             ),
174             'array'
175             )));
176         $answer='0101';
177         $v=$this->send($f);
178         if($v)
179         {
180             $sz=$v->arraysize();
181             $got='';
182             for($i=0; $i<$sz; $i++)
183             {
184                 $b=$v->arraymem($i);
185                 if($b->scalarval())
186                 {
187                     $got.='1';
188                 }
189                 else
190                 {
191                     $got.='0';
192                 }
193             }
194             $this->assertEquals($answer, $got);
195         }
196     }
197
198     function testBase64()
199     {
200         $sendstring='Mary had a little lamb,
201 Whose fleece was white as snow,
202 And everywhere that Mary went
203 the lamb was sure to go.
204
205 Mary had a little lamb
206 She tied it to a pylon
207 Ten thousand volts went down its back
208 And turned it into nylon';
209         $f=new xmlrpcmsg('examples.decode64',array(
210             new xmlrpcval($sendstring, 'base64')
211         ));
212         $v=$this->send($f);
213         if($v)
214         {
215             if (strlen($sendstring) == strlen($v->scalarval()))
216                 $this->assertEquals($sendstring, $v->scalarval());
217             else
218                 $this->assertEquals(str_replace(array("\r\n", "\r"), array("\n", "\n"), $sendstring), $v->scalarval());
219         }
220     }
221
222     function testDateTime()
223     {
224         $time = time();
225         $t1 = new xmlrpcval($time, 'dateTime.iso8601');
226         $t2 = new xmlrpcval(iso8601_encode($time), 'dateTime.iso8601');
227         $this->assertEquals($t1->serialize(), $t2->serialize());
228         if (class_exists('DateTime'))
229         {
230             $datetime = new DateTime();
231             $t3 = new xmlrpcval($datetime->setTimestamp($time), 'dateTime.iso8601');
232             $this->assertEquals($t1->serialize(), $t3->serialize());
233         }
234     }
235
236     function testCountEntities()
237     {
238         $sendstring = "h'fd>onc>>l>>rw&bpu>q>e<v&gxs<ytjzkami<";
239         $f = new xmlrpcmsg('validator1.countTheEntities',array(
240             new xmlrpcval($sendstring, 'string')
241         ));
242         $v = $this->send($f);
243         if($v)
244         {
245             $got = '';
246             $expected = '37210';
247             $expect_array = array('ctLeftAngleBrackets','ctRightAngleBrackets','ctAmpersands','ctApostrophes','ctQuotes');
248             while(list(,$val) = each($expect_array))
249             {
250                 $b = $v->structmem($val);
251                 $got .= $b->me['int'];
252             }
253             $this->assertEquals($expected, $got);
254         }
255     }
256
257     function _multicall_msg($method, $params)
258     {
259         $struct['methodName'] = new xmlrpcval($method, 'string');
260         $struct['params'] = new xmlrpcval($params, 'array');
261         return new xmlrpcval($struct, 'struct');
262     }
263
264     function testServerMulticall()
265     {
266         // We manually construct a system.multicall() call to ensure
267         // that the server supports it.
268
269         // NB: This test will NOT pass if server does not support system.multicall.
270
271         // Based on http://xmlrpc-c.sourceforge.net/hacks/test_multicall.py
272         $good1 = $this->_multicall_msg(
273             'system.methodHelp',
274             array(php_xmlrpc_encode('system.listMethods')));
275         $bad = $this->_multicall_msg(
276             'test.nosuch',
277             array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
278         $recursive = $this->_multicall_msg(
279             'system.multicall',
280             array(new xmlrpcval(array(), 'array')));
281         $good2 = $this->_multicall_msg(
282             'system.methodSignature',
283             array(php_xmlrpc_encode('system.listMethods')));
284         $arg = new xmlrpcval(
285             array($good1, $bad, $recursive, $good2),
286             'array'
287         );
288
289         $f = new xmlrpcmsg('system.multicall', array($arg));
290         $v = $this->send($f);
291         if($v)
292         {
293             //$this->assertTrue($r->faultCode() == 0, "fault from system.multicall");
294             $this->assertTrue($v->arraysize() == 4, "bad number of return values");
295
296             $r1 = $v->arraymem(0);
297             $this->assertTrue(
298                 $r1->kindOf() == 'array' && $r1->arraysize() == 1,
299                 "did not get array of size 1 from good1"
300             );
301
302             $r2 = $v->arraymem(1);
303             $this->assertTrue(
304                 $r2->kindOf() == 'struct',
305                 "no fault from bad"
306             );
307
308             $r3 = $v->arraymem(2);
309             $this->assertTrue(
310                 $r3->kindOf() == 'struct',
311                 "recursive system.multicall did not fail"
312             );
313
314             $r4 = $v->arraymem(3);
315             $this->assertTrue(
316                 $r4->kindOf() == 'array' && $r4->arraysize() == 1,
317                 "did not get array of size 1 from good2"
318             );
319         }
320     }
321
322     function testClientMulticall1()
323     {
324         // NB: This test will NOT pass if server does not support system.multicall.
325
326         $this->client->no_multicall = false;
327
328         $good1 = new xmlrpcmsg('system.methodHelp',
329             array(php_xmlrpc_encode('system.listMethods')));
330         $bad = new xmlrpcmsg('test.nosuch',
331             array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
332         $recursive = new xmlrpcmsg('system.multicall',
333             array(new xmlrpcval(array(), 'array')));
334         $good2 = new xmlrpcmsg('system.methodSignature',
335             array(php_xmlrpc_encode('system.listMethods'))
336         );
337
338         $r = $this->send(array($good1, $bad, $recursive, $good2));
339         if($r)
340         {
341             $this->assertTrue(count($r) == 4, "wrong number of return values");
342         }
343
344         $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
345         if(!$r[0]->faultCode())
346         {
347             $val = $r[0]->value();
348             $this->assertTrue(
349                 $val->kindOf() == 'scalar' && $val->scalartyp() == 'string',
350                 "good1 did not return string"
351             );
352         }
353         $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
354         $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall");
355         $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
356         if(!$r[3]->faultCode())
357         {
358             $val = $r[3]->value();
359             $this->assertTrue($val->kindOf() == 'array', "good2 did not return array");
360         }
361         // This is the only assert in this test which should fail
362         // if the test server does not support system.multicall.
363         $this->assertTrue($this->client->no_multicall == false,
364             "server does not support system.multicall"
365         );
366     }
367
368     function testClientMulticall2()
369     {
370         // NB: This test will NOT pass if server does not support system.multicall.
371
372         $this->client->no_multicall = true;
373
374         $good1 = new xmlrpcmsg('system.methodHelp',
375             array(php_xmlrpc_encode('system.listMethods')));
376         $bad = new xmlrpcmsg('test.nosuch',
377             array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
378         $recursive = new xmlrpcmsg('system.multicall',
379             array(new xmlrpcval(array(), 'array')));
380         $good2 = new xmlrpcmsg('system.methodSignature',
381             array(php_xmlrpc_encode('system.listMethods'))
382         );
383
384         $r = $this->send(array($good1, $bad, $recursive, $good2));
385         if($r)
386         {
387             $this->assertTrue(count($r) == 4, "wrong number of return values");
388         }
389
390         $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
391         if(!$r[0]->faultCode())
392         {
393             $val = $r[0]->value();
394             $this->assertTrue(
395                 $val->kindOf() == 'scalar' && $val->scalartyp() == 'string',
396                 "good1 did not return string");
397         }
398         $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
399         $this->assertTrue($r[2]->faultCode() == 0, "fault from (non recursive) system.multicall");
400         $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
401         if(!$r[3]->faultCode())
402         {
403             $val = $r[3]->value();
404             $this->assertTrue($val->kindOf() == 'array', "good2 did not return array");
405         }
406     }
407
408     function testClientMulticall3()
409     {
410         // NB: This test will NOT pass if server does not support system.multicall.
411
412         $this->client->return_type = 'phpvals';
413         $this->client->no_multicall = false;
414
415         $good1 = new xmlrpcmsg('system.methodHelp',
416             array(php_xmlrpc_encode('system.listMethods')));
417         $bad = new xmlrpcmsg('test.nosuch',
418             array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
419         $recursive = new xmlrpcmsg('system.multicall',
420             array(new xmlrpcval(array(), 'array')));
421         $good2 = new xmlrpcmsg('system.methodSignature',
422             array(php_xmlrpc_encode('system.listMethods'))
423         );
424
425         $r = $this->send(array($good1, $bad, $recursive, $good2));
426         if($r)
427         {
428             $this->assertTrue(count($r) == 4, "wrong number of return values");
429         }
430         $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
431         if(!$r[0]->faultCode())
432         {
433             $val = $r[0]->value();
434             $this->assertTrue(
435                 is_string($val) , "good1 did not return string");
436         }
437         $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
438         $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall");
439         $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
440         if(!$r[3]->faultCode())
441         {
442             $val = $r[3]->value();
443             $this->assertTrue(is_array($val), "good2 did not return array");
444         }
445         $this->client->return_type = 'xmlrpcvals';
446     }
447
448     function testCatchWarnings()
449     {
450         $f = new xmlrpcmsg('examples.generatePHPWarning', array(
451             new xmlrpcval('whatever', 'string')
452         ));
453         $v = $this->send($f);
454         if($v)
455         {
456             $this->assertEquals($v->scalarval(), true);
457         }
458     }
459
460     function testCatchExceptions()
461     {
462         global $URI;
463         $f = new xmlrpcmsg('examples.raiseException', array(
464             new xmlrpcval('whatever', 'string')
465         ));
466         $v = $this->send($f, $GLOBALS['xmlrpcerr']['server_error']);
467         $this->client->path = $URI.'?EXCEPTION_HANDLING=1';
468         $v = $this->send($f, 1);
469         $this->client->path = $URI.'?EXCEPTION_HANDLING=2';
470         $v = $this->send($f, $GLOBALS['xmlrpcerr']['invalid_return']);
471     }
472
473     function testZeroParams()
474     {
475         $f = new xmlrpcmsg('system.listMethods');
476         $v = $this->send($f);
477     }
478
479     function testCodeInjectionServerSide()
480     {
481         $f = new xmlrpcmsg('system.MethodHelp');
482         $f->payload = "<?xml version=\"1.0\"?><methodCall><methodName>validator1.echoStructTest</methodName><params><param><value><struct><member><name>','')); echo('gotcha!'); die(); //</name></member></struct></value></param></params></methodCall>";
483         $v = $this->send($f);
484         //$v = $r->faultCode();
485         if ($v)
486         {
487             $this->assertEquals(0, $v->structsize());
488         }
489     }
490
491     function testAutoRegisteredFunction()
492     {
493         $f=new xmlrpcmsg('examples.php.getStateName',array(
494             new xmlrpcval(23, 'int')
495         ));
496         $v=$this->send($f);
497         if($v)
498         {
499             $this->assertEquals('Michigan', $v->scalarval());
500         }
501         else
502         {
503             $this->fail('Note: server can only auto register functions if running with PHP 5.0.3 and up');
504         }
505     }
506
507     function testAutoRegisteredClass()
508     {
509         $f=new xmlrpcmsg('examples.php2.getStateName',array(
510             new xmlrpcval(23, 'int')
511         ));
512         $v=$this->send($f);
513         if($v)
514         {
515             $this->assertEquals('Michigan', $v->scalarval());
516             $f=new xmlrpcmsg('examples.php3.getStateName',array(
517             new xmlrpcval(23, 'int')
518         ));
519             $v=$this->send($f);
520             if($v)
521             {
522                 $this->assertEquals('Michigan', $v->scalarval());
523             }
524         }
525         else
526         {
527             $this->fail('Note: server can only auto register class methods if running with PHP 5.0.3 and up');
528         }
529     }
530
531     function testAutoRegisteredMethod()
532     {
533         $func=wrap_xmlrpc_method($this->client, 'examples.getStateName');
534         if($func == '')
535         {
536             $this->fail('Registration of examples.getStateName failed');
537         }
538         else
539         {
540             $v=$func(23);
541             $this->assertEquals('Michigan', $v);
542         }
543     }
544
545     function testGetCookies()
546     {
547         // let server set to us some cookies we tell it
548         $cookies = array(
549             //'c1' => array(),
550             'c2' => array('value' => 'c2'),
551             'c3' => array('value' => 'c3', 'expires' => time()+60*60*24*30),
552             'c4' => array('value' => 'c4', 'expires' => time()+60*60*24*30, 'path' => '/'),
553             'c5' => array('value' => 'c5', 'expires' => time()+60*60*24*30, 'path' => '/', 'domain' => 'localhost'),
554         );
555         $cookiesval = php_xmlrpc_encode($cookies);
556         $f=new xmlrpcmsg('examples.setcookies',array($cookiesval));
557         $r=$this->send($f, 0, true);
558         if($r)
559         {
560             $v = $r->value();
561             $this->assertEquals(1, $v->scalarval());
562             // now check if we decoded the cookies as we had set them
563             $rcookies = $r->cookies();
564             // remove extra cookies which might have been set by proxies
565             foreach($rcookies as $c => $v)
566                 if(!in_array($c, array('c2', 'c3', 'c4', 'c5')))
567                     unset($rcookies[$c]);
568             foreach($cookies as $c => $v)
569                 // format for date string in cookies: 'Mon, 31 Oct 2005 13:50:56 GMT'
570                 // but PHP versions differ on that, some use 'Mon, 31-Oct-2005 13:50:56 GMT'...
571                 if(isset($v['expires']))
572                 {
573                     if (isset($rcookies[$c]['expires']) && strpos($rcookies[$c]['expires'], '-'))
574                     {
575                         $cookies[$c]['expires'] = gmdate('D, d\-M\-Y H:i:s \G\M\T' ,$cookies[$c]['expires']);
576                     }
577                     else
578                     {
579                         $cookies[$c]['expires'] = gmdate('D, d M Y H:i:s \G\M\T' ,$cookies[$c]['expires']);
580                     }
581                 }
582             $this->assertEquals($cookies, $rcookies);
583         }
584     }
585
586     function testSetCookies()
587     {
588         // let server set to us some cookies we tell it
589         $cookies = array(
590             'c0' => null,
591             'c1' => 1,
592             'c2' => '2 3',
593             'c3' => '!@#$%^&*()_+|}{":?><,./\';[]\\=-'
594         );
595         $f=new xmlrpcmsg('examples.getcookies',array());
596         foreach ($cookies as $cookie => $val)
597         {
598             $this->client->setCookie($cookie, $val);
599             $cookies[$cookie] = (string) $cookies[$cookie];
600         }
601         $r = $this->client->send($f, $this->timeout, $this->method);
602         $this->assertEquals($r->faultCode(), 0, 'Error '.$r->faultCode().' connecting to server: '.$r->faultString());
603         if(!$r->faultCode())
604         {
605             $v = $r->value();
606             $v = php_xmlrpc_decode($v);
607             // on IIS and Apache getallheaders returns something slightly different...
608             $this->assertEquals($v, $cookies);
609         }
610     }
611
612     function testSendTwiceSameMsg()
613     {
614         $f=new xmlrpcmsg('examples.stringecho', array(
615             new xmlrpcval('hello world', 'string')
616         ));
617         $v1 = $this->send($f);
618         $v2 = $this->send($f);
619         //$v = $r->faultCode();
620         if ($v1 && $v2)
621         {
622             $this->assertEquals($v2, $v1);
623         }
624     }
625 }
626
627 class LocalHostMultiTests extends LocalhostTests
628 {
629     function _runtests()
630     {
631         global $failed_tests;
632         foreach(get_class_methods('LocalhostTests') as $meth)
633         {
634             if(strpos($meth, 'test') === 0 && $meth != 'testHttps' && $meth != 'testCatchExceptions')
635             {
636                 if (!isset($failed_tests[$meth]))
637                     $this->$meth();
638             }
639             if ($this->_failed)
640             {
641                 break;
642             }
643         }
644     }
645
646     function testDeflate()
647     {
648         if(!function_exists('gzdeflate'))
649         {
650             $this->fail('Zlib missing: cannot test deflate functionality');
651             return;
652         }
653         $this->client->accepted_compression = array('deflate');
654         $this->client->request_compression = 'deflate';
655         $this->_runtests();
656     }
657
658     function testGzip()
659     {
660         if(!function_exists('gzdeflate'))
661         {
662             $this->fail('Zlib missing: cannot test gzip functionality');
663             return;
664         }
665         $this->client->accepted_compression = array('gzip');
666         $this->client->request_compression = 'gzip';
667         $this->_runtests();
668     }
669
670     function testKeepAlives()
671     {
672         if(!function_exists('curl_init'))
673         {
674             $this->fail('CURL missing: cannot test http 1.1');
675             return;
676         }
677         $this->method = 'http11';
678         $this->client->keepalive = true;
679         $this->_runtests();
680     }
681
682     function testProxy()
683     {
684         global $PROXYSERVER, $PROXYPORT, $NOPROXY;
685         if ($PROXYSERVER)
686         {
687             $this->client->setProxy($PROXYSERVER, $PROXYPORT);
688             $this->_runtests();
689         }
690         else
691             if (!$NOPROXY)
692                 $this->fail('PROXY definition missing: cannot test proxy');
693     }
694
695     function testHttp11()
696     {
697         if(!function_exists('curl_init'))
698         {
699             $this->fail('CURL missing: cannot test http 1.1');
700             return;
701         }
702         $this->method = 'http11'; // not an error the double assignment!
703         $this->client->method = 'http11';
704         //$this->client->verifyhost = 0;
705         //$this->client->verifypeer = 0;
706         $this->client->keepalive = false;
707         $this->_runtests();
708     }
709
710     function testHttp11Gzip()
711     {
712         if(!function_exists('curl_init'))
713         {
714             $this->fail('CURL missing: cannot test http 1.1');
715             return;
716         }
717         $this->method = 'http11'; // not an error the double assignment!
718         $this->client->method = 'http11';
719         $this->client->keepalive = false;
720         $this->client->accepted_compression = array('gzip');
721         $this->client->request_compression = 'gzip';
722         $this->_runtests();
723     }
724
725     function testHttp11Deflate()
726     {
727         if(!function_exists('curl_init'))
728         {
729             $this->fail('CURL missing: cannot test http 1.1');
730             return;
731         }
732         $this->method = 'http11'; // not an error the double assignment!
733         $this->client->method = 'http11';
734         $this->client->keepalive = false;
735         $this->client->accepted_compression = array('deflate');
736         $this->client->request_compression = 'deflate';
737         $this->_runtests();
738     }
739
740     function testHttp11Proxy()
741     {
742         global $PROXYSERVER, $PROXYPORT, $NOPROXY;
743         if(!function_exists('curl_init'))
744         {
745             $this->fail('CURL missing: cannot test http 1.1 w. proxy');
746             return;
747         }
748         else if ($PROXYSERVER == '')
749         {
750             if (!$NOPROXY)
751                 $this->fail('PROXY definition missing: cannot test proxy w. http 1.1');
752             return;
753         }
754         $this->method = 'http11'; // not an error the double assignment!
755         $this->client->method = 'http11';
756         $this->client->setProxy($PROXYSERVER, $PROXYPORT);
757         //$this->client->verifyhost = 0;
758         //$this->client->verifypeer = 0;
759         $this->client->keepalive = false;
760         $this->_runtests();
761     }
762
763     function testHttps()
764     {
765         global $HTTPSSERVER, $HTTPSURI, $HTTPSIGNOREPEER;
766         if(!function_exists('curl_init'))
767         {
768             $this->fail('CURL missing: cannot test https functionality');
769             return;
770         }
771         $this->client->server = $HTTPSSERVER;
772         $this->method = 'https';
773         $this->client->method = 'https';
774         $this->client->path = $HTTPSURI;
775         $this->client->setSSLVerifyPeer( !$HTTPSIGNOREPEER );
776         $this->_runtests();
777     }
778
779     function testHttpsProxy()
780     {
781         global $HTTPSSERVER, $HTTPSURI, $PROXYSERVER, $PROXYPORT, $NOPROXY;
782         if(!function_exists('curl_init'))
783         {
784             $this->fail('CURL missing: cannot test https functionality');
785             return;
786         }
787         else if ($PROXYSERVER == '')
788         {
789             if (!$NOPROXY)
790                 $this->fail('PROXY definition missing: cannot test proxy w. http 1.1');
791             return;
792         }
793         $this->client->server = $HTTPSSERVER;
794         $this->method = 'https';
795         $this->client->method = 'https';
796         $this->client->setProxy($PROXYSERVER, $PROXYPORT);
797         $this->client->path = $HTTPSURI;
798         $this->_runtests();
799     }
800
801     function testUTF8Responses()
802     {
803         global $URI;
804         //$this->client->path = strpos($URI, '?') === null ? $URI.'?RESPONSE_ENCODING=UTF-8' : $URI.'&RESPONSE_ENCODING=UTF-8';
805         $this->client->path = $URI.'?RESPONSE_ENCODING=UTF-8';
806         $this->_runtests();
807     }
808
809     function testUTF8Requests()
810     {
811         $this->client->request_charset_encoding = 'UTF-8';
812         $this->_runtests();
813     }
814
815     function testISOResponses()
816     {
817         global $URI;
818         //$this->client->path = strpos($URI, '?') === null ? $URI.'?RESPONSE_ENCODING=UTF-8' : $URI.'&RESPONSE_ENCODING=UTF-8';
819         $this->client->path = $URI.'?RESPONSE_ENCODING=ISO-8859-1';
820         $this->_runtests();
821     }
822
823     function testISORequests()
824     {
825         $this->client->request_charset_encoding = 'ISO-8859-1';
826         $this->_runtests();
827     }
828 }
829
830 class ParsingBugsTests extends PHPUnit_TestCase
831 {
832     function testMinusOneString()
833     {
834         $v=new xmlrpcval('-1');
835         $u=new xmlrpcval('-1', 'string');
836         $this->assertEquals($u->scalarval(), $v->scalarval());
837     }
838
839     function testUnicodeInMemberName(){
840         $str = "G".chr(252)."nter, El".chr(232)."ne";
841         $v = array($str => new xmlrpcval(1));
842         $r = new xmlrpcresp(new xmlrpcval($v, 'struct'));
843         $r = $r->serialize();
844         $m = new xmlrpcmsg('dummy');
845         $r = $m->parseResponse($r);
846         $v = $r->value();
847         $this->assertEquals($v->structmemexists($str), true);
848     }
849
850     function testUnicodeInErrorString()
851     {
852         $response = utf8_encode(
853 '<?xml version="1.0"?>
854 <!-- $Id -->
855 <!-- found by G. giunta, covers what happens when lib receives
856   UTF8 chars in response text and comments -->
857 <!-- ï¿½ï¿½ï¿½&#224;&#252;&#232; -->
858 <methodResponse>
859 <fault>
860 <value>
861 <struct>
862 <member>
863 <name>faultCode</name>
864 <value><int>888</int></value>
865 </member>
866 <member>
867 <name>faultString</name>
868 <value><string>���&#224;&#252;&#232;</string></value>
869 </member>
870 </struct>
871 </value>
872 </fault>
873 </methodResponse>');
874         $m=new xmlrpcmsg('dummy');
875         $r=$m->parseResponse($response);
876         $v=$r->faultString();
877         $this->assertEquals('���àüè', $v);
878     }
879
880     function testValidNumbers()
881     {
882         $m=new xmlrpcmsg('dummy');
883         $fp=
884 '<?xml version="1.0"?>
885 <methodResponse>
886 <params>
887 <param>
888 <value>
889 <struct>
890 <member>
891 <name>integer1</name>
892 <value><int>01</int></value>
893 </member>
894 <member>
895 <name>float1</name>
896 <value><double>01.10</double></value>
897 </member>
898 <member>
899 <name>integer2</name>
900 <value><int>+1</int></value>
901 </member>
902 <member>
903 <name>float2</name>
904 <value><double>+1.10</double></value>
905 </member>
906 <member>
907 <name>float3</name>
908 <value><double>-1.10e2</double></value>
909 </member>
910 </struct>
911 </value>
912 </param>
913 </params>
914 </methodResponse>';
915         $r=$m->parseResponse($fp);
916         $v=$r->value();
917         $s=$v->structmem('integer1');
918         $t=$v->structmem('float1');
919         $u=$v->structmem('integer2');
920         $w=$v->structmem('float2');
921         $x=$v->structmem('float3');
922         $this->assertEquals(1, $s->scalarval());
923         $this->assertEquals(1.1, $t->scalarval());
924         $this->assertEquals(1, $u->scalarval());
925         $this->assertEquals(1.1, $w->scalarval());
926         $this->assertEquals(-110.0, $x->scalarval());
927     }
928
929     function testAddScalarToStruct()
930     {
931         $v=new xmlrpcval(array('a' => 'b'), 'struct');
932         // use @ operator in case error_log gets on screen
933         $r= @$v->addscalar('c');
934         $this->assertEquals(0, $r);
935     }
936
937     function testAddStructToStruct()
938     {
939         $v=new xmlrpcval(array('a' => new xmlrpcval('b')), 'struct');
940         $r=$v->addstruct(array('b' => new xmlrpcval('c')));
941         $this->assertEquals(2, $v->structsize());
942         $this->assertEquals(1, $r);
943         $r=$v->addstruct(array('b' => new xmlrpcval('b')));
944         $this->assertEquals(2, $v->structsize());
945     }
946
947     function testAddArrayToArray()
948     {
949         $v=new xmlrpcval(array(new xmlrpcval('a'), new xmlrpcval('b')), 'array');
950         $r=$v->addarray(array(new xmlrpcval('b'), new xmlrpcval('c')));
951         $this->assertEquals(4, $v->arraysize());
952         $this->assertEquals(1, $r);
953     }
954
955     function testEncodeArray()
956     {
957         $r=range(1, 100);
958         $v = php_xmlrpc_encode($r);
959         $this->assertEquals('array', $v->kindof());
960     }
961
962     function testEncodeRecursive()
963     {
964         $v = php_xmlrpc_encode(php_xmlrpc_encode('a simple string'));
965         $this->assertEquals('scalar', $v->kindof());
966     }
967
968     function testBrokenRequests()
969     {
970         $s = new xmlrpc_server();
971         // omitting the 'params' tag: not tolerated by the lib anymore
972 $f = '<?xml version="1.0"?>
973 <methodCall>
974 <methodName>system.methodHelp</methodName>
975 <param>
976 <value><string>system.methodHelp</string></value>
977 </param>
978 </methodCall>';
979         $r = $s->parserequest($f);
980         $this->assertEquals(15, $r->faultCode());
981         // omitting a 'param' tag
982 $f = '<?xml version="1.0"?>
983 <methodCall>
984 <methodName>system.methodHelp</methodName>
985 <params>
986 <value><string>system.methodHelp</string></value>
987 </params>
988 </methodCall>';
989         $r = $s->parserequest($f);
990         $this->assertEquals(15, $r->faultCode());
991         // omitting a 'value' tag
992 $f = '<?xml version="1.0"?>
993 <methodCall>
994 <methodName>system.methodHelp</methodName>
995 <params>
996 <param><string>system.methodHelp</string></param>
997 </params>
998 </methodCall>';
999         $r = $s->parserequest($f);
1000         $this->assertEquals(15, $r->faultCode());
1001     }
1002
1003     function testBrokenResponses()
1004     {
1005         $m=new xmlrpcmsg('dummy');
1006         //$m->debug = 1;
1007         // omitting the 'params' tag: no more tolerated by the lib...
1008 $f = '<?xml version="1.0"?>
1009 <methodResponse>
1010 <param>
1011 <value><string>system.methodHelp</string></value>
1012 </param>
1013 </methodResponse>';
1014         $r = $m->parseResponse($f);
1015         $this->assertEquals(2, $r->faultCode());
1016         // omitting the 'param' tag: no more tolerated by the lib...
1017 $f = '<?xml version="1.0"?>
1018 <methodResponse>
1019 <params>
1020 <value><string>system.methodHelp</string></value>
1021 </params>
1022 </methodResponse>';
1023         $r = $m->parseResponse($f);
1024         $this->assertEquals(2, $r->faultCode());
1025         // omitting a 'value' tag: KO
1026 $f = '<?xml version="1.0"?>
1027 <methodResponse>
1028 <params>
1029 <param><string>system.methodHelp</string></param>
1030 </params>
1031 </methodResponse>';
1032         $r = $m->parseResponse($f);
1033         $this->assertEquals(2, $r->faultCode());
1034     }
1035
1036     function testBuggyHttp()
1037     {
1038         $s = new xmlrpcmsg('dummy');
1039 $f = 'HTTP/1.1 100 Welcome to the jungle
1040
1041 HTTP/1.0 200 OK
1042 X-Content-Marx-Brothers: Harpo
1043         Chico and Groucho
1044 Content-Length: who knows?
1045
1046
1047
1048 <?xml version="1.0"?>
1049 <!-- First of all, let\'s check out if the lib properly handles a commented </methodResponse> tag... -->
1050 <methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
1051 <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow
1052
1053
1054 and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
1055 <script type="text\javascript">document.write(\'Hello, my name is added nag, I\\\'m happy to serve your content for free\');</script>
1056  ';
1057         $r = $s->parseResponse($f);
1058         $v = $r->value();
1059         $s = $v->structmem('content');
1060         $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s->scalarval());
1061     }
1062
1063     function testStringBug()
1064     {
1065         $s = new xmlrpcmsg('dummy');
1066 $f = '<?xml version="1.0"?>
1067 <!-- $Id -->
1068 <!-- found by 2z69xks7bpy001@sneakemail.com, amongst others
1069  covers what happens when there\'s character data after </string>
1070  and before </value> -->
1071 <methodResponse>
1072 <params>
1073 <param>
1074 <value>
1075 <struct>
1076 <member>
1077 <name>success</name>
1078 <value>
1079 <boolean>1</boolean>
1080 </value>
1081 </member>
1082 <member>
1083 <name>sessionID</name>
1084 <value>
1085 <string>S300510007I</string>
1086 </value>
1087 </member>
1088 </struct>
1089 </value>
1090 </param>
1091 </params>
1092 </methodResponse> ';
1093         $r = $s->parseResponse($f);
1094         $v = $r->value();
1095         $s = $v->structmem('sessionID');
1096         $this->assertEquals('S300510007I', $s->scalarval());
1097     }
1098
1099     function testWhiteSpace()
1100     {
1101         $s = new xmlrpcmsg('dummy');
1102 $f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
1103 <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow
1104
1105
1106 and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
1107 ';
1108         $r = $s->parseResponse($f);
1109         $v = $r->value();
1110         $s = $v->structmem('content');
1111         $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s->scalarval());
1112     }
1113
1114     function testDoubleDataInArrayTag()
1115     {
1116         $s = new xmlrpcmsg('dummy');
1117 $f = '<?xml version="1.0"?><methodResponse><params><param><value><array>
1118 <data></data>
1119 <data></data>
1120 </array></value></param></params></methodResponse>
1121 ';
1122         $r = $s->parseResponse($f);
1123         $v = $r->faultCode();
1124         $this->assertEquals(2, $v);
1125 $f = '<?xml version="1.0"?><methodResponse><params><param><value><array>
1126 <data><value>Hello world</value></data>
1127 <data></data>
1128 </array></value></param></params></methodResponse>
1129 ';
1130         $r = $s->parseResponse($f);
1131         $v = $r->faultCode();
1132         $this->assertEquals(2, $v);
1133     }
1134
1135     function testDoubleStuffInValueTag()
1136     {
1137         $s = new xmlrpcmsg('dummy');
1138 $f = '<?xml version="1.0"?><methodResponse><params><param><value>
1139 <string>hello world</string>
1140 <array><data></data></array>
1141 </value></param></params></methodResponse>
1142 ';
1143         $r = $s->parseResponse($f);
1144         $v = $r->faultCode();
1145         $this->assertEquals(2, $v);
1146 $f = '<?xml version="1.0"?><methodResponse><params><param><value>
1147 <string>hello</string>
1148 <string>world</string>
1149 </value></param></params></methodResponse>
1150 ';
1151         $r = $s->parseResponse($f);
1152         $v = $r->faultCode();
1153         $this->assertEquals(2, $v);
1154 $f = '<?xml version="1.0"?><methodResponse><params><param><value>
1155 <string>hello</string>
1156 <struct><member><name>hello><value>world</value></member></struct>
1157 </value></param></params></methodResponse>
1158 ';
1159         $r = $s->parseResponse($f);
1160         $v = $r->faultCode();
1161         $this->assertEquals(2, $v);
1162     }
1163
1164     function testAutodecodeResponse()
1165     {
1166         $s = new xmlrpcmsg('dummy');
1167 $f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
1168 <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow
1169
1170
1171 and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
1172 ';
1173         $r = $s->parseResponse($f, true, 'phpvals');
1174         $v = $r->value();
1175         $s = $v['content'];
1176         $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s);
1177     }
1178
1179     function testNoDecodeResponse()
1180     {
1181         $s = new xmlrpcmsg('dummy');
1182 $f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
1183 <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow
1184
1185
1186 and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>';
1187         $r = $s->parseResponse($f, true, 'xml');
1188         $v = $r->value();
1189         $this->assertEquals($f, $v);
1190     }
1191
1192     function testAutoCoDec()
1193     {
1194         $data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00');
1195         $data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1);
1196         $data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2);
1197         //$keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
1198         $v1 = php_xmlrpc_encode($data, array('auto_dates'));
1199         $v2 = php_xmlrpc_decode_xml($v1->serialize());
1200         $this->assertEquals($v1, $v2);
1201         $r1 = new xmlrpcresp($v1);
1202         $r2 = php_xmlrpc_decode_xml($r1->serialize());
1203         $r2->serialize(); // needed to set internal member payload
1204         $this->assertEquals($r1, $r2);
1205         $m1 = new xmlrpcmsg('hello dolly', array($v1));
1206         $m2 = php_xmlrpc_decode_xml($m1->serialize());
1207         $m2->serialize(); // needed to set internal member payload
1208         $this->assertEquals($m1, $m2);
1209     }
1210
1211     function testUTF8Request()
1212     {
1213         $sendstring='κόσμε'; // Greek word 'kosme'. NB: NOT a valid ISO8859 string!
1214         $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
1215         $f = new xmlrpcval($sendstring, 'string');
1216         $v=$f->serialize();
1217         $this->assertEquals("<value><string>&#954;&#8057;&#963;&#956;&#949;</string></value>\n", $v);
1218         $GLOBALS['xmlrpc_internalencoding'] = 'ISO-8859-1';
1219     }
1220
1221     function testUTF8Response()
1222     {
1223         $s = new xmlrpcmsg('dummy');
1224 $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>
1225 <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>'.utf8_encode('������').'</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
1226 ';
1227         $r = $s->parseResponse($f, false, 'phpvals');
1228         $v = $r->value();
1229         $v = $v['content'];
1230         $this->assertEquals("������", $v);
1231 $f = '<?xml version="1.0" encoding="utf-8"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
1232 <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>'.utf8_encode('������').'</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
1233 ';
1234         $r = $s->parseResponse($f, false, 'phpvals');
1235         $v = $r->value();
1236         $v = $v['content'];
1237         $this->assertEquals("������", $v);
1238     }
1239
1240     function testUTF8IntString()
1241     {
1242         $v=new xmlrpcval(100, 'int');
1243         $s=$v->serialize('UTF-8');
1244         $this->assertequals("<value><int>100</int></value>\n", $s);
1245     }
1246
1247     function testStringInt()
1248     {
1249         $v=new xmlrpcval('hello world', 'int');
1250         $s=$v->serialize();
1251         $this->assertequals("<value><int>0</int></value>\n", $s);
1252     }
1253
1254     function testStructMemExists()
1255     {
1256         $v=php_xmlrpc_encode(array('hello' => 'world'));
1257         $b=$v->structmemexists('hello');
1258         $this->assertequals(true, $b);
1259         $b=$v->structmemexists('world');
1260         $this->assertequals(false, $b);
1261     }
1262
1263     function testNilvalue()
1264     {
1265         // default case: we do not accept nil values received
1266         $v = new xmlrpcval('hello', 'null');
1267         $r = new xmlrpcresp($v);
1268         $s = $r->serialize();
1269         $m = new xmlrpcmsg('dummy');
1270         $r = $m->parseresponse($s);
1271         $this->assertequals(2, $r->faultCode());
1272         // enable reception of nil values
1273         $GLOBALS['xmlrpc_null_extension'] = true;
1274         $r = $m->parseresponse($s);
1275         $v = $r->value();
1276         $this->assertequals('null', $v->scalartyp());
1277         // test with the apache version: EX:NIL
1278         $GLOBALS['xmlrpc_null_apache_encoding'] = true;
1279         // serialization
1280         $v = new xmlrpcval('hello', 'null');
1281         $s = $v->serialize();
1282         $this->assertequals(1, preg_match( '#<value><ex:nil/></value>#', $s ));
1283         // deserialization
1284         $r = new xmlrpcresp($v);
1285         $s = $r->serialize();
1286         $r = $m->parseresponse($s);
1287         $v = $r->value();
1288         $this->assertequals('null', $v->scalartyp());
1289         $GLOBALS['xmlrpc_null_extension'] = false;
1290         $r = $m->parseresponse($s);
1291         $this->assertequals(2, $r->faultCode());
1292     }
1293
1294     function TestLocale()
1295     {
1296         $locale = setlocale(LC_NUMERIC, 0);
1297         /// @todo on php 5.3/win setting locale to german does not seem to set decimal separator to comma...
1298         if (setlocale(LC_NUMERIC,'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false)
1299         {
1300             $v = new xmlrpcval(1.1, 'double');
1301             if (strpos($v->scalarval(), ',') == 1)
1302             {
1303                 $r = $v->serialize();
1304                 $this->assertequals(false, strpos($r, ','));
1305             }
1306             setlocale(LC_NUMERIC, $locale);
1307         }
1308     }
1309 }
1310
1311 class InvalidHostTests extends PHPUnit_TestCase
1312 {
1313     var $client = null;
1314
1315     function setUp()
1316     {
1317         global $DEBUG,$LOCALSERVER;
1318         $this->client=new xmlrpc_client('/NOTEXIST.php', $LOCALSERVER, 80);
1319         if($DEBUG)
1320         {
1321             $this->client->setDebug($DEBUG);
1322         }
1323     }
1324
1325     function test404()
1326     {
1327         $f = new xmlrpcmsg('examples.echo',array(
1328             new xmlrpcval('hello', 'string')
1329         ));
1330         $r = $this->client->send($f, 5);
1331         $this->assertEquals(5, $r->faultCode());
1332     }
1333
1334     function testSrvNotFound()
1335     {
1336         $f = new xmlrpcmsg('examples.echo',array(
1337             new xmlrpcval('hello', 'string')
1338         ));
1339         $this->client->server .= 'XXX';
1340         $r = $this->client->send($f, 5);
1341         $this->assertEquals(5, $r->faultCode());
1342     }
1343
1344     function testCurlKAErr()
1345     {
1346         global $LOCALSERVER, $URI;
1347         if(!function_exists('curl_init'))
1348         {
1349             $this->fail('CURL missing: cannot test curl keepalive errors');
1350             return;
1351         }
1352         $f = new xmlrpcmsg('examples.stringecho',array(
1353             new xmlrpcval('hello', 'string')
1354         ));
1355         // test 2 calls w. keepalive: 1st time connection ko, second time ok
1356         $this->client->server .= 'XXX';
1357         $this->client->keepalive = true;
1358         $r = $this->client->send($f, 5, 'http11');
1359         // in case we have a "universal dns resolver" getting in the way, we might get a 302 instead of a 404
1360         $this->assertTrue($r->faultCode() === 8 || $r->faultCode() == 5);
1361
1362         // now test a successful connection
1363         $server = explode(':', $LOCALSERVER);
1364         if(count($server) > 1)
1365         {
1366             $this->client->port = $server[1];
1367         }
1368         $this->client->server = $server[0];
1369         $this->client->path = $URI;
1370
1371         $r = $this->client->send($f, 5, 'http11');
1372         $this->assertEquals(0, $r->faultCode());
1373         $ro = $r->value();
1374         is_object( $ro ) && $this->assertEquals('hello', $ro->scalarVal());
1375     }
1376 }
1377
1378
1379 $suite->addTest(new LocalhostTests('testString'));
1380 $suite->addTest(new LocalhostTests('testAdding'));
1381 $suite->addTest(new LocalhostTests('testAddingDoubles'));
1382 $suite->addTest(new LocalhostTests('testInvalidNumber'));
1383 $suite->addTest(new LocalhostTests('testBoolean'));
1384 $suite->addTest(new LocalhostTests('testCountEntities'));
1385 $suite->addTest(new LocalhostTests('testBase64'));
1386 $suite->addTest(new LocalhostTests('testDateTime'));
1387 $suite->addTest(new LocalhostTests('testServerMulticall'));
1388 $suite->addTest(new LocalhostTests('testClientMulticall1'));
1389 $suite->addTest(new LocalhostTests('testClientMulticall2'));
1390 $suite->addTest(new LocalhostTests('testClientMulticall3'));
1391 $suite->addTest(new LocalhostTests('testCatchWarnings'));
1392 $suite->addTest(new LocalhostTests('testCatchExceptions'));
1393 $suite->addTest(new LocalhostTests('testZeroParams'));
1394 $suite->addTest(new LocalhostTests('testCodeInjectionServerSide'));
1395 $suite->addTest(new LocalhostTests('testAutoRegisteredFunction'));
1396 $suite->addTest(new LocalhostTests('testAutoRegisteredMethod'));
1397 $suite->addTest(new LocalhostTests('testSetCookies'));
1398 $suite->addTest(new LocalhostTests('testGetCookies'));
1399 $suite->addTest(new LocalhostTests('testSendTwiceSameMsg'));
1400
1401 $suite->addTest(new LocalhostMultiTests('testUTF8Requests'));
1402 $suite->addTest(new LocalhostMultiTests('testUTF8Responses'));
1403 $suite->addTest(new LocalhostMultiTests('testISORequests'));
1404 $suite->addTest(new LocalhostMultiTests('testISOResponses'));
1405 $suite->addTest(new LocalhostMultiTests('testGzip'));
1406 $suite->addTest(new LocalhostMultiTests('testDeflate'));
1407 $suite->addTest(new LocalhostMultiTests('testProxy'));
1408 $suite->addTest(new LocalhostMultiTests('testHttp11'));
1409 $suite->addTest(new LocalhostMultiTests('testHttp11Gzip'));
1410 $suite->addTest(new LocalhostMultiTests('testHttp11Deflate'));
1411 $suite->addTest(new LocalhostMultiTests('testKeepAlives'));
1412 $suite->addTest(new LocalhostMultiTests('testHttp11Proxy'));
1413 $suite->addTest(new LocalhostMultiTests('testHttps'));
1414 $suite->addTest(new LocalhostMultiTests('testHttpsProxy'));
1415
1416 $suite->addTest(new InvalidHostTests('test404'));
1417 //$suite->addTest(new InvalidHostTests('testSrvNotFound'));
1418 $suite->addTest(new InvalidHostTests('testCurlKAErr'));
1419
1420 $suite->addTest(new ParsingBugsTests('testMinusOneString'));
1421 $suite->addTest(new ParsingBugsTests('testUnicodeInMemberName'));
1422 $suite->addTest(new ParsingBugsTests('testUnicodeInErrorString'));
1423 $suite->addTest(new ParsingBugsTests('testValidNumbers'));
1424 $suite->addTest(new ParsingBugsTests('testAddScalarToStruct'));
1425 $suite->addTest(new ParsingBugsTests('testAddStructToStruct'));
1426 $suite->addTest(new ParsingBugsTests('testAddArrayToArray'));
1427 $suite->addTest(new ParsingBugsTests('testEncodeArray'));
1428 $suite->addTest(new ParsingBugsTests('testEncodeRecursive'));
1429 $suite->addTest(new ParsingBugsTests('testBrokenrequests'));
1430 $suite->addTest(new ParsingBugsTests('testBrokenresponses'));
1431 $suite->addTest(new ParsingBugsTests('testBuggyHttp'));
1432 $suite->addTest(new ParsingBugsTests('testStringBug'));
1433 $suite->addTest(new ParsingBugsTests('testWhiteSpace'));
1434 $suite->addTest(new ParsingBugsTests('testAutodecodeResponse'));
1435 $suite->addTest(new ParsingBugsTests('testNoDecodeResponse'));
1436 $suite->addTest(new ParsingBugsTests('testAutoCoDec'));
1437 $suite->addTest(new ParsingBugsTests('testUTF8Response'));
1438 $suite->addTest(new ParsingBugsTests('testUTF8Request'));
1439 $suite->addTest(new ParsingBugsTests('testUTF8IntString'));
1440 $suite->addTest(new ParsingBugsTests('testStringInt'));
1441 $suite->addTest(new ParsingBugsTests('testStructMemExists'));
1442 $suite->addTest(new ParsingBugsTests('testDoubleDataInArrayTag'));
1443 $suite->addTest(new ParsingBugsTests('testDoubleStuffInValueTag'));
1444 $suite->addTest(new ParsingBugsTests('testNilValue'));
1445 $suite->addTest(new ParsingBugsTests('testLocale'));
1446
1447 $title = 'XML-RPC Unit Tests';
1448
1449 if(isset($only))
1450 {
1451     $suite = new PHPUnit_TestSuite($only);
1452 }
1453
1454 if(isset($_SERVER['REQUEST_METHOD']))
1455 {
1456     echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n<head>\n<title>$title</title>\n</head>\n<body>\n<h1>$title</h1>\n";
1457 }
1458 else
1459 {
1460     echo "$title\n\n";
1461 }
1462
1463 if(isset($_SERVER['REQUEST_METHOD']))
1464 {
1465     echo "<h3>Using lib version: $xmlrpcVersion on PHP version: ".phpversion()."</h3>\n";
1466     echo '<h3>Running '.$suite->testCount().' tests (some of which are multiple) against servers: http://'.htmlspecialchars($LOCALSERVER.$URI).' and https://'.htmlspecialchars($HTTPSSERVER.$HTTPSURI)."\n ...</h3>\n";
1467     flush();
1468     @ob_flush();
1469 }
1470 else
1471 {
1472     echo "Using lib version: $xmlrpcVersion on PHP version: ".phpversion()."\n";
1473     echo 'Running '.$suite->testCount().' tests (some of which are multiple) against servers: http://'.$LOCALSERVER.$URI.' and https://'.$HTTPSSERVER.$HTTPSURI."\n\n";
1474 }
1475
1476 // do some basic timing measurement
1477 list($micro, $sec) = explode(' ', microtime());
1478 $start_time = $sec + $micro;
1479
1480 $PHPUnit = new PHPUnit;
1481 $result = $PHPUnit->run($suite, ($DEBUG == 0 ? '.' : '<hr/>'));
1482
1483 list($micro, $sec) = explode(' ', microtime());
1484 $end_time = $sec + $micro;
1485
1486 if(!isset($_SERVER['REQUEST_METHOD']))
1487 {
1488     echo $result->toString()."\n";
1489 }
1490
1491 if(isset($_SERVER['REQUEST_METHOD']))
1492 {
1493     echo '<h3>'.$result->failureCount()." test failures</h3>\n";
1494     printf("Time spent: %.2f secs<br/>\n", $end_time - $start_time);
1495 }
1496 else
1497 {
1498     echo $result->failureCount()." test failures\n";
1499     printf("Time spent: %.2f secs\n", $end_time - $start_time);
1500 }
1501
1502 if($result->failureCount() && !$DEBUG)
1503 {
1504     $target = strpos($_SERVER['PHP_SELF'], '?') ? $_SERVER['PHP_SELF'].'&amp;DEBUG=1' : $_SERVER['PHP_SELF'].'?DEBUG=1';
1505     $t2 = strpos($_SERVER['PHP_SELF'], '?') ? $_SERVER['PHP_SELF'].'&amp;DEBUG=2' : $_SERVER['PHP_SELF'].'?DEBUG=2';
1506     if(isset($_SERVER['REQUEST_METHOD']))
1507     {
1508         echo '<p>Run testsuite with <a href="'.$target.'">DEBUG=1</a> to have more detail about tests results. Or with <a href="'.$t2.'">DEBUG=2</a> for even more.</p>'."\n";
1509     }
1510     else
1511     {
1512         echo "Run testsuite with DEBUG=1 (or 2) to have more detail about tests results\n";
1513     }
1514 }
1515
1516 if(isset($_SERVER['REQUEST_METHOD']))
1517 {
1518 ?>
1519 <a href="#" onclick="if (document.getElementById('opts').style.display == 'block') document.getElementById('opts').style.display = 'none'; else document.getElementById('opts').style.display = 'block';">More options...</a>
1520 <div id="opts" style="display: none;">
1521 <form method="GET" style="border: 1px solid silver; margin: 5px; padding: 5px; font-family: monospace;">
1522 HTTP Server:&nbsp;&nbsp;<input name="LOCALSERVER" size="30" value="<?php echo htmlspecialchars($LOCALSERVER); ?>"/> Path: <input name="URI"  size="30" value="<?php echo htmlspecialchars($URI); ?>"/><br/>
1523 HTTPS Server: <input name="HTTPSSERVER" size="30" value="<?php echo htmlspecialchars($HTTPSSERVER); ?>"/> Path: <input name="HTTPSURI"  size="30" value="<?php echo htmlspecialchars($HTTPSURI); ?>"/> Do not verify cert: <input name="HTTPSIGNOREPEER" value="true" type="checkbox" <?php if ($HTTPSIGNOREPEER) echo 'checked="checked"'; ?>/><br/>
1524
1525 Proxy Server: <input name="PROXY" size="30" value="<?php echo isset($PROXY) ? htmlspecialchars($PROXY) : ''; ?>"/> <input type="submit" value="Run Testsuite"/>
1526 </form>
1527 </div>
1528 <?php
1529 echo $result->toHTML()."\n</body>\n</html>\n";
1530 }
1531 ?>