Set default internal charset to UTF8 and change tests accordingly; add function has_e...
[plcapi.git] / tests / 3LocalhostTest.php
1 <?php
2
3 include_once __DIR__ . '/../lib/xmlrpc.inc';
4 include_once __DIR__ . '/../lib/xmlrpc_wrappers.inc';
5
6 include_once __DIR__ . '/parse_args.php';
7
8 class LocalhostTest extends PHPUnit_Framework_TestCase
9 {
10     /** @var xmlrpc_client $client */
11     protected $client = null;
12     protected $method = 'http';
13     protected $timeout = 10;
14     protected $request_compression = null;
15     protected $accepted_compression = '';
16     protected $args = array();
17
18     protected static $failed_tests = array();
19
20     protected $testId;
21     /** @var boolean $collectCodeCoverageInformation */
22     protected $collectCodeCoverageInformation;
23     protected $coverageScriptUrl;
24
25     public static function fail($message = '')
26     {
27         // save in a static var that this particular test has failed
28         // (but only if not called from subclass objects / multitests)
29         if (function_exists('debug_backtrace') && strtolower(get_called_class()) == 'localhosttests') {
30             $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
31             for ($i = 0; $i < count($trace); $i++) {
32                 if (strpos($trace[$i]['function'], 'test') === 0) {
33                     self::$failed_tests[$trace[$i]['function']] = true;
34                     break;
35                 }
36             }
37         }
38
39         parent::fail($message);
40     }
41
42     /**
43      * Reimplemented to allow us to collect code coverage info from the target server.
44      * Code taken from PHPUnit_Extensions_Selenium2TestCase
45      *
46      * @param PHPUnit_Framework_TestResult $result
47      * @return PHPUnit_Framework_TestResult
48      * @throws Exception
49      */
50     public function run(PHPUnit_Framework_TestResult $result = NULL)
51     {
52         $this->testId = get_class($this) . '__' . $this->getName();
53
54         if ($result === NULL) {
55             $result = $this->createResult();
56         }
57
58         $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
59
60         parent::run($result);
61
62         if ($this->collectCodeCoverageInformation) {
63             $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage(
64                 $this->coverageScriptUrl,
65                 $this->testId
66             );
67             $result->getCodeCoverage()->append(
68                 $coverage->get(), $this
69             );
70         }
71
72         // do not call this before to give the time to the Listeners to run
73         //$this->getStrategy()->endOfTest($this->session);
74
75         return $result;
76     }
77
78     public function setUp()
79     {
80         $this->args = argParser::getArgs();
81
82         $server = explode(':', $this->args['LOCALSERVER']);
83         if (count($server) > 1) {
84             $this->client = new xmlrpc_client($this->args['URI'], $server[0], $server[1]);
85         } else {
86             $this->client = new xmlrpc_client($this->args['URI'], $this->args['LOCALSERVER']);
87         }
88
89         $this->client->setDebug($this->args['DEBUG']);
90         $this->client->request_compression = $this->request_compression;
91         $this->client->accepted_compression = $this->accepted_compression;
92
93         $this->coverageScriptUrl = 'http://' . $this->args['LOCALSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['URI'] );
94
95         if ($this->args['DEBUG'] == 1)
96             ob_start();
97     }
98
99     protected function tearDown()
100     {
101         if ($this->args['DEBUG'] != 1)
102             return;
103         $out = ob_get_clean();
104         $status = $this->getStatus();
105         if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR
106             || $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
107             echo $out;
108         }
109     }
110
111     protected function send($msg, $errorCode = 0, $returnResponse = false)
112     {
113         if ($this->collectCodeCoverageInformation) {
114             $this->client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId);
115         }
116
117         $r = $this->client->send($msg, $this->timeout, $this->method);
118         // for multicall, return directly array of responses
119         if (is_array($r)) {
120             return $r;
121         }
122         if (is_array($errorCode)) {
123             $this->assertContains($r->faultCode(), $errorCode, 'Error ' . $r->faultCode() . ' connecting to server: ' . $r->faultString());
124         } else {
125             $this->assertEquals($errorCode, $r->faultCode(), 'Error ' . $r->faultCode() . ' connecting to server: ' . $r->faultString());
126         }
127         if (!$r->faultCode()) {
128             if ($returnResponse) {
129                 return $r;
130             } else {
131                 return $r->value();
132             }
133         } else {
134             return;
135         }
136     }
137
138     public function testString()
139     {
140         $sendString = "here are 3 \"entities\": < > & " .
141             "and here's a dollar sign: \$pretendvarname and a backslash too: " . chr(92) .
142             " - isn't that great? \\\"hackery\\\" at it's best " .
143             " also don't want to miss out on \$item[0]. " .
144             "The real weird stuff follows: CRLF here" . chr(13) . chr(10) .
145             "a simple CR here" . chr(13) .
146             "a simple LF here" . chr(10) .
147             "and then LFCR" . chr(10) . chr(13) .
148             "last but not least weird names: G" . chr(252) . "nter, El" . chr(232) . "ne, and an xml comment closing tag: -->";
149         $f = new xmlrpcmsg('examples.stringecho', array(
150             new xmlrpcval($sendString, 'string'),
151         ));
152         $v = $this->send($f);
153         if ($v) {
154             // when sending/receiving non-US-ASCII encoded strings, XML says cr-lf can be normalized.
155             // so we relax our tests...
156             $l1 = strlen($sendString);
157             $l2 = strlen($v->scalarval());
158             if ($l1 == $l2) {
159                 $this->assertEquals($sendString, $v->scalarval());
160             } else {
161                 $this->assertEquals(str_replace(array("\r\n", "\r"), array("\n", "\n"), $sendString), $v->scalarval());
162             }
163         }
164     }
165
166     public function testLatin1String()
167     {
168         $sendString =
169             "last but not least weird names: G" . chr(252) . "nter, El" . chr(232) . "ne";
170         $f = '<?xml version="1.0" encoding="ISO-8859-1"?><methodCall><methodName>examples.stringecho</methodName><params><param><value>'.
171             $sendString.
172             '</value></param></params></methodCall>';
173         $v = $this->send($f);
174         if ($v) {
175             $this->assertEquals($sendString, $v->scalarval());
176         }
177     }
178
179     /*public function testLatin1Method()
180     {
181         $f = new xmlrpcmsg("tests.iso88591methodname." . chr(224) . chr(252) . chr(232), array(
182             new xmlrpcval('hello')
183         ));
184         $v = $this->send($f);
185         if ($v) {
186             $this->assertEquals('hello', $v->scalarval());
187         }
188     }*/
189
190     public function testUtf8Method()
191     {
192         PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'UTF-8';
193         $f = new xmlrpcmsg("tests.utf8methodname." . 'κόσμε', array(
194             new xmlrpcval('hello')
195         ));
196         $v = $this->send($f);
197         if ($v) {
198             $this->assertEquals('hello', $v->scalarval());
199         }
200         PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'ISO-8859-1';
201     }
202
203     public function testAddingDoubles()
204     {
205         // note that rounding errors mean we
206         // keep precision to sensible levels here ;-)
207         $a = 12.13;
208         $b = -23.98;
209         $f = new xmlrpcmsg('examples.addtwodouble', array(
210             new xmlrpcval($a, 'double'),
211             new xmlrpcval($b, 'double'),
212         ));
213         $v = $this->send($f);
214         if ($v) {
215             $this->assertEquals($a + $b, $v->scalarval());
216         }
217     }
218
219     public function testAdding()
220     {
221         $f = new xmlrpcmsg('examples.addtwo', array(
222             new xmlrpcval(12, 'int'),
223             new xmlrpcval(-23, 'int'),
224         ));
225         $v = $this->send($f);
226         if ($v) {
227             $this->assertEquals(12 - 23, $v->scalarval());
228         }
229     }
230
231     public function testInvalidNumber()
232     {
233         $f = new xmlrpcmsg('examples.addtwo', array(
234             new xmlrpcval('fred', 'int'),
235             new xmlrpcval("\"; exec('ls')", 'int'),
236         ));
237         $v = $this->send($f);
238         /// @todo a fault condition should be generated here
239         /// by the server, which we pick up on
240         if ($v) {
241             $this->assertEquals(0, $v->scalarval());
242         }
243     }
244
245     public function testBoolean()
246     {
247         $f = new xmlrpcmsg('examples.invertBooleans', array(
248             new xmlrpcval(array(
249                 new xmlrpcval(true, 'boolean'),
250                 new xmlrpcval(false, 'boolean'),
251                 new xmlrpcval(1, 'boolean'),
252                 new xmlrpcval(0, 'boolean')
253             ),
254                 'array'
255             ),));
256         $answer = '0101';
257         $v = $this->send($f);
258         if ($v) {
259             $sz = $v->arraysize();
260             $got = '';
261             for ($i = 0; $i < $sz; $i++) {
262                 $b = $v->arraymem($i);
263                 if ($b->scalarval()) {
264                     $got .= '1';
265                 } else {
266                     $got .= '0';
267                 }
268             }
269             $this->assertEquals($answer, $got);
270         }
271     }
272
273     public function testBase64()
274     {
275         $sendString = 'Mary had a little lamb,
276 Whose fleece was white as snow,
277 And everywhere that Mary went
278 the lamb was sure to go.
279
280 Mary had a little lamb
281 She tied it to a pylon
282 Ten thousand volts went down its back
283 And turned it into nylon';
284         $f = new xmlrpcmsg('examples.decode64', array(
285             new xmlrpcval($sendString, 'base64'),
286         ));
287         $v = $this->send($f);
288         if ($v) {
289             if (strlen($sendString) == strlen($v->scalarval())) {
290                 $this->assertEquals($sendString, $v->scalarval());
291             } else {
292                 $this->assertEquals(str_replace(array("\r\n", "\r"), array("\n", "\n"), $sendString), $v->scalarval());
293             }
294         }
295     }
296
297     public function testDateTime()
298     {
299         $time = time();
300         $t1 = new xmlrpcval($time, 'dateTime.iso8601');
301         $t2 = new xmlrpcval(iso8601_encode($time), 'dateTime.iso8601');
302         $this->assertEquals($t1->serialize(), $t2->serialize());
303         if (class_exists('DateTime')) {
304             $datetime = new DateTime();
305             // skip this test for php 5.2. It is a bit harder there to build a DateTime from unix timestamp with proper TZ info
306             if (is_callable(array($datetime, 'setTimestamp'))) {
307                 $t3 = new xmlrpcval($datetime->setTimestamp($time), 'dateTime.iso8601');
308                 $this->assertEquals($t1->serialize(), $t3->serialize());
309             }
310         }
311     }
312
313     public function testCountEntities()
314     {
315         $sendString = "h'fd>onc>>l>>rw&bpu>q>e<v&gxs<ytjzkami<";
316         $f = new xmlrpcmsg('validator1.countTheEntities', array(
317             new xmlrpcval($sendString, 'string'),
318         ));
319         $v = $this->send($f);
320         if ($v) {
321             $got = '';
322             $expected = '37210';
323             $expect_array = array('ctLeftAngleBrackets', 'ctRightAngleBrackets', 'ctAmpersands', 'ctApostrophes', 'ctQuotes');
324             while (list(, $val) = each($expect_array)) {
325                 $b = $v->structmem($val);
326                 $got .= $b->me['int'];
327             }
328             $this->assertEquals($expected, $got);
329         }
330     }
331
332     public function _multicall_msg($method, $params)
333     {
334         $struct['methodName'] = new xmlrpcval($method, 'string');
335         $struct['params'] = new xmlrpcval($params, 'array');
336
337         return new xmlrpcval($struct, 'struct');
338     }
339
340     public function testServerMulticall()
341     {
342         // We manually construct a system.multicall() call to ensure
343         // that the server supports it.
344
345         // NB: This test will NOT pass if server does not support system.multicall.
346
347         // Based on http://xmlrpc-c.sourceforge.net/hacks/test_multicall.py
348         $good1 = $this->_multicall_msg(
349             'system.methodHelp',
350             array(php_xmlrpc_encode('system.listMethods')));
351         $bad = $this->_multicall_msg(
352             'test.nosuch',
353             array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
354         $recursive = $this->_multicall_msg(
355             'system.multicall',
356             array(new xmlrpcval(array(), 'array')));
357         $good2 = $this->_multicall_msg(
358             'system.methodSignature',
359             array(php_xmlrpc_encode('system.listMethods')));
360         $arg = new xmlrpcval(
361             array($good1, $bad, $recursive, $good2),
362             'array'
363         );
364
365         $f = new xmlrpcmsg('system.multicall', array($arg));
366         $v = $this->send($f);
367         if ($v) {
368             //$this->assertTrue($r->faultCode() == 0, "fault from system.multicall");
369             $this->assertTrue($v->arraysize() == 4, "bad number of return values");
370
371             $r1 = $v->arraymem(0);
372             $this->assertTrue(
373                 $r1->kindOf() == 'array' && $r1->arraysize() == 1,
374                 "did not get array of size 1 from good1"
375             );
376
377             $r2 = $v->arraymem(1);
378             $this->assertTrue(
379                 $r2->kindOf() == 'struct',
380                 "no fault from bad"
381             );
382
383             $r3 = $v->arraymem(2);
384             $this->assertTrue(
385                 $r3->kindOf() == 'struct',
386                 "recursive system.multicall did not fail"
387             );
388
389             $r4 = $v->arraymem(3);
390             $this->assertTrue(
391                 $r4->kindOf() == 'array' && $r4->arraysize() == 1,
392                 "did not get array of size 1 from good2"
393             );
394         }
395     }
396
397     public function testClientMulticall1()
398     {
399         // NB: This test will NOT pass if server does not support system.multicall.
400
401         $this->client->no_multicall = false;
402
403         $good1 = new xmlrpcmsg('system.methodHelp',
404             array(php_xmlrpc_encode('system.listMethods')));
405         $bad = new xmlrpcmsg('test.nosuch',
406             array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
407         $recursive = new xmlrpcmsg('system.multicall',
408             array(new xmlrpcval(array(), 'array')));
409         $good2 = new xmlrpcmsg('system.methodSignature',
410             array(php_xmlrpc_encode('system.listMethods'))
411         );
412
413         $r = $this->send(array($good1, $bad, $recursive, $good2));
414         if ($r) {
415             $this->assertTrue(count($r) == 4, "wrong number of return values");
416         }
417
418         $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
419         if (!$r[0]->faultCode()) {
420             $val = $r[0]->value();
421             $this->assertTrue(
422                 $val->kindOf() == 'scalar' && $val->scalartyp() == 'string',
423                 "good1 did not return string"
424             );
425         }
426         $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
427         $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall");
428         $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
429         if (!$r[3]->faultCode()) {
430             $val = $r[3]->value();
431             $this->assertTrue($val->kindOf() == 'array', "good2 did not return array");
432         }
433         // This is the only assert in this test which should fail
434         // if the test server does not support system.multicall.
435         $this->assertTrue($this->client->no_multicall == false,
436             "server does not support system.multicall"
437         );
438     }
439
440     public function testClientMulticall2()
441     {
442         // NB: This test will NOT pass if server does not support system.multicall.
443
444         $this->client->no_multicall = true;
445
446         $good1 = new xmlrpcmsg('system.methodHelp',
447             array(php_xmlrpc_encode('system.listMethods')));
448         $bad = new xmlrpcmsg('test.nosuch',
449             array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
450         $recursive = new xmlrpcmsg('system.multicall',
451             array(new xmlrpcval(array(), 'array')));
452         $good2 = new xmlrpcmsg('system.methodSignature',
453             array(php_xmlrpc_encode('system.listMethods'))
454         );
455
456         $r = $this->send(array($good1, $bad, $recursive, $good2));
457         if ($r) {
458             $this->assertTrue(count($r) == 4, "wrong number of return values");
459         }
460
461         $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
462         if (!$r[0]->faultCode()) {
463             $val = $r[0]->value();
464             $this->assertTrue(
465                 $val->kindOf() == 'scalar' && $val->scalartyp() == 'string',
466                 "good1 did not return string");
467         }
468         $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
469         $this->assertTrue($r[2]->faultCode() == 0, "fault from (non recursive) system.multicall");
470         $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
471         if (!$r[3]->faultCode()) {
472             $val = $r[3]->value();
473             $this->assertTrue($val->kindOf() == 'array', "good2 did not return array");
474         }
475     }
476
477     public function testClientMulticall3()
478     {
479         // NB: This test will NOT pass if server does not support system.multicall.
480
481         $this->client->return_type = 'phpvals';
482         $this->client->no_multicall = false;
483
484         $good1 = new xmlrpcmsg('system.methodHelp',
485             array(php_xmlrpc_encode('system.listMethods')));
486         $bad = new xmlrpcmsg('test.nosuch',
487             array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
488         $recursive = new xmlrpcmsg('system.multicall',
489             array(new xmlrpcval(array(), 'array')));
490         $good2 = new xmlrpcmsg('system.methodSignature',
491             array(php_xmlrpc_encode('system.listMethods'))
492         );
493
494         $r = $this->send(array($good1, $bad, $recursive, $good2));
495         if ($r) {
496             $this->assertTrue(count($r) == 4, "wrong number of return values");
497         }
498         $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
499         if (!$r[0]->faultCode()) {
500             $val = $r[0]->value();
501             $this->assertTrue(
502                 is_string($val), "good1 did not return string");
503         }
504         $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
505         $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall");
506         $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
507         if (!$r[3]->faultCode()) {
508             $val = $r[3]->value();
509             $this->assertTrue(is_array($val), "good2 did not return array");
510         }
511         $this->client->return_type = 'xmlrpcvals';
512     }
513
514     public function testCatchWarnings()
515     {
516         $f = new xmlrpcmsg('tests.generatePHPWarning', array(
517             new xmlrpcval('whatever', 'string'),
518         ));
519         $v = $this->send($f);
520         if ($v) {
521             $this->assertEquals(true, $v->scalarval());
522         }
523     }
524
525     public function testCatchExceptions()
526     {
527         $f = new xmlrpcmsg('tests.raiseException', array(
528             new xmlrpcval('whatever', 'string'),
529         ));
530         $v = $this->send($f, $GLOBALS['xmlrpcerr']['server_error']);
531         $this->client->path = $this->args['URI'] . '?EXCEPTION_HANDLING=1';
532         $v = $this->send($f, 1);
533         $this->client->path = $this->args['URI'] . '?EXCEPTION_HANDLING=2';
534         // depending on whether display_errors is ON or OFF on the server, we will get back a different error here,
535         // as php will generate an http status code of either 200 or 500...
536         $v = $this->send($f, array($GLOBALS['xmlrpcerr']['invalid_return'], $GLOBALS['xmlrpcerr']['http_error']));
537     }
538
539     public function testZeroParams()
540     {
541         $f = new xmlrpcmsg('system.listMethods');
542         $v = $this->send($f);
543     }
544
545     public function testCodeInjectionServerSide()
546     {
547         $f = new xmlrpcmsg('system.MethodHelp');
548         $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>";
549         $v = $this->send($f);
550         if ($v) {
551             $this->assertEquals(0, $v->structsize());
552         }
553     }
554
555     public function testAutoRegisteredFunction()
556     {
557         $f = new xmlrpcmsg('examples.php.getStateName', array(
558             new xmlrpcval(23, 'int'),
559         ));
560         $v = $this->send($f);
561         if ($v) {
562             $this->assertEquals('Michigan', $v->scalarval());
563         } else {
564             $this->fail('Note: server can only auto register functions if running with PHP 5.0.3 and up');
565         }
566     }
567
568     public function testAutoRegisteredClass()
569     {
570         $f = new xmlrpcmsg('examples.php2.getStateName', array(
571             new xmlrpcval(23, 'int'),
572         ));
573         $v = $this->send($f);
574         if ($v) {
575             $this->assertEquals('Michigan', $v->scalarval());
576             $f = new xmlrpcmsg('examples.php3.getStateName', array(
577                 new xmlrpcval(23, 'int'),
578             ));
579             $v = $this->send($f);
580             if ($v) {
581                 $this->assertEquals('Michigan', $v->scalarval());
582             }
583         } else {
584             $this->fail('Note: server can only auto register class methods if running with PHP 5.0.3 and up');
585         }
586     }
587
588     public function testAutoRegisteredMethod()
589     {
590         // make a 'deep client copy' as the original one might have many properties set
591         $func = wrap_xmlrpc_method($this->client, 'examples.getStateName', array('simple_client_copy' => 1));
592         if ($func == '') {
593             $this->fail('Registration of examples.getStateName failed');
594         } else {
595             $v = $func(23);
596             // work around bug in current version of phpunit
597             if (is_object($v)) {
598                 $v = var_export($v, true);
599             }
600             $this->assertEquals('Michigan', $v);
601         }
602     }
603
604     public function testGetCookies()
605     {
606         // let server set to us some cookies we tell it
607         $cookies = array(
608             //'c1' => array(),
609             'c2' => array('value' => 'c2'),
610             'c3' => array('value' => 'c3', 'expires' => time() + 60 * 60 * 24 * 30),
611             'c4' => array('value' => 'c4', 'expires' => time() + 60 * 60 * 24 * 30, 'path' => '/'),
612             'c5' => array('value' => 'c5', 'expires' => time() + 60 * 60 * 24 * 30, 'path' => '/', 'domain' => 'localhost'),
613         );
614         $cookiesval = php_xmlrpc_encode($cookies);
615         $f = new xmlrpcmsg('examples.setcookies', array($cookiesval));
616         $r = $this->send($f, 0, true);
617         if ($r) {
618             $v = $r->value();
619             $this->assertEquals(1, $v->scalarval());
620             // now check if we decoded the cookies as we had set them
621             $rcookies = $r->cookies();
622             // remove extra cookies which might have been set by proxies
623             foreach ($rcookies as $c => $v) {
624                 if (!in_array($c, array('c2', 'c3', 'c4', 'c5'))) {
625                     unset($rcookies[$c]);
626                 }
627                 // Seems like we get this when using php-fpm and php 5.5+ ...
628                 if (isset($rcookies[$c]['Max-Age'])) {
629                     unset($rcookies[$c]['Max-Age']);
630                 }
631             }
632             foreach ($cookies as $c => $v) {
633                 // format for date string in cookies: 'Mon, 31 Oct 2005 13:50:56 GMT'
634                 // but PHP versions differ on that, some use 'Mon, 31-Oct-2005 13:50:56 GMT'...
635                 if (isset($v['expires'])) {
636                     if (isset($rcookies[$c]['expires']) && strpos($rcookies[$c]['expires'], '-')) {
637                         $cookies[$c]['expires'] = gmdate('D, d\-M\-Y H:i:s \G\M\T', $cookies[$c]['expires']);
638                     } else {
639                         $cookies[$c]['expires'] = gmdate('D, d M Y H:i:s \G\M\T', $cookies[$c]['expires']);
640                     }
641                 }
642             }
643
644             $this->assertEquals($cookies, $rcookies);
645         }
646     }
647
648     public function testSetCookies()
649     {
650         // let server set to us some cookies we tell it
651         $cookies = array(
652             'c0' => null,
653             'c1' => 1,
654             'c2' => '2 3',
655             'c3' => '!@#$%^&*()_+|}{":?><,./\';[]\\=-',
656         );
657         $f = new xmlrpcmsg('examples.getcookies', array());
658         foreach ($cookies as $cookie => $val) {
659             $this->client->setCookie($cookie, $val);
660             $cookies[$cookie] = (string)$cookies[$cookie];
661         }
662         $r = $this->client->send($f, $this->timeout, $this->method);
663         $this->assertEquals(0, $r->faultCode(), 'Error ' . $r->faultCode() . ' connecting to server: ' . $r->faultString());
664         if (!$r->faultCode()) {
665             $v = $r->value();
666             $v = php_xmlrpc_decode($v);
667
668             // take care for the extra cookie used for coverage collection
669             if (isset($v['PHPUNIT_SELENIUM_TEST_ID'])) {
670                 unset($v['PHPUNIT_SELENIUM_TEST_ID']);
671             }
672
673             // on IIS and Apache getallheaders returns something slightly different...
674             $this->assertEquals($cookies, $v);
675         }
676     }
677
678     public function testSendTwiceSameMsg()
679     {
680         $f = new xmlrpcmsg('examples.stringecho', array(
681             new xmlrpcval('hello world', 'string'),
682         ));
683         $v1 = $this->send($f);
684         $v2 = $this->send($f);
685         if ($v1 && $v2) {
686             $this->assertEquals($v1, $v2);
687         }
688     }
689 }