3 include_once __DIR__ . '/../lib/xmlrpc.inc';
4 include_once __DIR__ . '/../lib/xmlrpc_wrappers.inc';
6 include_once __DIR__ . '/parse_args.php';
9 * Tests which involve interaction between the client and the server.
10 * They are run against the server found in demo/server.php
12 class LocalhostTest extends PHPUnit_Framework_TestCase
14 /** @var xmlrpc_client $client */
15 protected $client = null;
16 protected $method = 'http';
17 protected $timeout = 10;
18 protected $request_compression = null;
19 protected $accepted_compression = '';
20 protected $args = array();
22 protected static $failed_tests = array();
25 /** @var boolean $collectCodeCoverageInformation */
26 protected $collectCodeCoverageInformation;
27 protected $coverageScriptUrl;
29 public static function fail($message = '')
31 // save in a static var that this particular test has failed
32 // (but only if not called from subclass objects / multitests)
33 if (function_exists('debug_backtrace') && strtolower(get_called_class()) == 'localhosttests') {
34 $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
35 for ($i = 0; $i < count($trace); $i++) {
36 if (strpos($trace[$i]['function'], 'test') === 0) {
37 self::$failed_tests[$trace[$i]['function']] = true;
43 parent::fail($message);
47 * Reimplemented to allow us to collect code coverage info from the target server.
48 * Code taken from PHPUnit_Extensions_Selenium2TestCase
50 * @param PHPUnit_Framework_TestResult $result
51 * @return PHPUnit_Framework_TestResult
54 public function run(PHPUnit_Framework_TestResult $result = NULL)
56 $this->testId = get_class($this) . '__' . $this->getName();
58 if ($result === NULL) {
59 $result = $this->createResult();
62 $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
66 if ($this->collectCodeCoverageInformation) {
67 $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage(
68 $this->coverageScriptUrl,
71 $result->getCodeCoverage()->append(
72 $coverage->get(), $this
76 // do not call this before to give the time to the Listeners to run
77 //$this->getStrategy()->endOfTest($this->session);
82 public function setUp()
84 $this->args = argParser::getArgs();
86 $server = explode(':', $this->args['LOCALSERVER']);
87 if (count($server) > 1) {
88 $this->client = new xmlrpc_client($this->args['URI'], $server[0], $server[1]);
90 $this->client = new xmlrpc_client($this->args['URI'], $this->args['LOCALSERVER']);
93 $this->client->setDebug($this->args['DEBUG']);
94 $this->client->request_compression = $this->request_compression;
95 $this->client->accepted_compression = $this->accepted_compression;
97 $this->coverageScriptUrl = 'http://' . $this->args['LOCALSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['URI'] );
99 if ($this->args['DEBUG'] == 1)
103 protected function tearDown()
105 if ($this->args['DEBUG'] != 1)
107 $out = ob_get_clean();
108 $status = $this->getStatus();
109 if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR
110 || $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
116 * @param PhpXmlRpc\Request|array $msg
117 * @param int|array $errorCode
118 * @param bool $returnResponse
119 * @return mixed|\PhpXmlRpc\Response|\PhpXmlRpc\Response[]|\PhpXmlRpc\Value|string|null
121 protected function send($msg, $errorCode = 0, $returnResponse = false)
123 if ($this->collectCodeCoverageInformation) {
124 $this->client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId);
127 $r = $this->client->send($msg, $this->timeout, $this->method);
128 // for multicall, return directly array of responses
132 if (is_array($errorCode)) {
133 $this->assertContains($r->faultCode(), $errorCode, 'Error ' . $r->faultCode() . ' connecting to server: ' . $r->faultString());
135 $this->assertEquals($errorCode, $r->faultCode(), 'Error ' . $r->faultCode() . ' connecting to server: ' . $r->faultString());
137 if (!$r->faultCode()) {
138 if ($returnResponse) {
149 * Adds (and replaces) query params to the url currently used by the client
152 protected function addQueryParams($data)
154 $query = parse_url($this->client->path, PHP_URL_QUERY);
155 parse_str($query, $vars);
156 $query = http_build_query(array_merge($vars, $data));
157 $this->client->path = parse_url($this->client->path, PHP_URL_PATH) . '?' . $query;
160 public function testString()
162 $sendString = "here are 3 \"entities\": < > & " .
163 "and here's a dollar sign: \$pretendvarname and a backslash too: " . chr(92) .
164 " - isn't that great? \\\"hackery\\\" at it's best " .
165 " also don't want to miss out on \$item[0]. " .
166 "The real weird stuff follows: CRLF here" . chr(13) . chr(10) .
167 "a simple CR here" . chr(13) .
168 "a simple LF here" . chr(10) .
169 "and then LFCR" . chr(10) . chr(13) .
170 "last but not least weird names: G" . chr(252) . "nter, El" . chr(232) . "ne, and an xml comment closing tag: -->";
171 $m = new xmlrpcmsg('examples.stringecho', array(
172 new xmlrpcval($sendString, 'string'),
174 $v = $this->send($m);
176 // when sending/receiving non-US-ASCII encoded strings, XML says cr-lf can be normalized.
177 // so we relax our tests...
178 $l1 = strlen($sendString);
179 $l2 = strlen($v->scalarval());
181 $this->assertEquals($sendString, $v->scalarval());
183 $this->assertEquals(str_replace(array("\r\n", "\r"), array("\n", "\n"), $sendString), $v->scalarval());
188 public function testLatin1String()
191 "last but not least weird names: G" . chr(252) . "nter, El" . chr(232) . "ne";
192 $x = '<?xml version="1.0" encoding="ISO-8859-1"?><methodCall><methodName>examples.stringecho</methodName><params><param><value>'.
194 '</value></param></params></methodCall>';
195 $v = $this->send($x);
197 $this->assertEquals($sendString, $v->scalarval());
201 public function testExoticCharsetsRequests()
203 // note that we should disable this call also when mbstring is missing server-side
204 if (!function_exists('mb_convert_encoding')) {
205 $this->markTestSkipped('Miss mbstring extension to test exotic charsets');
208 $sendString = 'κόσμε'; // Greek word 'kosme'. NB: NOT a valid ISO8859 string!
209 $str = '<?xml version="1.0" encoding="_ENC_"?>
211 <methodName>examples.stringecho</methodName>
214 <value><string>'.$sendString.'</string></value>
219 PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'UTF-8';
220 // we have to set the encoding declaration either in the http header or xml prolog, as mb_detect_encoding
221 // (used on the server side) will fail recognizing these 2 charsets
222 $v = $this->send(mb_convert_encoding(str_replace('_ENC_', 'UCS-4', $str), 'UCS-4', 'UTF-8'));
223 $this->assertEquals($sendString, $v->scalarval());
224 $v = $this->send(mb_convert_encoding(str_replace('_ENC_', 'UTF-16', $str), 'UTF-16', 'UTF-8'));
225 $this->assertEquals($sendString, $v->scalarval());
226 PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'ISO-8859-1';
229 public function testExoticCharsetsRequests2()
231 // note that we should disable this call also when mbstring is missing server-side
232 if (!function_exists('mb_convert_encoding')) {
233 $this->markTestSkipped('Miss mbstring extension to test exotic charsets');
236 $sendString = '安室奈美恵'; // No idea what this means :-) NB: NOT a valid ISO8859 string!
237 $str = '<?xml version="1.0"?>
239 <methodName>examples.stringecho</methodName>
242 <value><string>'.$sendString.'</string></value>
247 PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'UTF-8';
248 // no encoding declaration either in the http header or xml prolog, let mb_detect_encoding
249 // (used on the server side) sort it out
250 $this->addQueryParams(array('DETECT_ENCODINGS' => array('EUC-JP', 'UTF-8')));
251 $v = $this->send(mb_convert_encoding($str, 'EUC-JP', 'UTF-8'));
252 $this->assertEquals($sendString, $v->scalarval());
253 PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'ISO-8859-1';
256 public function testExoticCharsetsRequests3()
258 // note that we should disable this call also when mbstring is missing server-side
259 if (!function_exists('mb_convert_encoding')) {
260 $this->markTestSkipped('Miss mbstring extension to test exotic charsets');
263 $sendString = utf8_decode('élève');
264 $str = '<?xml version="1.0"?>
266 <methodName>examples.stringecho</methodName>
269 <value><string>'.$sendString.'</string></value>
274 // no encoding declaration either in the http header or xml prolog, let mb_detect_encoding
275 // (used on the server side) sort it out
276 $this->addQueryParams(array('DETECT_ENCODINGS' => array('ISO-8859-1', 'UTF-8')));
277 $v = $this->send($str);
278 $this->assertEquals($sendString, $v->scalarval());
281 /*public function testLatin1Method()
283 $f = new xmlrpcmsg("tests.iso88591methodname." . chr(224) . chr(252) . chr(232), array(
284 new xmlrpcval('hello')
286 $v = $this->send($f);
288 $this->assertEquals('hello', $v->scalarval());
292 public function testUtf8Method()
294 PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'UTF-8';
295 $m = new xmlrpcmsg("tests.utf8methodname." . 'κόσμε', array(
296 new xmlrpcval('hello')
298 $v = $this->send($m);
300 $this->assertEquals('hello', $v->scalarval());
302 PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'ISO-8859-1';
305 public function testAddingDoubles()
307 // note that rounding errors mean we
308 // keep precision to sensible levels here ;-)
311 $m = new xmlrpcmsg('examples.addtwodouble', array(
312 new xmlrpcval($a, 'double'),
313 new xmlrpcval($b, 'double'),
315 $v = $this->send($m);
317 $this->assertEquals($a + $b, $v->scalarval());
321 public function testAdding()
323 $m = new xmlrpcmsg('examples.addtwo', array(
324 new xmlrpcval(12, 'int'),
325 new xmlrpcval(-23, 'int'),
327 $v = $this->send($m);
329 $this->assertEquals(12 - 23, $v->scalarval());
333 public function testInvalidNumber()
335 $m = new xmlrpcmsg('examples.addtwo', array(
336 new xmlrpcval('fred', 'int'),
337 new xmlrpcval("\"; exec('ls')", 'int'),
339 $v = $this->send($m);
340 /// @todo a fault condition should be generated here
341 /// by the server, which we pick up on
343 $this->assertEquals(0, $v->scalarval());
347 public function testBoolean()
349 $m = new xmlrpcmsg('examples.invertBooleans', array(
351 new xmlrpcval(true, 'boolean'),
352 new xmlrpcval(false, 'boolean'),
353 new xmlrpcval(1, 'boolean'),
354 new xmlrpcval(0, 'boolean')
359 $v = $this->send($m);
361 $sz = $v->arraysize();
363 for ($i = 0; $i < $sz; $i++) {
364 $b = $v->arraymem($i);
365 if ($b->scalarval()) {
371 $this->assertEquals($answer, $got);
375 public function testBase64()
377 $sendString = 'Mary had a little lamb,
378 Whose fleece was white as snow,
379 And everywhere that Mary went
380 the lamb was sure to go.
382 Mary had a little lamb
383 She tied it to a pylon
384 Ten thousand volts went down its back
385 And turned it into nylon';
386 $m = new xmlrpcmsg('examples.decode64', array(
387 new xmlrpcval($sendString, 'base64'),
389 $v = $this->send($m);
391 if (strlen($sendString) == strlen($v->scalarval())) {
392 $this->assertEquals($sendString, $v->scalarval());
394 $this->assertEquals(str_replace(array("\r\n", "\r"), array("\n", "\n"), $sendString), $v->scalarval());
399 public function testDateTime()
402 $t1 = new xmlrpcval($time, 'dateTime.iso8601');
403 $t2 = new xmlrpcval(iso8601_encode($time), 'dateTime.iso8601');
404 $this->assertEquals($t1->serialize(), $t2->serialize());
405 if (class_exists('DateTime')) {
406 $datetime = new DateTime();
407 // skip this test for php 5.2. It is a bit harder there to build a DateTime from unix timestamp with proper TZ info
408 if (is_callable(array($datetime, 'setTimestamp'))) {
409 $t3 = new xmlrpcval($datetime->setTimestamp($time), 'dateTime.iso8601');
410 $this->assertEquals($t1->serialize(), $t3->serialize());
415 public function testCountEntities()
417 $sendString = "h'fd>onc>>l>>rw&bpu>q>e<v&gxs<ytjzkami<";
418 $m = new xmlrpcmsg('validator1.countTheEntities', array(
419 new xmlrpcval($sendString, 'string'),
421 $v = $this->send($m);
425 $expect_array = array('ctLeftAngleBrackets', 'ctRightAngleBrackets', 'ctAmpersands', 'ctApostrophes', 'ctQuotes');
426 foreach($expect_array as $val) {
427 $b = $v->structmem($val);
428 $got .= $b->me['int'];
430 $this->assertEquals($expected, $got);
434 public function _multicall_msg($method, $params)
436 $struct['methodName'] = new xmlrpcval($method, 'string');
437 $struct['params'] = new xmlrpcval($params, 'array');
439 return new xmlrpcval($struct, 'struct');
442 public function testServerMulticall()
444 // We manually construct a system.multicall() call to ensure
445 // that the server supports it.
447 // NB: This test will NOT pass if server does not support system.multicall.
449 // Based on http://xmlrpc-c.sourceforge.net/hacks/test_multicall.py
450 $good1 = $this->_multicall_msg(
452 array(php_xmlrpc_encode('system.listMethods')));
453 $bad = $this->_multicall_msg(
455 array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
456 $recursive = $this->_multicall_msg(
458 array(new xmlrpcval(array(), 'array')));
459 $good2 = $this->_multicall_msg(
460 'system.methodSignature',
461 array(php_xmlrpc_encode('system.listMethods')));
462 $arg = new xmlrpcval(
463 array($good1, $bad, $recursive, $good2),
467 $m = new xmlrpcmsg('system.multicall', array($arg));
468 $v = $this->send($m);
470 //$this->assertTrue($r->faultCode() == 0, "fault from system.multicall");
471 $this->assertTrue($v->arraysize() == 4, "bad number of return values");
473 $r1 = $v->arraymem(0);
475 $r1->kindOf() == 'array' && $r1->arraysize() == 1,
476 "did not get array of size 1 from good1"
479 $r2 = $v->arraymem(1);
481 $r2->kindOf() == 'struct',
485 $r3 = $v->arraymem(2);
487 $r3->kindOf() == 'struct',
488 "recursive system.multicall did not fail"
491 $r4 = $v->arraymem(3);
493 $r4->kindOf() == 'array' && $r4->arraysize() == 1,
494 "did not get array of size 1 from good2"
499 public function testClientMulticall1()
501 // NB: This test will NOT pass if server does not support system.multicall.
503 $this->client->no_multicall = false;
505 $good1 = new xmlrpcmsg('system.methodHelp',
506 array(php_xmlrpc_encode('system.listMethods')));
507 $bad = new xmlrpcmsg('test.nosuch',
508 array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
509 $recursive = new xmlrpcmsg('system.multicall',
510 array(new xmlrpcval(array(), 'array')));
511 $good2 = new xmlrpcmsg('system.methodSignature',
512 array(php_xmlrpc_encode('system.listMethods'))
515 $r = $this->send(array($good1, $bad, $recursive, $good2));
517 $this->assertTrue(count($r) == 4, "wrong number of return values");
520 $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
521 if (!$r[0]->faultCode()) {
522 $val = $r[0]->value();
524 $val->kindOf() == 'scalar' && $val->scalartyp() == 'string',
525 "good1 did not return string"
528 $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
529 $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall");
530 $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
531 if (!$r[3]->faultCode()) {
532 $val = $r[3]->value();
533 $this->assertTrue($val->kindOf() == 'array', "good2 did not return array");
535 // This is the only assert in this test which should fail
536 // if the test server does not support system.multicall.
537 $this->assertTrue($this->client->no_multicall == false,
538 "server does not support system.multicall"
542 public function testClientMulticall2()
544 // NB: This test will NOT pass if server does not support system.multicall.
546 $this->client->no_multicall = true;
548 $good1 = new xmlrpcmsg('system.methodHelp',
549 array(php_xmlrpc_encode('system.listMethods')));
550 $bad = new xmlrpcmsg('test.nosuch',
551 array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
552 $recursive = new xmlrpcmsg('system.multicall',
553 array(new xmlrpcval(array(), 'array')));
554 $good2 = new xmlrpcmsg('system.methodSignature',
555 array(php_xmlrpc_encode('system.listMethods'))
558 $r = $this->send(array($good1, $bad, $recursive, $good2));
560 $this->assertTrue(count($r) == 4, "wrong number of return values");
563 $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
564 if (!$r[0]->faultCode()) {
565 $val = $r[0]->value();
567 $val->kindOf() == 'scalar' && $val->scalartyp() == 'string',
568 "good1 did not return string");
570 $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
571 $this->assertTrue($r[2]->faultCode() == 0, "fault from (non recursive) system.multicall");
572 $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
573 if (!$r[3]->faultCode()) {
574 $val = $r[3]->value();
575 $this->assertTrue($val->kindOf() == 'array', "good2 did not return array");
579 public function testClientMulticall3()
581 // NB: This test will NOT pass if server does not support system.multicall.
583 $this->client->return_type = 'phpvals';
584 $this->client->no_multicall = false;
586 $good1 = new xmlrpcmsg('system.methodHelp',
587 array(php_xmlrpc_encode('system.listMethods')));
588 $bad = new xmlrpcmsg('test.nosuch',
589 array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
590 $recursive = new xmlrpcmsg('system.multicall',
591 array(new xmlrpcval(array(), 'array')));
592 $good2 = new xmlrpcmsg('system.methodSignature',
593 array(php_xmlrpc_encode('system.listMethods'))
596 $r = $this->send(array($good1, $bad, $recursive, $good2));
598 $this->assertTrue(count($r) == 4, "wrong number of return values");
600 $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
601 if (!$r[0]->faultCode()) {
602 $val = $r[0]->value();
604 is_string($val), "good1 did not return string");
606 $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
607 $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall");
608 $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
609 if (!$r[3]->faultCode()) {
610 $val = $r[3]->value();
611 $this->assertTrue(is_array($val), "good2 did not return array");
613 //$this->client->return_type = 'xmlrpcvals';
616 public function testCatchWarnings()
618 $m = new xmlrpcmsg('tests.generatePHPWarning', array(
619 new xmlrpcval('whatever', 'string'),
621 $v = $this->send($m);
623 $this->assertEquals(true, $v->scalarval());
627 public function testCatchExceptions()
629 $m = new xmlrpcmsg('tests.raiseException', array(
630 new xmlrpcval('whatever', 'string'),
632 $v = $this->send($m, $GLOBALS['xmlrpcerr']['server_error']);
633 $this->addQueryParams(array('EXCEPTION_HANDLING' => 1));
634 $v = $this->send($m, 1); // the error code of the expected exception
635 $this->addQueryParams(array('EXCEPTION_HANDLING' => 2));
636 // depending on whether display_errors is ON or OFF on the server, we will get back a different error here,
637 // as php will generate an http status code of either 200 or 500...
638 $v = $this->send($m, array($GLOBALS['xmlrpcerr']['invalid_return'], $GLOBALS['xmlrpcerr']['http_error']));
641 public function testZeroParams()
643 $m = new xmlrpcmsg('system.listMethods');
644 $v = $this->send($m);
647 public function testNullParams()
649 $m = new xmlrpcmsg('tests.getStateName.12', array(
650 new xmlrpcval('whatever', 'null'),
651 new xmlrpcval(23, 'int'),
653 $v = $this->send($m);
655 $this->assertEquals('Michigan', $v->scalarval());
657 $m = new xmlrpcmsg('tests.getStateName.12', array(
658 new xmlrpcval(23, 'int'),
659 new xmlrpcval('whatever', 'null'),
661 $v = $this->send($m);
663 $this->assertEquals('Michigan', $v->scalarval());
665 $m = new xmlrpcmsg('tests.getStateName.12', array(
666 new xmlrpcval(23, 'int')
668 $v = $this->send($m, array($GLOBALS['xmlrpcerr']['incorrect_params']));
671 public function testCodeInjectionServerSide()
673 $m = new xmlrpcmsg('system.MethodHelp');
674 $m->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>";
675 $v = $this->send($m);
677 $this->assertEquals(0, $v->structsize());
681 public function testServerWrappedFunction()
683 $m = new xmlrpcmsg('tests.getStateName.2', array(
684 new xmlrpcval(23, 'int'),
686 $v = $this->send($m);
687 $this->assertEquals('Michigan', $v->scalarval());
689 // this generates an exception in the function which was wrapped, which is by default wrapped in a known error response
690 $m = new xmlrpcmsg('tests.getStateName.2', array(
691 new xmlrpcval(0, 'int'),
693 $v = $this->send($m, $GLOBALS['xmlrpcerr']['server_error']);
695 // check if the generated function dispatch map is fine, by checking if the server registered it
696 $m = new xmlrpcmsg('system.methodSignature', array(
697 new xmlrpcval('tests.getStateName.2'),
699 $v = $this->send($m);
700 $encoder = new \PhpXmlRpc\Encoder();
701 $this->assertEquals(array(array('string', 'int')), $encoder->decode($v));
704 public function testServerWrappedFunctionAsSource()
706 $m = new xmlrpcmsg('tests.getStateName.6', array(
707 new xmlrpcval(23, 'int'),
709 $v = $this->send($m);
710 $this->assertEquals('Michigan', $v->scalarval());
712 // this generates an exception in the function which was wrapped, which is by default wrapped in a known error response
713 $m = new xmlrpcmsg('tests.getStateName.6', array(
714 new xmlrpcval(0, 'int'),
716 $v = $this->send($m, $GLOBALS['xmlrpcerr']['server_error']);
719 public function testServerWrappedObjectMethods()
721 $m = new xmlrpcmsg('tests.getStateName.3', array(
722 new xmlrpcval(23, 'int'),
724 $v = $this->send($m);
725 $this->assertEquals('Michigan', $v->scalarval());
727 $m = new xmlrpcmsg('tests.getStateName.4', array(
728 new xmlrpcval(23, 'int'),
730 $v = $this->send($m);
731 $this->assertEquals('Michigan', $v->scalarval());
733 $m = new xmlrpcmsg('tests.getStateName.5', array(
734 new xmlrpcval(23, 'int'),
736 $v = $this->send($m);
737 $this->assertEquals('Michigan', $v->scalarval());
739 $m = new xmlrpcmsg('tests.getStateName.7', array(
740 new xmlrpcval(23, 'int'),
742 $v = $this->send($m);
743 $this->assertEquals('Michigan', $v->scalarval());
745 $m = new xmlrpcmsg('tests.getStateName.8', array(
746 new xmlrpcval(23, 'int'),
748 $v = $this->send($m);
749 $this->assertEquals('Michigan', $v->scalarval());
751 $m = new xmlrpcmsg('tests.getStateName.9', array(
752 new xmlrpcval(23, 'int'),
754 $v = $this->send($m);
755 $this->assertEquals('Michigan', $v->scalarval());
758 public function testServerWrappedObjectMethodsAsSource()
760 $m = new xmlrpcmsg('tests.getStateName.7', array(
761 new xmlrpcval(23, 'int'),
763 $v = $this->send($m);
764 $this->assertEquals('Michigan', $v->scalarval());
766 $m = new xmlrpcmsg('tests.getStateName.8', array(
767 new xmlrpcval(23, 'int'),
769 $v = $this->send($m);
770 $this->assertEquals('Michigan', $v->scalarval());
772 $m = new xmlrpcmsg('tests.getStateName.9', array(
773 new xmlrpcval(23, 'int'),
775 $v = $this->send($m);
776 $this->assertEquals('Michigan', $v->scalarval());
779 public function testServerClosure()
781 $m = new xmlrpcmsg('tests.getStateName.10', array(
782 new xmlrpcval(23, 'int'),
784 $v = $this->send($m);
785 $this->assertEquals('Michigan', $v->scalarval());
788 public function testServerWrappedClosure()
790 $m = new xmlrpcmsg('tests.getStateName.11', array(
791 new xmlrpcval(23, 'int'),
793 $v = $this->send($m);
794 $this->assertEquals('Michigan', $v->scalarval());
797 public function testServerWrappedClass()
799 $m = new xmlrpcmsg('tests.xmlrpcServerMethodsContainer.findState', array(
800 new xmlrpcval(23, 'int'),
802 $v = $this->send($m);
803 $this->assertEquals('Michigan', $v->scalarval());
806 public function testWrappedMethod()
808 // make a 'deep client copy' as the original one might have many properties set
809 $func = wrap_xmlrpc_method($this->client, 'examples.getStateName', array('simple_client_copy' => 0));
810 if ($func == false) {
811 $this->fail('Registration of examples.getStateName failed');
814 // work around bug in current (or old?) version of phpunit when reporting the error
815 /*if (is_object($v)) {
816 $v = var_export($v, true);
818 $this->assertEquals('Michigan', $v);
822 public function testWrappedMethodAsSource()
824 // make a 'deep client copy' as the original one might have many properties set
825 $func = wrap_xmlrpc_method($this->client, 'examples.getStateName', array('simple_client_copy' => 0, 'return_source' => true));
826 if ($func == false) {
827 $this->fail('Registration of examples.getStateName failed');
829 eval($func['source']);
830 $func = $func['function'];
832 // work around bug in current (or old?) version of phpunit when reporting the error
833 /*if (is_object($v)) {
834 $v = var_export($v, true);
836 $this->assertEquals('Michigan', $v);
840 public function testWrappedClass()
842 // make a 'deep client copy' as the original one might have many properties set
843 // also for speed only wrap one method of the whole server
844 $class = wrap_xmlrpc_server($this->client, array('simple_client_copy' => 0, 'method_filter' => '/examples\.getStateName/' ));
846 $this->fail('Registration of remote server failed');
849 $v = $obj->examples_getStateName(23);
850 // work around bug in current (or old?) version of phpunit when reporting the error
851 /*if (is_object($v)) {
852 $v = var_export($v, true);
854 $this->assertEquals('Michigan', $v);
858 public function testTransferOfObjectViaWrapping()
860 // make a 'deep client copy' as the original one might have many properties set
861 $func = wrap_xmlrpc_method($this->client, 'tests.returnPhpObject', array('simple_client_copy' => true,
862 'decode_php_objs' => true));
863 if ($func == false) {
864 $this->fail('Registration of tests.returnPhpObject failed');
867 $obj = new stdClass();
868 $obj->hello = 'world';
869 $this->assertEquals($obj, $v);
873 public function testGetCookies()
875 // let server set to us some cookies we tell it
878 'c2' => array('value' => 'c2'),
879 'c3' => array('value' => 'c3', 'expires' => time() + 60 * 60 * 24 * 30),
880 'c4' => array('value' => 'c4', 'expires' => time() + 60 * 60 * 24 * 30, 'path' => '/'),
881 'c5' => array('value' => 'c5', 'expires' => time() + 60 * 60 * 24 * 30, 'path' => '/', 'domain' => 'localhost'),
883 $cookiesval = php_xmlrpc_encode($cookies);
884 $m = new xmlrpcmsg('examples.setcookies', array($cookiesval));
885 $r = $this->send($m, 0, true);
888 $this->assertEquals(1, $v->scalarval());
889 // now check if we decoded the cookies as we had set them
890 $rcookies = $r->cookies();
891 // remove extra cookies which might have been set by proxies
892 foreach ($rcookies as $c => $v) {
893 if (!in_array($c, array('c2', 'c3', 'c4', 'c5'))) {
894 unset($rcookies[$c]);
896 // Seems like we get this when using php-fpm and php 5.5+ ...
897 if (isset($rcookies[$c]['Max-Age'])) {
898 unset($rcookies[$c]['Max-Age']);
901 foreach ($cookies as $c => $v) {
902 // format for date string in cookies: 'Mon, 31 Oct 2005 13:50:56 GMT'
903 // but PHP versions differ on that, some use 'Mon, 31-Oct-2005 13:50:56 GMT'...
904 if (isset($v['expires'])) {
905 if (isset($rcookies[$c]['expires']) && strpos($rcookies[$c]['expires'], '-')) {
906 $cookies[$c]['expires'] = gmdate('D, d\-M\-Y H:i:s \G\M\T', $cookies[$c]['expires']);
908 $cookies[$c]['expires'] = gmdate('D, d M Y H:i:s \G\M\T', $cookies[$c]['expires']);
913 $this->assertEquals($cookies, $rcookies);
917 public function testSetCookies()
919 // let server set to us some cookies we tell it
924 'c3' => '!@#$%^&*()_+|}{":?><,./\';[]\\=-',
926 $m = new xmlrpcmsg('examples.getcookies', array());
927 foreach ($cookies as $cookie => $val) {
928 $this->client->setCookie($cookie, $val);
929 $cookies[$cookie] = (string)$cookies[$cookie];
931 $r = $this->client->send($m, $this->timeout, $this->method);
932 $this->assertEquals(0, $r->faultCode(), 'Error ' . $r->faultCode() . ' connecting to server: ' . $r->faultString());
933 if (!$r->faultCode()) {
935 $v = php_xmlrpc_decode($v);
937 // take care for the extra cookie used for coverage collection
938 if (isset($v['PHPUNIT_SELENIUM_TEST_ID'])) {
939 unset($v['PHPUNIT_SELENIUM_TEST_ID']);
942 // on IIS and Apache getallheaders returns something slightly different...
943 $this->assertEquals($cookies, $v);
947 public function testServerComments()
949 $m = new xmlrpcmsg('tests.xmlrpcServerMethodsContainer.debugMessageGenerator', array(
950 new xmlrpcval('hello world', 'string'),
952 $r = $this->send($m, 0, true);
953 $this->assertContains('hello world', $r->raw_data);
956 public function testSendTwiceSameMsg()
958 $m = new xmlrpcmsg('examples.stringecho', array(
959 new xmlrpcval('hello world', 'string'),
961 $v1 = $this->send($m);
962 $v2 = $this->send($m);
964 $this->assertEquals($v1, $v2);