args = argParser::getArgs();
if ($this->args['DEBUG'] == 1)
ob_start();
}
protected function tear_down()
{
if ($this->args['DEBUG'] != 1)
return;
$out = ob_get_clean();
$status = $this->getStatus();
if ($status == BaseTestRunner::STATUS_ERROR
|| $status == BaseTestRunner::STATUS_FAILURE) {
echo $out;
}
}
protected function newMsg($methodName, $params = array())
{
$msg = new xmlrpcmsg($methodName, $params);
$msg->setDebug($this->args['DEBUG']);
return $msg;
}
public function testValidNumbers()
{
$m = $this->newMsg('dummy');
$fp =
'
integer1
01
integer2
+1
integer3
1
float1
01.10
float2
+1.10
float3
-1.10e2
';
$r = $m->parseResponse($fp);
$v = $r->value();
$s = $v->structmem('integer1');
$t = $v->structmem('integer2');
$u = $v->structmem('integer3');
$x = $v->structmem('float1');
$y = $v->structmem('float2');
$z = $v->structmem('float3');
$this->assertEquals(1, $s->scalarval());
$this->assertEquals(1, $t->scalarval());
$this->assertEquals(1, $u->scalarval());
$this->assertEquals(1.1, $x->scalarval());
$this->assertEquals(1.1, $y->scalarval());
$this->assertEquals(-110.0, $z->scalarval());
}
public function testI8()
{
if (PHP_INT_SIZE == 4 ) {
$this->markTestSkipped('Can not test i8 as php is compiled in 32 bit mode');
return;
}
$m = $this->newMsg('dummy');
$fp =
'
integer1
1
';
$r = $m->parseResponse($fp);
$v = $r->value();
$s = $v->structmem('integer1');
$this->assertEquals(1, $s->scalarval());
}
public 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 = $this->newMsg('dummy');
$r = $m->parseResponse($r);
$v = $r->value();
$this->assertEquals(true, $v->structmemexists($str));
}
public function testUnicodeInErrorString()
{
$response = utf8_encode(
'
faultCode
888
faultString
' . chr(224) . chr(252) . chr(232) . 'àüè
');
$m = $this->newMsg('dummy');
$r = $m->parseResponse($response);
$v = $r->faultString();
$this->assertEquals(chr(224) . chr(252) . chr(232) . chr(224) . chr(252) . chr(232), $v);
}
public function testBrokenRequests()
{
$s = new xmlrpc_server();
// omitting the 'params' tag: not tolerated by the lib anymore
$f = '
system.methodHelp
system.methodHelp
';
$r = $s->parserequest($f);
$this->assertEquals(15, $r->faultCode());
// omitting a 'param' tag
$f = '
system.methodHelp
system.methodHelp
';
$r = $s->parserequest($f);
$this->assertEquals(15, $r->faultCode());
// omitting a 'value' tag
$f = '
system.methodHelp
system.methodHelp
';
$r = $s->parserequest($f);
$this->assertEquals(15, $r->faultCode());
}
public function testBrokenResponses()
{
$m = $this->newMsg('dummy');
// 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...
$f = '
system.methodHelp
';
$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());
}
public function testBuggyHttp()
{
$s = $this->newMsg('dummy');
$f = 'HTTP/1.1 100 Welcome to the jungle
HTTP/1.0 200 OK
X-Content-Marx-Brothers: Harpo
Chico and Groucho
Content-Length: who knows?
userid311127
dateCreated20011126T09:17:52contenthello world. 2 newlines follow
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());
}
public function testStringBug()
{
$s = $this->newMsg('dummy');
$f = '
success
1
sessionID
S300510007I
';
$r = $s->parseResponse($f);
$v = $r->value();
$s = $v->structmem('sessionID');
$this->assertEquals('S300510007I', $s->scalarval());
}
public function testWhiteSpace()
{
$s = $this->newMsg('dummy');
$f = 'userid311127
dateCreated20011126T09:17:52contenthello world. 2 newlines follow
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());
}
public function testDoubleDataInArrayTag()
{
$s = $this->newMsg('dummy');
$f = '
';
$r = $s->parseResponse($f);
$v = $r->faultCode();
$this->assertEquals(2, $v);
$f = '
Hello world
';
$r = $s->parseResponse($f);
$v = $r->faultCode();
$this->assertEquals(2, $v);
}
public function testDoubleStuffInValueTag()
{
$s = $this->newMsg('dummy');
$f = '
hello world
';
$r = $s->parseResponse($f);
$v = $r->faultCode();
$this->assertEquals(2, $v);
$f = '
hello
world
';
$r = $s->parseResponse($f);
$v = $r->faultCode();
$this->assertEquals(2, $v);
$f = '
hello
hello>world
';
$r = $s->parseResponse($f);
$v = $r->faultCode();
$this->assertEquals(2, $v);
}
public function testAutodecodeResponse()
{
$s = $this->newMsg('dummy');
$f = 'userid311127
dateCreated20011126T09:17:52contenthello world. 3 newlines follow
and there they were.postid7414222
';
$r = $s->parseResponse($f, true, 'phpvals');
$v = $r->value();
$s = $v['content'];
$this->assertEquals("hello world. 3 newlines follow\n\n\nand there they were.", $s);
}
public function testNoDecodeResponse()
{
$s = $this->newMsg('dummy');
$f = 'userid311127
dateCreated20011126T09:17:52contenthello world. 3 newlines follow
and there they were.postid7414222';
$r = $s->parseResponse($f, true, 'xml');
$v = $r->value();
$this->assertEquals($f, $v);
}
public function testUTF8Request()
{
$sendstring = 'κόσμε'; // Greek word 'kosme'. NB: NOT a valid ISO8859 string!
$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
\PhpXmlRpc\PhpXmlRpc::importGlobals();
$f = new xmlrpcval($sendstring, 'string');
$v = $f->serialize();
$this->assertEquals("κόσμε\n", $v);
$GLOBALS['xmlrpc_internalencoding'] = 'ISO-8859-1';
\PhpXmlRpc\PhpXmlRpc::importGlobals();
}
public function testUTF8Response()
{
$string = chr(224) . chr(252) . chr(232);
$s = $this->newMsg('dummy');
$f = "HTTP/1.1 200 OK\r\nContent-type: text/xml; charset=UTF-8\r\n\r\n" . 'userid311127
dateCreated20011126T09:17:52content' . utf8_encode($string) . 'postid7414222
';
$r = $s->parseResponse($f, false, 'phpvals');
$v = $r->value();
$v = $v['content'];
$this->assertEquals($string, $v);
$f = 'userid311127
dateCreated20011126T09:17:52content' . utf8_encode($string) . 'postid7414222
';
$r = $s->parseResponse($f, false, 'phpvals');
$v = $r->value();
$v = $v['content'];
$this->assertEquals($string, $v);
/// @todo move to EncoderTest
$r = php_xmlrpc_decode_xml($f);
$v = $r->value();
$v = $v->structmem('content')->scalarval();
$this->assertEquals($string, $v);
}
public function testLatin1Response()
{
$string = chr(224) . chr(252) . chr(232);
$s = $this->newMsg('dummy');
$f = "HTTP/1.1 200 OK\r\nContent-type: text/xml; charset=ISO-8859-1\r\n\r\n" . 'userid311127
dateCreated20011126T09:17:52content' . $string . 'postid7414222
';
$r = $s->parseResponse($f, false, 'phpvals');
$v = $r->value();
$v = $v['content'];
$this->assertEquals($string, $v);
$f = 'userid311127
dateCreated20011126T09:17:52content' . $string . 'postid7414222
';
$r = $s->parseResponse($f, false, 'phpvals');
$v = $r->value();
$v = $v['content'];
$this->assertEquals($string, $v);
/// @todo move to EncoderTest
$r = php_xmlrpc_decode_xml($f);
$v = $r->value();
$v = $v->structmem('content')->scalarval();
$this->assertEquals($string, $v);
}
/// @todo can we change this test to purely using the Value class ?
public function testNilvalue()
{
// default case: we do not accept nil values received
$v = new xmlrpcval('hello', 'null');
$r = new xmlrpcresp($v);
$s = $r->serialize();
$m = $this->newMsg('dummy');
$r = $m->parseresponse($s);
$this->assertequals(2, $r->faultCode());
// enable reception of nil values
$GLOBALS['xmlrpc_null_extension'] = true;
\PhpXmlRpc\PhpXmlRpc::importGlobals();
$r = $m->parseresponse($s);
$v = $r->value();
$this->assertequals('null', $v->scalartyp());
// test with the apache version: EX:NIL
$GLOBALS['xmlrpc_null_apache_encoding'] = true;
\PhpXmlRpc\PhpXmlRpc::importGlobals();
// serialization
$v = new xmlrpcval('hello', 'null');
$s = $v->serialize();
$this->assertequals(1, preg_match('##', $s));
// deserialization
$r = new xmlrpcresp($v);
$s = $r->serialize();
$r = $m->parseresponse($s);
$v = $r->value();
$this->assertequals('null', $v->scalartyp());
$GLOBALS['xmlrpc_null_extension'] = false;
\PhpXmlRpc\PhpXmlRpc::importGlobals();
$r = $m->parseresponse($s);
$this->assertequals(2, $r->faultCode());
}
}