From: gggeek Date: Fri, 10 Jan 2014 18:00:21 +0000 (+0100) Subject: - update testsuite X-Git-Tag: 3.0.0~13 X-Git-Url: http://git.onelab.eu/?p=plcapi.git;a=commitdiff_plain;h=2c732850d51db98da039e49e018b342d2a4e0242 - update testsuite --- diff --git a/ChangeLog b/ChangeLog index b0e65e9..48a7305 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * xmlrpc.inc: when using curl and keepalive, reset curl handle if we did not get back an http 200 response (eg a 302) + * testsuite.php, parse_args.php: update testsuite + 2010-05-23 - G. Giunta (giunta.gaetano@gmail.com) * xmlrpc.inc: omit port on http 'Host' header if it is 80; @@ -10,6 +12,7 @@ 2010-04-12 - G. Giunta (giunta.gaetano@gmail.com) * testsuite.php, parse_args.php: testsuite allows interrogating https servers ignoring their certs + * xmlrpc.inc: method setAcceptedCompression was failing to disable reception of compressed responses if the client supported them (triggering a bug with https and php < 5.3 on windows due); remove a php warning that could be diff --git a/test/parse_args.php b/test/parse_args.php index 6430b4c..81f5bd0 100644 --- a/test/parse_args.php +++ b/test/parse_args.php @@ -79,6 +79,10 @@ { $HTTPSURI = '/server.php'; } + if(!isset($HTTPSIGNOREPEER)) + { + $HTTPSIGNOREPEER = false; + } if(!isset($PROXY)) { $PROXYSERVER = null; diff --git a/test/testsuite.php b/test/testsuite.php index 90c5844..dbbfa0b 100644 --- a/test/testsuite.php +++ b/test/testsuite.php @@ -1,205 +1,203 @@ 1) - { - $this->client=new xmlrpc_client($URI, $server[0], $server[1]); - } - else - { - $this->client=new xmlrpc_client($URI, $LOCALSERVER); - } - if($DEBUG) - { - $this->client->setDebug($DEBUG); - } - $this->client->request_compression = $this->request_compression; - $this->client->accepted_compression = $this->accepted_compression; - } - - function send($msg, $errrorcode=0, $return_response=false) - { - $r = $this->client->send($msg, $this->timeout, $this->method); - // for multicall, return directly array of responses - if(is_array($r)) - { - return $r; - } - $this->assertEquals($r->faultCode(), $errrorcode, 'Error '.$r->faultCode().' connecting to server: '.$r->faultString()); - if(!$r->faultCode()) - { - if($return_response) - return $r; - else - return $r->value(); - } - else - { - return null; - } - } - - function testString() - { - $sendstring="here are 3 \"entities\": < > &" . - "and here's a dollar sign: \$pretendvarname and a backslash too: " . chr(92) . - " - isn't that great? \\\"hackery\\\" at it's best " . - " also don't want to miss out on \$item[0]. ". - "The real weird stuff follows: CRLF here".chr(13).chr(10). - "a simple CR here".chr(13). - "a simple LF here".chr(10). - "and then LFCR".chr(10).chr(13). - "last but not least weird names: G�nter, El�ne, and an xml comment closing tag: -->"; - $f=new xmlrpcmsg('examples.stringecho', array( - new xmlrpcval($sendstring, 'string') - )); - $v=$this->send($f); - if($v) - { - // when sending/receiving non-US-ASCII encoded strings, XML says cr-lf can be normalized. - // so we relax our tests... - $l1 = strlen($sendstring); - $l2 = strlen($v->scalarval()); - if ($l1 == $l2) - $this->assertEquals($sendstring, $v->scalarval()); - else - $this->assertEquals(str_replace(array("\r\n", "\r"), array("\n", "\n"), $sendstring), $v->scalarval()); - } - } - - function testAddingDoubles() - { - // note that rounding errors mean i - // keep precision to sensible levels here ;-) - $a=12.13; $b=-23.98; - $f=new xmlrpcmsg('examples.addtwodouble',array( - new xmlrpcval($a, 'double'), - new xmlrpcval($b, 'double') - )); - $v=$this->send($f); - if($v) - { - $this->assertEquals($a+$b,$v->scalarval()); - } - } - - function testAdding() - { - $f=new xmlrpcmsg('examples.addtwo',array( - new xmlrpcval(12, 'int'), - new xmlrpcval(-23, 'int') - )); - $v=$this->send($f); - if($v) - { - $this->assertEquals(12-23, $v->scalarval()); - } - } - - function testInvalidNumber() - { - $f=new xmlrpcmsg('examples.addtwo',array( - new xmlrpcval('fred', 'int'), - new xmlrpcval("\"; exec('ls')", 'int') - )); - $v=$this->send($f); - /// @todo a fault condition should be generated here - /// by the server, which we pick up on - if($v) - { - $this->assertEquals(0, $v->scalarval()); - } - } - - function testBoolean() - { - $f=new xmlrpcmsg('examples.invertBooleans', array( - new xmlrpcval(array( - new xmlrpcval(true, 'boolean'), - new xmlrpcval(false, 'boolean'), - new xmlrpcval(1, 'boolean'), - new xmlrpcval(0, 'boolean'), - //new xmlrpcval('true', 'boolean'), - //new xmlrpcval('false', 'boolean') - ), - 'array' - ))); - $answer='0101'; - $v=$this->send($f); - if($v) - { - $sz=$v->arraysize(); - $got=''; - for($i=0; $i<$sz; $i++) - { - $b=$v->arraymem($i); - if($b->scalarval()) - { - $got.='1'; - } - else - { - $got.='0'; - } - } - $this->assertEquals($answer, $got); - } - } - - function testBase64() - { - $sendstring='Mary had a little lamb, +include(getcwd().'/parse_args.php'); + +require_once('xmlrpc.inc'); +require_once('xmlrpcs.inc'); +require_once('xmlrpc_wrappers.inc'); + +require_once 'phpunit.php'; +//require_once 'PHPUnit/TestDecorator.php'; + +// let testuite run for the needed time +if ((int)ini_get('max_execution_time') < 180) + ini_set('max_execution_time', 180); + +$suite = new PHPUnit_TestSuite(); + +// array with list of failed tests +$failed_tests = array(); + +class LocalhostTests extends PHPUnit_TestCase +{ + var $client = null; + var $method = 'http'; + var $timeout = 10; + var $request_compression = null; + var $accepted_compression = ''; + + function fail($message = '') + { + PHPUnit_TestCase::fail($message); + // save in global var that this particular test has failed + // (but only if not called from subclass objects / multitests) + if (function_exists('debug_backtrace') && strtolower(get_class($this)) == 'localhosttests') + { + global $failed_tests; + $trace = debug_backtrace(); + for ($i = 0; $i < count($trace); $i++) + { + if (strpos($trace[$i]['function'], 'test') === 0) + { + $failed_tests[$trace[$i]['function']] = true; + break; + } + } + } + } + + function setUp() + { + global $DEBUG, $LOCALSERVER, $URI; + $server = explode(':', $LOCALSERVER); + if(count($server) > 1) + { + $this->client=new xmlrpc_client($URI, $server[0], $server[1]); + } + else + { + $this->client=new xmlrpc_client($URI, $LOCALSERVER); + } + if($DEBUG) + { + $this->client->setDebug($DEBUG); + } + $this->client->request_compression = $this->request_compression; + $this->client->accepted_compression = $this->accepted_compression; + } + + function send($msg, $errrorcode=0, $return_response=false) + { + $r = $this->client->send($msg, $this->timeout, $this->method); + // for multicall, return directly array of responses + if(is_array($r)) + { + return $r; + } + $this->assertEquals($r->faultCode(), $errrorcode, 'Error '.$r->faultCode().' connecting to server: '.$r->faultString()); + if(!$r->faultCode()) + { + if($return_response) + return $r; + else + return $r->value(); + } + else + { + return null; + } + } + + function testString() + { + $sendstring="here are 3 \"entities\": < > & " . + "and here's a dollar sign: \$pretendvarname and a backslash too: " . chr(92) . + " - isn't that great? \\\"hackery\\\" at it's best " . + " also don't want to miss out on \$item[0]. ". + "The real weird stuff follows: CRLF here".chr(13).chr(10). + "a simple CR here".chr(13). + "a simple LF here".chr(10). + "and then LFCR".chr(10).chr(13). + "last but not least weird names: G".chr(252)."nter, El".chr(232)."ne, and an xml comment closing tag: -->"; + $f=new xmlrpcmsg('examples.stringecho', array( + new xmlrpcval($sendstring, 'string') + )); + $v=$this->send($f); + if($v) + { + // when sending/receiving non-US-ASCII encoded strings, XML says cr-lf can be normalized. + // so we relax our tests... + $l1 = strlen($sendstring); + $l2 = strlen($v->scalarval()); + if ($l1 == $l2) + $this->assertEquals($sendstring, $v->scalarval()); + else + $this->assertEquals(str_replace(array("\r\n", "\r"), array("\n", "\n"), $sendstring), $v->scalarval()); + } + } + + function testAddingDoubles() + { + // note that rounding errors mean we + // keep precision to sensible levels here ;-) + $a=12.13; $b=-23.98; + $f=new xmlrpcmsg('examples.addtwodouble',array( + new xmlrpcval($a, 'double'), + new xmlrpcval($b, 'double') + )); + $v=$this->send($f); + if($v) + { + $this->assertEquals($a+$b,$v->scalarval()); + } + } + + function testAdding() + { + $f=new xmlrpcmsg('examples.addtwo',array( + new xmlrpcval(12, 'int'), + new xmlrpcval(-23, 'int') + )); + $v=$this->send($f); + if($v) + { + $this->assertEquals(12-23, $v->scalarval()); + } + } + + function testInvalidNumber() + { + $f=new xmlrpcmsg('examples.addtwo',array( + new xmlrpcval('fred', 'int'), + new xmlrpcval("\"; exec('ls')", 'int') + )); + $v=$this->send($f); + /// @todo a fault condition should be generated here + /// by the server, which we pick up on + if($v) + { + $this->assertEquals(0, $v->scalarval()); + } + } + + function testBoolean() + { + $f=new xmlrpcmsg('examples.invertBooleans', array( + new xmlrpcval(array( + new xmlrpcval(true, 'boolean'), + new xmlrpcval(false, 'boolean'), + new xmlrpcval(1, 'boolean'), + new xmlrpcval(0, 'boolean'), + //new xmlrpcval('true', 'boolean'), + //new xmlrpcval('false', 'boolean') + ), + 'array' + ))); + $answer='0101'; + $v=$this->send($f); + if($v) + { + $sz=$v->arraysize(); + $got=''; + for($i=0; $i<$sz; $i++) + { + $b=$v->arraymem($i); + if($b->scalarval()) + { + $got.='1'; + } + else + { + $got.='0'; + } + } + $this->assertEquals($answer, $got); + } + } + + function testBase64() + { + $sendstring='Mary had a little lamb, Whose fleece was white as snow, And everywhere that Mary went the lamb was sure to go. @@ -208,645 +206,647 @@ Mary had a little lamb She tied it to a pylon Ten thousand volts went down its back And turned it into nylon'; - $f=new xmlrpcmsg('examples.decode64',array( - new xmlrpcval($sendstring, 'base64') - )); - $v=$this->send($f); - if($v) - { - if (strlen($sendstring) == strlen($v->scalarval())) - $this->assertEquals($sendstring, $v->scalarval()); - else - $this->assertEquals(str_replace(array("\r\n", "\r"), array("\n", "\n"), $sendstring), $v->scalarval()); - } - } - - function testDateTime() + $f=new xmlrpcmsg('examples.decode64',array( + new xmlrpcval($sendstring, 'base64') + )); + $v=$this->send($f); + if($v) { - $time = time(); - $t1 = new xmlrpcval($time, 'dateTime.iso8601'); - $t2 = new xmlrpcval(iso8601_encode($time), 'dateTime.iso8601'); - $this->assertEquals($t1->serialize(), $t2->serialize()); - if (class_exists('DateTime')) + if (strlen($sendstring) == strlen($v->scalarval())) + $this->assertEquals($sendstring, $v->scalarval()); + else + $this->assertEquals(str_replace(array("\r\n", "\r"), array("\n", "\n"), $sendstring), $v->scalarval()); + } + } + + function testDateTime() + { + $time = time(); + $t1 = new xmlrpcval($time, 'dateTime.iso8601'); + $t2 = new xmlrpcval(iso8601_encode($time), 'dateTime.iso8601'); + $this->assertEquals($t1->serialize(), $t2->serialize()); + if (class_exists('DateTime')) + { + $datetime = new DateTime(); + $t3 = new xmlrpcval($datetime->setTimestamp($time), 'dateTime.iso8601'); + $this->assertEquals($t1->serialize(), $t3->serialize()); + } + } + + function testCountEntities() + { + $sendstring = "h'fd>onc>>l>>rw&bpu>q>esend($f); + if($v) + { + $got = ''; + $expected = '37210'; + $expect_array = array('ctLeftAngleBrackets','ctRightAngleBrackets','ctAmpersands','ctApostrophes','ctQuotes'); + while(list(,$val) = each($expect_array)) { - $datetime = new DateTime(); - $t3 = new xmlrpcval($datetime->setTimestamp($time), 'dateTime.iso8601'); - $this->assertEquals($t1->serialize(), $t3->serialize()); + $b = $v->structmem($val); + $got .= $b->me['int']; } + $this->assertEquals($expected, $got); + } + } + + function _multicall_msg($method, $params) + { + $struct['methodName'] = new xmlrpcval($method, 'string'); + $struct['params'] = new xmlrpcval($params, 'array'); + return new xmlrpcval($struct, 'struct'); + } + + function testServerMulticall() + { + // We manually construct a system.multicall() call to ensure + // that the server supports it. + + // NB: This test will NOT pass if server does not support system.multicall. + + // Based on http://xmlrpc-c.sourceforge.net/hacks/test_multicall.py + $good1 = $this->_multicall_msg( + 'system.methodHelp', + array(php_xmlrpc_encode('system.listMethods'))); + $bad = $this->_multicall_msg( + 'test.nosuch', + array(php_xmlrpc_encode(1), php_xmlrpc_encode(2))); + $recursive = $this->_multicall_msg( + 'system.multicall', + array(new xmlrpcval(array(), 'array'))); + $good2 = $this->_multicall_msg( + 'system.methodSignature', + array(php_xmlrpc_encode('system.listMethods'))); + $arg = new xmlrpcval( + array($good1, $bad, $recursive, $good2), + 'array' + ); + + $f = new xmlrpcmsg('system.multicall', array($arg)); + $v = $this->send($f); + if($v) + { + //$this->assertTrue($r->faultCode() == 0, "fault from system.multicall"); + $this->assertTrue($v->arraysize() == 4, "bad number of return values"); + + $r1 = $v->arraymem(0); + $this->assertTrue( + $r1->kindOf() == 'array' && $r1->arraysize() == 1, + "did not get array of size 1 from good1" + ); + + $r2 = $v->arraymem(1); + $this->assertTrue( + $r2->kindOf() == 'struct', + "no fault from bad" + ); + + $r3 = $v->arraymem(2); + $this->assertTrue( + $r3->kindOf() == 'struct', + "recursive system.multicall did not fail" + ); + + $r4 = $v->arraymem(3); + $this->assertTrue( + $r4->kindOf() == 'array' && $r4->arraysize() == 1, + "did not get array of size 1 from good2" + ); + } + } + + function testClientMulticall1() + { + // NB: This test will NOT pass if server does not support system.multicall. + + $this->client->no_multicall = false; + + $good1 = new xmlrpcmsg('system.methodHelp', + array(php_xmlrpc_encode('system.listMethods'))); + $bad = new xmlrpcmsg('test.nosuch', + array(php_xmlrpc_encode(1), php_xmlrpc_encode(2))); + $recursive = new xmlrpcmsg('system.multicall', + array(new xmlrpcval(array(), 'array'))); + $good2 = new xmlrpcmsg('system.methodSignature', + array(php_xmlrpc_encode('system.listMethods')) + ); + + $r = $this->send(array($good1, $bad, $recursive, $good2)); + if($r) + { + $this->assertTrue(count($r) == 4, "wrong number of return values"); + } + + $this->assertTrue($r[0]->faultCode() == 0, "fault from good1"); + if(!$r[0]->faultCode()) + { + $val = $r[0]->value(); + $this->assertTrue( + $val->kindOf() == 'scalar' && $val->scalartyp() == 'string', + "good1 did not return string" + ); + } + $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad"); + $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall"); + $this->assertTrue($r[3]->faultCode() == 0, "fault from good2"); + if(!$r[3]->faultCode()) + { + $val = $r[3]->value(); + $this->assertTrue($val->kindOf() == 'array', "good2 did not return array"); + } + // This is the only assert in this test which should fail + // if the test server does not support system.multicall. + $this->assertTrue($this->client->no_multicall == false, + "server does not support system.multicall" + ); + } + + function testClientMulticall2() + { + // NB: This test will NOT pass if server does not support system.multicall. + + $this->client->no_multicall = true; + + $good1 = new xmlrpcmsg('system.methodHelp', + array(php_xmlrpc_encode('system.listMethods'))); + $bad = new xmlrpcmsg('test.nosuch', + array(php_xmlrpc_encode(1), php_xmlrpc_encode(2))); + $recursive = new xmlrpcmsg('system.multicall', + array(new xmlrpcval(array(), 'array'))); + $good2 = new xmlrpcmsg('system.methodSignature', + array(php_xmlrpc_encode('system.listMethods')) + ); + + $r = $this->send(array($good1, $bad, $recursive, $good2)); + if($r) + { + $this->assertTrue(count($r) == 4, "wrong number of return values"); } - function testCountEntities() - { - $sendstring = "h'fd>onc>>l>>rw&bpu>q>esend($f); - if($v) - { - $got = ''; - $expected = '37210'; - $expect_array = array('ctLeftAngleBrackets','ctRightAngleBrackets','ctAmpersands','ctApostrophes','ctQuotes'); - while(list(,$val) = each($expect_array)) - { - $b = $v->structmem($val); - $got .= $b->me['int']; - } - $this->assertEquals($expected, $got); - } - } - - function _multicall_msg($method, $params) - { - $struct['methodName'] = new xmlrpcval($method, 'string'); - $struct['params'] = new xmlrpcval($params, 'array'); - return new xmlrpcval($struct, 'struct'); - } - - function testServerMulticall() - { - // We manually construct a system.multicall() call to ensure - // that the server supports it. - - // NB: This test will NOT pass if server does not support system.multicall. - - // Based on http://xmlrpc-c.sourceforge.net/hacks/test_multicall.py - $good1 = $this->_multicall_msg( - 'system.methodHelp', - array(php_xmlrpc_encode('system.listMethods'))); - $bad = $this->_multicall_msg( - 'test.nosuch', - array(php_xmlrpc_encode(1), php_xmlrpc_encode(2))); - $recursive = $this->_multicall_msg( - 'system.multicall', - array(new xmlrpcval(array(), 'array'))); - $good2 = $this->_multicall_msg( - 'system.methodSignature', - array(php_xmlrpc_encode('system.listMethods'))); - $arg = new xmlrpcval( - array($good1, $bad, $recursive, $good2), - 'array' - ); - - $f = new xmlrpcmsg('system.multicall', array($arg)); - $v = $this->send($f); - if($v) - { - //$this->assertTrue($r->faultCode() == 0, "fault from system.multicall"); - $this->assertTrue($v->arraysize() == 4, "bad number of return values"); - - $r1 = $v->arraymem(0); - $this->assertTrue( - $r1->kindOf() == 'array' && $r1->arraysize() == 1, - "did not get array of size 1 from good1" - ); - - $r2 = $v->arraymem(1); - $this->assertTrue( - $r2->kindOf() == 'struct', - "no fault from bad" - ); - - $r3 = $v->arraymem(2); - $this->assertTrue( - $r3->kindOf() == 'struct', - "recursive system.multicall did not fail" - ); - - $r4 = $v->arraymem(3); - $this->assertTrue( - $r4->kindOf() == 'array' && $r4->arraysize() == 1, - "did not get array of size 1 from good2" - ); - } - } - - function testClientMulticall1() - { - // NB: This test will NOT pass if server does not support system.multicall. - - $this->client->no_multicall = false; - - $good1 = new xmlrpcmsg('system.methodHelp', - array(php_xmlrpc_encode('system.listMethods'))); - $bad = new xmlrpcmsg('test.nosuch', - array(php_xmlrpc_encode(1), php_xmlrpc_encode(2))); - $recursive = new xmlrpcmsg('system.multicall', - array(new xmlrpcval(array(), 'array'))); - $good2 = new xmlrpcmsg('system.methodSignature', - array(php_xmlrpc_encode('system.listMethods')) - ); - - $r = $this->send(array($good1, $bad, $recursive, $good2)); - if($r) - { - $this->assertTrue(count($r) == 4, "wrong number of return values"); - } - - $this->assertTrue($r[0]->faultCode() == 0, "fault from good1"); - if(!$r[0]->faultCode()) - { - $val = $r[0]->value(); - $this->assertTrue( - $val->kindOf() == 'scalar' && $val->scalartyp() == 'string', - "good1 did not return string" - ); - } - $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad"); - $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall"); - $this->assertTrue($r[3]->faultCode() == 0, "fault from good2"); - if(!$r[3]->faultCode()) - { - $val = $r[3]->value(); - $this->assertTrue($val->kindOf() == 'array', "good2 did not return array"); - } - // This is the only assert in this test which should fail - // if the test server does not support system.multicall. - $this->assertTrue($this->client->no_multicall == false, - "server does not support system.multicall" - ); - } - - function testClientMulticall2() - { - // NB: This test will NOT pass if server does not support system.multicall. - - $this->client->no_multicall = true; - - $good1 = new xmlrpcmsg('system.methodHelp', - array(php_xmlrpc_encode('system.listMethods'))); - $bad = new xmlrpcmsg('test.nosuch', - array(php_xmlrpc_encode(1), php_xmlrpc_encode(2))); - $recursive = new xmlrpcmsg('system.multicall', - array(new xmlrpcval(array(), 'array'))); - $good2 = new xmlrpcmsg('system.methodSignature', - array(php_xmlrpc_encode('system.listMethods')) - ); - - $r = $this->send(array($good1, $bad, $recursive, $good2)); - if($r) - { - $this->assertTrue(count($r) == 4, "wrong number of return values"); - } - - $this->assertTrue($r[0]->faultCode() == 0, "fault from good1"); - if(!$r[0]->faultCode()) - { - $val = $r[0]->value(); - $this->assertTrue( - $val->kindOf() == 'scalar' && $val->scalartyp() == 'string', - "good1 did not return string"); - } - $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad"); - $this->assertTrue($r[2]->faultCode() == 0, "fault from (non recursive) system.multicall"); - $this->assertTrue($r[3]->faultCode() == 0, "fault from good2"); - if(!$r[3]->faultCode()) - { - $val = $r[3]->value(); - $this->assertTrue($val->kindOf() == 'array', "good2 did not return array"); - } - } - - function testClientMulticall3() - { - // NB: This test will NOT pass if server does not support system.multicall. - - $this->client->return_type = 'phpvals'; - $this->client->no_multicall = false; - - $good1 = new xmlrpcmsg('system.methodHelp', - array(php_xmlrpc_encode('system.listMethods'))); - $bad = new xmlrpcmsg('test.nosuch', - array(php_xmlrpc_encode(1), php_xmlrpc_encode(2))); - $recursive = new xmlrpcmsg('system.multicall', - array(new xmlrpcval(array(), 'array'))); - $good2 = new xmlrpcmsg('system.methodSignature', - array(php_xmlrpc_encode('system.listMethods')) - ); - - $r = $this->send(array($good1, $bad, $recursive, $good2)); - if($r) - { - $this->assertTrue(count($r) == 4, "wrong number of return values"); - } - $this->assertTrue($r[0]->faultCode() == 0, "fault from good1"); - if(!$r[0]->faultCode()) - { - $val = $r[0]->value(); - $this->assertTrue( - is_string($val) , "good1 did not return string"); - } - $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad"); - $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall"); - $this->assertTrue($r[3]->faultCode() == 0, "fault from good2"); - if(!$r[3]->faultCode()) - { - $val = $r[3]->value(); - $this->assertTrue(is_array($val), "good2 did not return array"); - } - $this->client->return_type = 'xmlrpcvals'; - } - - function testCatchWarnings() - { - $f = new xmlrpcmsg('examples.generatePHPWarning', array( - new xmlrpcval('whatever', 'string') - )); - $v = $this->send($f); - if($v) - { - $this->assertEquals($v->scalarval(), true); - } - } - - function testCatchExceptions() - { - global $URI; - $f = new xmlrpcmsg('examples.raiseException', array( - new xmlrpcval('whatever', 'string') - )); - $v = $this->send($f, $GLOBALS['xmlrpcerr']['server_error']); - $this->client->path = $URI.'?EXCEPTION_HANDLING=1'; - $v = $this->send($f, 1); - $this->client->path = $URI.'?EXCEPTION_HANDLING=2'; - $v = $this->send($f, $GLOBALS['xmlrpcerr']['invalid_return']); - } - - function testZeroParams() - { - $f = new xmlrpcmsg('system.listMethods'); - $v = $this->send($f); - } - - function testCodeInjectionServerSide() - { - $f = new xmlrpcmsg('system.MethodHelp'); - $f->payload = "validator1.echoStructTest','')); echo('gotcha!'); die(); //"; - $v = $this->send($f); - //$v = $r->faultCode(); - if ($v) - { - $this->assertEquals(0, $v->structsize()); - } - } - - function testAutoRegisteredFunction() - { - $f=new xmlrpcmsg('examples.php.getStateName',array( - new xmlrpcval(23, 'int') - )); - $v=$this->send($f); - if($v) - { - $this->assertEquals('Michigan', $v->scalarval()); - } - else - { - $this->fail('Note: server can only auto register functions if running with PHP 5.0.3 and up'); - } - } - - function testAutoRegisteredClass() - { - $f=new xmlrpcmsg('examples.php2.getStateName',array( - new xmlrpcval(23, 'int') - )); - $v=$this->send($f); - if($v) - { - $this->assertEquals('Michigan', $v->scalarval()); - $f=new xmlrpcmsg('examples.php3.getStateName',array( - new xmlrpcval(23, 'int') - )); - $v=$this->send($f); - if($v) - { - $this->assertEquals('Michigan', $v->scalarval()); - } - } - else - { - $this->fail('Note: server can only auto register class methods if running with PHP 5.0.3 and up'); - } - } - - function testAutoRegisteredMethod() - { - $func=wrap_xmlrpc_method($this->client, 'examples.getStateName'); - if($func == '') - { - $this->fail('Registration of examples.getStateName failed'); - } - else - { - $v=$func(23); - $this->assertEquals('Michigan', $v); - } - } - - function testGetCookies() - { - // let server set to us some cookies we tell it - $cookies = array( - //'c1' => array(), - 'c2' => array('value' => 'c2'), - 'c3' => array('value' => 'c3', 'expires' => time()+60*60*24*30), - 'c4' => array('value' => 'c4', 'expires' => time()+60*60*24*30, 'path' => '/'), - 'c5' => array('value' => 'c5', 'expires' => time()+60*60*24*30, 'path' => '/', 'domain' => 'localhost'), - ); - $cookiesval = php_xmlrpc_encode($cookies); - $f=new xmlrpcmsg('examples.setcookies',array($cookiesval)); - $r=$this->send($f, 0, true); - if($r) - { - $v = $r->value(); - $this->assertEquals(1, $v->scalarval()); - // now check if we decoded the cookies as we had set them - $rcookies = $r->cookies(); - foreach($cookies as $c => $v) - // format for date string in cookies: 'Mon, 31 Oct 2005 13:50:56 GMT' - // but PHP versions differ on that, some use 'Mon, 31-Oct-2005 13:50:56 GMT'... - if(isset($v['expires'])) - { - if (isset($rcookies[$c]['expires']) && strpos($rcookies[$c]['expires'], '-')) - { - $cookies[$c]['expires'] = gmdate('D, d\-M\-Y H:i:s \G\M\T' ,$cookies[$c]['expires']); - } - else - { - $cookies[$c]['expires'] = gmdate('D, d M Y H:i:s \G\M\T' ,$cookies[$c]['expires']); - } - } - $this->assertEquals($cookies, $rcookies); - } - } - - function testSetCookies() - { - // let server set to us some cookies we tell it - $cookies = array( - 'c0' => null, - 'c1' => 1, - 'c2' => '2 3', - 'c3' => '!@#$%^&*()_+|}{":?><,./\';[]\\=-' - ); - $f=new xmlrpcmsg('examples.getcookies',array()); - foreach ($cookies as $cookie => $val) - { - $this->client->setCookie($cookie, $val); - $cookies[$cookie] = (string) $cookies[$cookie]; - } - $r = $this->client->send($f, $this->timeout, $this->method); - $this->assertEquals($r->faultCode(), 0, 'Error '.$r->faultCode().' connecting to server: '.$r->faultString()); - if(!$r->faultCode()) - { - $v = $r->value(); - $v = php_xmlrpc_decode($v); - // on IIS and Apache getallheaders returns something slightly different... - $this->assertEquals($v, $cookies); - } - } - - function testSendTwiceSameMsg() - { - $f=new xmlrpcmsg('examples.stringecho', array( - new xmlrpcval('hello world', 'string') - )); - $v1 = $this->send($f); - $v2 = $this->send($f); - //$v = $r->faultCode(); - if ($v1 && $v2) - { - $this->assertEquals($v2, $v1); - } - } - } - - class LocalHostMultiTests extends LocalhostTests - { - function _runtests() - { - global $failed_tests; - foreach(get_class_methods('LocalhostTests') as $meth) - { - if(strpos($meth, 'test') === 0 && $meth != 'testHttps' && $meth != 'testCatchExceptions') - { - if (!isset($failed_tests[$meth])) - $this->$meth(); - } - if ($this->_failed) - { - break; - } - } - } - - function testDeflate() - { - if(!function_exists('gzdeflate')) - { - $this->fail('Zlib missing: cannot test deflate functionality'); - return; - } - $this->client->accepted_compression = array('deflate'); - $this->client->request_compression = 'deflate'; - $this->_runtests(); - } - - function testGzip() - { - if(!function_exists('gzdeflate')) - { - $this->fail('Zlib missing: cannot test gzip functionality'); - return; - } - $this->client->accepted_compression = array('gzip'); - $this->client->request_compression = 'gzip'; - $this->_runtests(); - } - - function testKeepAlives() - { - if(!function_exists('curl_init')) - { - $this->fail('CURL missing: cannot test http 1.1'); - return; - } - $this->method = 'http11'; - $this->client->keepalive = true; - $this->_runtests(); - } - - function testProxy() - { - global $PROXYSERVER, $PROXYPORT; - if ($PROXYSERVER) + $this->assertTrue($r[0]->faultCode() == 0, "fault from good1"); + if(!$r[0]->faultCode()) + { + $val = $r[0]->value(); + $this->assertTrue( + $val->kindOf() == 'scalar' && $val->scalartyp() == 'string', + "good1 did not return string"); + } + $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad"); + $this->assertTrue($r[2]->faultCode() == 0, "fault from (non recursive) system.multicall"); + $this->assertTrue($r[3]->faultCode() == 0, "fault from good2"); + if(!$r[3]->faultCode()) + { + $val = $r[3]->value(); + $this->assertTrue($val->kindOf() == 'array', "good2 did not return array"); + } + } + + function testClientMulticall3() + { + // NB: This test will NOT pass if server does not support system.multicall. + + $this->client->return_type = 'phpvals'; + $this->client->no_multicall = false; + + $good1 = new xmlrpcmsg('system.methodHelp', + array(php_xmlrpc_encode('system.listMethods'))); + $bad = new xmlrpcmsg('test.nosuch', + array(php_xmlrpc_encode(1), php_xmlrpc_encode(2))); + $recursive = new xmlrpcmsg('system.multicall', + array(new xmlrpcval(array(), 'array'))); + $good2 = new xmlrpcmsg('system.methodSignature', + array(php_xmlrpc_encode('system.listMethods')) + ); + + $r = $this->send(array($good1, $bad, $recursive, $good2)); + if($r) + { + $this->assertTrue(count($r) == 4, "wrong number of return values"); + } + $this->assertTrue($r[0]->faultCode() == 0, "fault from good1"); + if(!$r[0]->faultCode()) + { + $val = $r[0]->value(); + $this->assertTrue( + is_string($val) , "good1 did not return string"); + } + $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad"); + $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall"); + $this->assertTrue($r[3]->faultCode() == 0, "fault from good2"); + if(!$r[3]->faultCode()) + { + $val = $r[3]->value(); + $this->assertTrue(is_array($val), "good2 did not return array"); + } + $this->client->return_type = 'xmlrpcvals'; + } + + function testCatchWarnings() + { + $f = new xmlrpcmsg('examples.generatePHPWarning', array( + new xmlrpcval('whatever', 'string') + )); + $v = $this->send($f); + if($v) + { + $this->assertEquals($v->scalarval(), true); + } + } + + function testCatchExceptions() + { + global $URI; + $f = new xmlrpcmsg('examples.raiseException', array( + new xmlrpcval('whatever', 'string') + )); + $v = $this->send($f, $GLOBALS['xmlrpcerr']['server_error']); + $this->client->path = $URI.'?EXCEPTION_HANDLING=1'; + $v = $this->send($f, 1); + $this->client->path = $URI.'?EXCEPTION_HANDLING=2'; + $v = $this->send($f, $GLOBALS['xmlrpcerr']['invalid_return']); + } + + function testZeroParams() + { + $f = new xmlrpcmsg('system.listMethods'); + $v = $this->send($f); + } + + function testCodeInjectionServerSide() + { + $f = new xmlrpcmsg('system.MethodHelp'); + $f->payload = "validator1.echoStructTest','')); echo('gotcha!'); die(); //"; + $v = $this->send($f); + //$v = $r->faultCode(); + if ($v) + { + $this->assertEquals(0, $v->structsize()); + } + } + + function testAutoRegisteredFunction() + { + $f=new xmlrpcmsg('examples.php.getStateName',array( + new xmlrpcval(23, 'int') + )); + $v=$this->send($f); + if($v) + { + $this->assertEquals('Michigan', $v->scalarval()); + } + else + { + $this->fail('Note: server can only auto register functions if running with PHP 5.0.3 and up'); + } + } + + function testAutoRegisteredClass() + { + $f=new xmlrpcmsg('examples.php2.getStateName',array( + new xmlrpcval(23, 'int') + )); + $v=$this->send($f); + if($v) + { + $this->assertEquals('Michigan', $v->scalarval()); + $f=new xmlrpcmsg('examples.php3.getStateName',array( + new xmlrpcval(23, 'int') + )); + $v=$this->send($f); + if($v) { - $this->client->setProxy($PROXYSERVER, $PROXYPORT); - $this->_runtests(); + $this->assertEquals('Michigan', $v->scalarval()); } - else - $this->fail('PROXY definition missing: cannot test proxy'); - } - - function testHttp11() - { - if(!function_exists('curl_init')) - { - $this->fail('CURL missing: cannot test http 1.1'); - return; - } - $this->method = 'http11'; // not an error the double assignment! - $this->client->method = 'http11'; - //$this->client->verifyhost = 0; - //$this->client->verifypeer = 0; - $this->client->keepalive = false; - $this->_runtests(); - } - - function testHttp11Gzip() - { - if(!function_exists('curl_init')) - { - $this->fail('CURL missing: cannot test http 1.1'); - return; - } - $this->method = 'http11'; // not an error the double assignment! - $this->client->method = 'http11'; - $this->client->keepalive = false; - $this->client->accepted_compression = array('gzip'); - $this->client->request_compression = 'gzip'; - $this->_runtests(); - } - - function testHttp11Deflate() - { - if(!function_exists('curl_init')) - { - $this->fail('CURL missing: cannot test http 1.1'); - return; - } - $this->method = 'http11'; // not an error the double assignment! - $this->client->method = 'http11'; - $this->client->keepalive = false; - $this->client->accepted_compression = array('deflate'); - $this->client->request_compression = 'deflate'; - $this->_runtests(); - } - - function testHttp11Proxy() - { - global $PROXYSERVER, $PROXYPORT; - if(!function_exists('curl_init')) - { - $this->fail('CURL missing: cannot test http 1.1 w. proxy'); - return; - } - else if ($PROXYSERVER == '') + } + else + { + $this->fail('Note: server can only auto register class methods if running with PHP 5.0.3 and up'); + } + } + + function testAutoRegisteredMethod() + { + $func=wrap_xmlrpc_method($this->client, 'examples.getStateName'); + if($func == '') + { + $this->fail('Registration of examples.getStateName failed'); + } + else + { + $v=$func(23); + $this->assertEquals('Michigan', $v); + } + } + + function testGetCookies() + { + // let server set to us some cookies we tell it + $cookies = array( + //'c1' => array(), + 'c2' => array('value' => 'c2'), + 'c3' => array('value' => 'c3', 'expires' => time()+60*60*24*30), + 'c4' => array('value' => 'c4', 'expires' => time()+60*60*24*30, 'path' => '/'), + 'c5' => array('value' => 'c5', 'expires' => time()+60*60*24*30, 'path' => '/', 'domain' => 'localhost'), + ); + $cookiesval = php_xmlrpc_encode($cookies); + $f=new xmlrpcmsg('examples.setcookies',array($cookiesval)); + $r=$this->send($f, 0, true); + if($r) + { + $v = $r->value(); + $this->assertEquals(1, $v->scalarval()); + // now check if we decoded the cookies as we had set them + $rcookies = $r->cookies(); + foreach($cookies as $c => $v) + // format for date string in cookies: 'Mon, 31 Oct 2005 13:50:56 GMT' + // but PHP versions differ on that, some use 'Mon, 31-Oct-2005 13:50:56 GMT'... + if(isset($v['expires'])) + { + if (isset($rcookies[$c]['expires']) && strpos($rcookies[$c]['expires'], '-')) + { + $cookies[$c]['expires'] = gmdate('D, d\-M\-Y H:i:s \G\M\T' ,$cookies[$c]['expires']); + } + else + { + $cookies[$c]['expires'] = gmdate('D, d M Y H:i:s \G\M\T' ,$cookies[$c]['expires']); + } + } + $this->assertEquals($cookies, $rcookies); + } + } + + function testSetCookies() + { + // let server set to us some cookies we tell it + $cookies = array( + 'c0' => null, + 'c1' => 1, + 'c2' => '2 3', + 'c3' => '!@#$%^&*()_+|}{":?><,./\';[]\\=-' + ); + $f=new xmlrpcmsg('examples.getcookies',array()); + foreach ($cookies as $cookie => $val) + { + $this->client->setCookie($cookie, $val); + $cookies[$cookie] = (string) $cookies[$cookie]; + } + $r = $this->client->send($f, $this->timeout, $this->method); + $this->assertEquals($r->faultCode(), 0, 'Error '.$r->faultCode().' connecting to server: '.$r->faultString()); + if(!$r->faultCode()) + { + $v = $r->value(); + $v = php_xmlrpc_decode($v); + // on IIS and Apache getallheaders returns something slightly different... + $this->assertEquals($v, $cookies); + } + } + + function testSendTwiceSameMsg() + { + $f=new xmlrpcmsg('examples.stringecho', array( + new xmlrpcval('hello world', 'string') + )); + $v1 = $this->send($f); + $v2 = $this->send($f); + //$v = $r->faultCode(); + if ($v1 && $v2) + { + $this->assertEquals($v2, $v1); + } + } +} + +class LocalHostMultiTests extends LocalhostTests +{ + function _runtests() + { + global $failed_tests; + foreach(get_class_methods('LocalhostTests') as $meth) + { + if(strpos($meth, 'test') === 0 && $meth != 'testHttps' && $meth != 'testCatchExceptions') { - $this->fail('PROXY definition missing: cannot test proxy w. http 1.1'); - return; + if (!isset($failed_tests[$meth])) + $this->$meth(); } - $this->method = 'http11'; // not an error the double assignment! - $this->client->method = 'http11'; - $this->client->setProxy($PROXYSERVER, $PROXYPORT); - //$this->client->verifyhost = 0; - //$this->client->verifypeer = 0; - $this->client->keepalive = false; - $this->_runtests(); - } - - function testHttps() - { - global $HTTPSSERVER, $HTTPSURI; - if(!function_exists('curl_init')) - { - $this->fail('CURL missing: cannot test https functionality'); - return; - } - $this->client->server = $HTTPSSERVER; - $this->method = 'https'; - $this->client->method = 'https'; - $this->client->path = $HTTPSURI; - $this->_runtests(); - } - - function testHttpsProxy() - { - global $HTTPSSERVER, $HTTPSURI, $PROXYSERVER, $PROXYPORT;; - if(!function_exists('curl_init')) - { - $this->fail('CURL missing: cannot test https functionality'); - return; - } - else if ($PROXYSERVER == '') + if ($this->_failed) { - $this->fail('PROXY definition missing: cannot test proxy w. http 1.1'); - return; + break; } - $this->client->server = $HTTPSSERVER; - $this->method = 'https'; - $this->client->method = 'https'; + } + } + + function testDeflate() + { + if(!function_exists('gzdeflate')) + { + $this->fail('Zlib missing: cannot test deflate functionality'); + return; + } + $this->client->accepted_compression = array('deflate'); + $this->client->request_compression = 'deflate'; + $this->_runtests(); + } + + function testGzip() + { + if(!function_exists('gzdeflate')) + { + $this->fail('Zlib missing: cannot test gzip functionality'); + return; + } + $this->client->accepted_compression = array('gzip'); + $this->client->request_compression = 'gzip'; + $this->_runtests(); + } + + function testKeepAlives() + { + if(!function_exists('curl_init')) + { + $this->fail('CURL missing: cannot test http 1.1'); + return; + } + $this->method = 'http11'; + $this->client->keepalive = true; + $this->_runtests(); + } + + function testProxy() + { + global $PROXYSERVER, $PROXYPORT; + if ($PROXYSERVER) + { $this->client->setProxy($PROXYSERVER, $PROXYPORT); - $this->client->path = $HTTPSURI; - $this->_runtests(); - } - - function testUTF8Responses() - { - global $URI; - //$this->client->path = strpos($URI, '?') === null ? $URI.'?RESPONSE_ENCODING=UTF-8' : $URI.'&RESPONSE_ENCODING=UTF-8'; - $this->client->path = $URI.'?RESPONSE_ENCODING=UTF-8'; - $this->_runtests(); - } - - function testUTF8Requests() - { - $this->client->request_charset_encoding = 'UTF-8'; - $this->_runtests(); - } - - function testISOResponses() - { - global $URI; - //$this->client->path = strpos($URI, '?') === null ? $URI.'?RESPONSE_ENCODING=UTF-8' : $URI.'&RESPONSE_ENCODING=UTF-8'; - $this->client->path = $URI.'?RESPONSE_ENCODING=ISO-8859-1'; - $this->_runtests(); - } - - function testISORequests() - { - $this->client->request_charset_encoding = 'ISO-8859-1'; - $this->_runtests(); - } - } - - class ParsingBugsTests extends PHPUnit_TestCase - { - function testMinusOneString() - { - $v=new xmlrpcval('-1'); - $u=new xmlrpcval('-1', 'string'); - $this->assertEquals($u->scalarval(), $v->scalarval()); - } - - function testUnicodeInMemberName(){ - $v = array('G�nter, El�ne' => new xmlrpcval(1)); - $r = new xmlrpcresp(new xmlrpcval($v, 'struct')); - $r = $r->serialize(); - $m = new xmlrpcmsg('dummy'); - $r = $m->parseResponse($r); - $v = $r->value(); - $this->assertEquals($v->structmemexists('G�nter, El�ne'), true); - } - - function testUnicodeInErrorString() - { - $response = utf8_encode( + $this->_runtests(); + } + else + $this->fail('PROXY definition missing: cannot test proxy'); + } + + function testHttp11() + { + if(!function_exists('curl_init')) + { + $this->fail('CURL missing: cannot test http 1.1'); + return; + } + $this->method = 'http11'; // not an error the double assignment! + $this->client->method = 'http11'; + //$this->client->verifyhost = 0; + //$this->client->verifypeer = 0; + $this->client->keepalive = false; + $this->_runtests(); + } + + function testHttp11Gzip() + { + if(!function_exists('curl_init')) + { + $this->fail('CURL missing: cannot test http 1.1'); + return; + } + $this->method = 'http11'; // not an error the double assignment! + $this->client->method = 'http11'; + $this->client->keepalive = false; + $this->client->accepted_compression = array('gzip'); + $this->client->request_compression = 'gzip'; + $this->_runtests(); + } + + function testHttp11Deflate() + { + if(!function_exists('curl_init')) + { + $this->fail('CURL missing: cannot test http 1.1'); + return; + } + $this->method = 'http11'; // not an error the double assignment! + $this->client->method = 'http11'; + $this->client->keepalive = false; + $this->client->accepted_compression = array('deflate'); + $this->client->request_compression = 'deflate'; + $this->_runtests(); + } + + function testHttp11Proxy() + { + global $PROXYSERVER, $PROXYPORT; + if(!function_exists('curl_init')) + { + $this->fail('CURL missing: cannot test http 1.1 w. proxy'); + return; + } + else if ($PROXYSERVER == '') + { + $this->fail('PROXY definition missing: cannot test proxy w. http 1.1'); + return; + } + $this->method = 'http11'; // not an error the double assignment! + $this->client->method = 'http11'; + $this->client->setProxy($PROXYSERVER, $PROXYPORT); + //$this->client->verifyhost = 0; + //$this->client->verifypeer = 0; + $this->client->keepalive = false; + $this->_runtests(); + } + + function testHttps() + { + global $HTTPSSERVER, $HTTPSURI, $HTTPSIGNOREPEER; + if(!function_exists('curl_init')) + { + $this->fail('CURL missing: cannot test https functionality'); + return; + } + $this->client->server = $HTTPSSERVER; + $this->method = 'https'; + $this->client->method = 'https'; + $this->client->path = $HTTPSURI; + $this->client->setSSLVerifyPeer( !$HTTPSIGNOREPEER ); + $this->_runtests(); + } + + function testHttpsProxy() + { + global $HTTPSSERVER, $HTTPSURI, $PROXYSERVER, $PROXYPORT;; + if(!function_exists('curl_init')) + { + $this->fail('CURL missing: cannot test https functionality'); + return; + } + else if ($PROXYSERVER == '') + { + $this->fail('PROXY definition missing: cannot test proxy w. http 1.1'); + return; + } + $this->client->server = $HTTPSSERVER; + $this->method = 'https'; + $this->client->method = 'https'; + $this->client->setProxy($PROXYSERVER, $PROXYPORT); + $this->client->path = $HTTPSURI; + $this->_runtests(); + } + + function testUTF8Responses() + { + global $URI; + //$this->client->path = strpos($URI, '?') === null ? $URI.'?RESPONSE_ENCODING=UTF-8' : $URI.'&RESPONSE_ENCODING=UTF-8'; + $this->client->path = $URI.'?RESPONSE_ENCODING=UTF-8'; + $this->_runtests(); + } + + function testUTF8Requests() + { + $this->client->request_charset_encoding = 'UTF-8'; + $this->_runtests(); + } + + function testISOResponses() + { + global $URI; + //$this->client->path = strpos($URI, '?') === null ? $URI.'?RESPONSE_ENCODING=UTF-8' : $URI.'&RESPONSE_ENCODING=UTF-8'; + $this->client->path = $URI.'?RESPONSE_ENCODING=ISO-8859-1'; + $this->_runtests(); + } + + function testISORequests() + { + $this->client->request_charset_encoding = 'ISO-8859-1'; + $this->_runtests(); + } +} + +class ParsingBugsTests extends PHPUnit_TestCase +{ + function testMinusOneString() + { + $v=new xmlrpcval('-1'); + $u=new xmlrpcval('-1', 'string'); + $this->assertEquals($u->scalarval(), $v->scalarval()); + } + + function testUnicodeInMemberName(){ + $str = "G".chr(252)."nter, El".chr(232)."ne"; + $v = array($str => new xmlrpcval(1)); + $r = new xmlrpcresp(new xmlrpcval($v, 'struct')); + $r = $r->serialize(); + $m = new xmlrpcmsg('dummy'); + $r = $m->parseResponse($r); + $v = $r->value(); + $this->assertEquals($v->structmemexists($str), true); + } + + function testUnicodeInErrorString() + { + $response = utf8_encode( ' + UTF8 chars in response text and comments --> @@ -864,16 +864,16 @@ And turned it into nylon'; '); - $m=new xmlrpcmsg('dummy'); - $r=$m->parseResponse($response); - $v=$r->faultString(); - $this->assertEquals('������', $v); - } - - function testValidNumbers() - { - $m=new xmlrpcmsg('dummy'); - $fp= + $m=new xmlrpcmsg('dummy'); + $r=$m->parseResponse($response); + $v=$r->faultString(); + $this->assertEquals('���àüè', $v); + } + + function testValidNumbers() + { + $m=new xmlrpcmsg('dummy'); + $fp= ' @@ -905,63 +905,63 @@ And turned it into nylon'; '; - $r=$m->parseResponse($fp); - $v=$r->value(); - $s=$v->structmem('integer1'); - $t=$v->structmem('float1'); - $u=$v->structmem('integer2'); - $w=$v->structmem('float2'); - $x=$v->structmem('float3'); - $this->assertEquals(1, $s->scalarval()); - $this->assertEquals(1.1, $t->scalarval()); - $this->assertEquals(1, $u->scalarval()); - $this->assertEquals(1.1, $w->scalarval()); - $this->assertEquals(-110.0, $x->scalarval()); - } - - function testAddScalarToStruct() - { - $v=new xmlrpcval(array('a' => 'b'), 'struct'); - // use @ operator in case error_log gets on screen - $r= @$v->addscalar('c'); - $this->assertEquals(0, $r); - } - - function testAddStructToStruct() - { - $v=new xmlrpcval(array('a' => new xmlrpcval('b')), 'struct'); - $r=$v->addstruct(array('b' => new xmlrpcval('c'))); - $this->assertEquals(2, $v->structsize()); - $this->assertEquals(1, $r); - $r=$v->addstruct(array('b' => new xmlrpcval('b'))); - $this->assertEquals(2, $v->structsize()); - } - - function testAddArrayToArray() - { - $v=new xmlrpcval(array(new xmlrpcval('a'), new xmlrpcval('b')), 'array'); - $r=$v->addarray(array(new xmlrpcval('b'), new xmlrpcval('c'))); - $this->assertEquals(4, $v->arraysize()); - $this->assertEquals(1, $r); - } - - function testEncodeArray() - { - $r=range(1, 100); - $v = php_xmlrpc_encode($r); - $this->assertEquals('array', $v->kindof()); - } - - function testEncodeRecursive() - { - $v = php_xmlrpc_encode(php_xmlrpc_encode('a simple string')); - $this->assertEquals('scalar', $v->kindof()); - } - - function testBrokenRequests() - { - $s = new xmlrpc_server(); -// omitting the 'params' tag: not tolerated by the lib anymore + $r=$m->parseResponse($fp); + $v=$r->value(); + $s=$v->structmem('integer1'); + $t=$v->structmem('float1'); + $u=$v->structmem('integer2'); + $w=$v->structmem('float2'); + $x=$v->structmem('float3'); + $this->assertEquals(1, $s->scalarval()); + $this->assertEquals(1.1, $t->scalarval()); + $this->assertEquals(1, $u->scalarval()); + $this->assertEquals(1.1, $w->scalarval()); + $this->assertEquals(-110.0, $x->scalarval()); + } + + function testAddScalarToStruct() + { + $v=new xmlrpcval(array('a' => 'b'), 'struct'); + // use @ operator in case error_log gets on screen + $r= @$v->addscalar('c'); + $this->assertEquals(0, $r); + } + + function testAddStructToStruct() + { + $v=new xmlrpcval(array('a' => new xmlrpcval('b')), 'struct'); + $r=$v->addstruct(array('b' => new xmlrpcval('c'))); + $this->assertEquals(2, $v->structsize()); + $this->assertEquals(1, $r); + $r=$v->addstruct(array('b' => new xmlrpcval('b'))); + $this->assertEquals(2, $v->structsize()); + } + + function testAddArrayToArray() + { + $v=new xmlrpcval(array(new xmlrpcval('a'), new xmlrpcval('b')), 'array'); + $r=$v->addarray(array(new xmlrpcval('b'), new xmlrpcval('c'))); + $this->assertEquals(4, $v->arraysize()); + $this->assertEquals(1, $r); + } + + function testEncodeArray() + { + $r=range(1, 100); + $v = php_xmlrpc_encode($r); + $this->assertEquals('array', $v->kindof()); + } + + function testEncodeRecursive() + { + $v = php_xmlrpc_encode(php_xmlrpc_encode('a simple string')); + $this->assertEquals('scalar', $v->kindof()); + } + + function testBrokenRequests() + { + $s = new xmlrpc_server(); + // omitting the 'params' tag: not tolerated by the lib anymore $f = ' system.methodHelp @@ -969,9 +969,9 @@ $f = ' system.methodHelp '; - $r = $s->parserequest($f); - $this->assertEquals(15, $r->faultCode()); -// omitting a 'param' tag + $r = $s->parserequest($f); + $this->assertEquals(15, $r->faultCode()); + // omitting a 'param' tag $f = ' system.methodHelp @@ -979,9 +979,9 @@ $f = ' system.methodHelp '; - $r = $s->parserequest($f); - $this->assertEquals(15, $r->faultCode()); -// omitting a 'value' tag + $r = $s->parserequest($f); + $this->assertEquals(15, $r->faultCode()); + // omitting a 'value' tag $f = ' system.methodHelp @@ -989,51 +989,51 @@ $f = ' system.methodHelp '; - $r = $s->parserequest($f); - $this->assertEquals(15, $r->faultCode()); - } - - function testBrokenResponses() - { - $m=new xmlrpcmsg('dummy'); - //$m->debug = 1; -// omitting the 'params' tag: no more tolerated by the lib... + $r = $s->parserequest($f); + $this->assertEquals(15, $r->faultCode()); + } + + function testBrokenResponses() + { + $m=new xmlrpcmsg('dummy'); + //$m->debug = 1; + // omitting the 'params' tag: no more tolerated by the lib... $f = ' system.methodHelp '; - $r = $m->parseResponse($f); - $this->assertEquals(2, $r->faultCode()); -// omitting the 'param' tag: no more tolerated by the lib... + $r = $m->parseResponse($f); + $this->assertEquals(2, $r->faultCode()); + // omitting the 'param' tag: no more tolerated by the lib... $f = ' system.methodHelp '; - $r = $m->parseResponse($f); - $this->assertEquals(2, $r->faultCode()); -// omitting a 'value' tag: KO + $r = $m->parseResponse($f); + $this->assertEquals(2, $r->faultCode()); + // omitting a 'value' tag: KO $f = ' system.methodHelp '; - $r = $m->parseResponse($f); - $this->assertEquals(2, $r->faultCode()); - } + $r = $m->parseResponse($f); + $this->assertEquals(2, $r->faultCode()); + } - function testBuggyHttp() - { - $s = new xmlrpcmsg('dummy'); + function testBuggyHttp() + { + $s = new xmlrpcmsg('dummy'); $f = 'HTTP/1.1 100 Welcome to the jungle HTTP/1.0 200 OK X-Content-Marx-Brothers: Harpo - Chico and Groucho + Chico and Groucho Content-Length: who knows? @@ -1047,15 +1047,15 @@ Content-Length: who knows? and there they were.postid7414222 '; - $r = $s->parseResponse($f); - $v = $r->value(); - $s = $v->structmem('content'); - $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s->scalarval()); - } - - function testStringBug() - { - $s = new xmlrpcmsg('dummy'); + $r = $s->parseResponse($f); + $v = $r->value(); + $s = $v->structmem('content'); + $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s->scalarval()); + } + + function testStringBug() + { + $s = new xmlrpcmsg('dummy'); $f = '