X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=php%2Fphpxmlrpc%2Ftests%2F2MessageTest.php;fp=php%2Fphpxmlrpc%2Ftests%2F1ParsingBugsTest.php;h=bb7461a97450c915d3c447e13aff7b689b0d4ca2;hb=c379c0fff5edc592cc5d5d647c7fadb91317db87;hp=ce463f7a1283e009e69719cd04b5fcb9118b5a3b;hpb=ae8b10f8363f7a1df02e77cbd820904c4ded10b8;p=plcapi.git
diff --git a/php/phpxmlrpc/tests/1ParsingBugsTest.php b/php/phpxmlrpc/tests/2MessageTest.php
similarity index 71%
rename from php/phpxmlrpc/tests/1ParsingBugsTest.php
rename to php/phpxmlrpc/tests/2MessageTest.php
index ce463f7..bb7461a 100644
--- a/php/phpxmlrpc/tests/1ParsingBugsTest.php
+++ b/php/phpxmlrpc/tests/2MessageTest.php
@@ -1,34 +1,38 @@
args = argParser::getArgs();
if ($this->args['DEBUG'] == 1)
ob_start();
}
- protected function tearDown()
+ protected function tear_down()
{
if ($this->args['DEBUG'] != 1)
return;
$out = ob_get_clean();
$status = $this->getStatus();
- if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR
- || $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
+ if ($status == BaseTestRunner::STATUS_ERROR
+ || $status == BaseTestRunner::STATUS_FAILURE) {
echo $out;
}
}
@@ -40,66 +44,6 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase
return $msg;
}
- public function testMinusOneString()
- {
- $v = new xmlrpcval('-1');
- $u = new xmlrpcval('-1', 'string');
- $t = new xmlrpcval(-1, 'string');
- $this->assertEquals($v->scalarval(), $u->scalarval());
- $this->assertEquals($v->scalarval(), $t->scalarval());
- }
-
- /**
- * This looks funny, and we might call it a bug. But we strive for 100 backwards compat...
- */
- public function testMinusOneInt()
- {
- $u = new xmlrpcval();
- $v = new xmlrpcval(-1);
- $this->assertEquals($u->scalarval(), $v->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 testValidNumbers()
{
@@ -160,7 +104,7 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase
public function testI8()
{
if (PHP_INT_SIZE == 4 ) {
- $this->markTestSkipped('did not find a locale which sets decimal separator to comma');
+ $this->markTestSkipped('Can not test i8 as php is compiled in 32 bit mode');
return;
}
@@ -187,43 +131,45 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase
$this->assertEquals(1, $s->scalarval());
}
- public 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);
- }
-
- public 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());
- }
-
- public 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);
- }
-
- public function testEncodeArray()
+ public function testUnicodeInMemberName()
{
- $r = range(1, 100);
- $v = php_xmlrpc_encode($r);
- $this->assertEquals('array', $v->kindof());
+ $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 testEncodeRecursive()
+ public function testUnicodeInErrorString()
{
- $v = php_xmlrpc_encode(php_xmlrpc_encode('a simple string'));
- $this->assertEquals('scalar', $v->kindof());
+ $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()
@@ -425,7 +371,7 @@ and there they were.postid7414222
{
$s = $this->newMsg('dummy');
$f = 'userid311127
-dateCreated20011126T09:17:52contenthello world. 2 newlines follow
+dateCreated20011126T09:17:52contenthello world. 3 newlines follow
and there they were.postid7414222
@@ -433,14 +379,14 @@ and there they were.postid7414222
$r = $s->parseResponse($f, true, 'phpvals');
$v = $r->value();
$s = $v['content'];
- $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s);
+ $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. 2 newlines follow
+dateCreated20011126T09:17:52contenthello world. 3 newlines follow
and there they were.postid7414222';
@@ -449,25 +395,6 @@ and there they were.postid7414222
$this->assertEquals($f, $v);
}
- public function testAutoCoDec()
- {
- $data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00');
- $data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1);
- $data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2);
- //$keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
- $v1 = php_xmlrpc_encode($data, array('auto_dates'));
- $v2 = php_xmlrpc_decode_xml($v1->serialize());
- $this->assertEquals($v1, $v2);
- $r1 = new PhpXmlRpc\Response($v1);
- $r2 = php_xmlrpc_decode_xml($r1->serialize());
- $r2->serialize(); // needed to set internal member payload
- $this->assertEquals($r1, $r2);
- $m1 = new PhpXmlRpc\Request('hello dolly', array($v1));
- $m2 = php_xmlrpc_decode_xml($m1->serialize());
- $m2->serialize(); // needed to set internal member payload
- $this->assertEquals($m1, $m2);
- }
-
public function testUTF8Request()
{
$sendstring = 'κόÏμε'; // Greek word 'kosme'. NB: NOT a valid ISO8859 string!
@@ -501,6 +428,7 @@ and there they were.postid7414222
$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();
@@ -528,35 +456,14 @@ and there they were.postid7414222
$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 testUTF8IntString()
- {
- $v = new xmlrpcval(100, 'int');
- $s = $v->serialize('UTF-8');
- $this->assertequals("100\n", $s);
- }
-
- public function testStringInt()
- {
- $v = new xmlrpcval('hello world', 'int');
- $s = $v->serialize();
- $this->assertequals("0\n", $s);
- }
-
- public function testStructMemExists()
- {
- $v = php_xmlrpc_encode(array('hello' => 'world'));
- $b = $v->structmemexists('hello');
- $this->assertequals(true, $b);
- $b = $v->structmemexists('world');
- $this->assertequals(false, $b);
- }
-
+ /// @todo can we change this test to purely using the Value class ?
public function testNilvalue()
{
// default case: we do not accept nil values received
@@ -590,50 +497,4 @@ and there they were.postid7414222
$r = $m->parseresponse($s);
$this->assertequals(2, $r->faultCode());
}
-
- public function testLocale()
- {
- $locale = setlocale(LC_NUMERIC, 0);
- /// @todo on php 5.3/win setting locale to german does not seem to set decimal separator to comma...
- if (setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false) {
- $v = new xmlrpcval(1.1, 'double');
- if (strpos($v->scalarval(), ',') == 1) {
- $r = $v->serialize();
- $this->assertequals(false, strpos($r, ','));
- setlocale(LC_NUMERIC, $locale);
- } else {
- setlocale(LC_NUMERIC, $locale);
- $this->markTestSkipped('did not find a locale which sets decimal separator to comma');
- }
- } else {
- $this->markTestSkipped('did not find a locale which sets decimal separator to comma');
- }
- }
-
- public function testArrayAccess()
- {
- $v1 = new xmlrpcval(array(new xmlrpcval('one'), new xmlrpcval('two')), 'array');
- $this->assertequals(1, count($v1));
- $out = array('me' => array(), 'mytype' => 2, '_php_class' => null);
- foreach($v1 as $key => $val)
- {
- $expected = each($out);
- $this->assertequals($expected['key'], $key);
- if (gettype($expected['value']) == 'array') {
- $this->assertequals('array', gettype($val));
- } else {
- $this->assertequals($expected['value'], $val);
- }
- }
-
- $v2 = new \PhpXmlRpc\Value(array(new \PhpXmlRpc\Value('one'), new \PhpXmlRpc\Value('two')), 'array');
- $this->assertequals(2, count($v2));
- $out = array(0 => 'object', 1 => 'object');
- foreach($v2 as $key => $val)
- {
- $expected = each($out);
- $this->assertequals($expected['key'], $key);
- $this->assertequals($expected['value'], gettype($val));
- }
- }
}