X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2F1ParsingBugsTest.php;h=f32bd2e5e9d32379ae31ed5c2fffb5f745ecf323;hb=640b8c0e60bb8a13dde241ec4d23ca1f58bb5b8a;hp=4bbccba082e76620145daf3d2e9f25c183185e18;hpb=a3b1d45eb2e1fd0712d574a423c6c4af8d512ee1;p=plcapi.git
diff --git a/tests/1ParsingBugsTest.php b/tests/1ParsingBugsTest.php
index 4bbccba..f32bd2e 100644
--- a/tests/1ParsingBugsTest.php
+++ b/tests/1ParsingBugsTest.php
@@ -5,21 +5,38 @@
include_once __DIR__ . '/../lib/xmlrpc.inc';
include_once __DIR__ . '/../lib/xmlrpcs.inc';
+include_once __DIR__ . '/parse_args.php';
+
+/**
+ * Tests involving parsing of xml and handling of xmlrpc values
+ */
class ParsingBugsTests extends PHPUnit_Framework_TestCase
{
public $args = array();
- public function setUp()
+ protected function setUp()
{
$this->args = argParser::getArgs();
+ if ($this->args['DEBUG'] == 1)
+ ob_start();
+ }
+
+ protected function tearDown()
+ {
+ 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) {
+ echo $out;
+ }
}
protected function newMsg($methodName, $params = array())
{
$msg = new xmlrpcmsg($methodName, $params);
- if ($this->args['DEBUG']) {
- $msg->setDebug($this->args['DEBUG']);
- }
+ $msg->setDebug($this->args['DEBUG']);
return $msg;
}
@@ -28,8 +45,8 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase
$v = new xmlrpcval('-1');
$u = new xmlrpcval('-1', 'string');
$t = new xmlrpcval(-1, 'string');
- $this->assertEquals($u->scalarval(), $v->scalarval());
- $this->assertEquals($t->scalarval(), $v->scalarval());
+ $this->assertEquals($v->scalarval(), $u->scalarval());
+ $this->assertEquals($v->scalarval(), $t->scalarval());
}
/**
@@ -37,8 +54,8 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase
*/
public function testMinusOneInt()
{
- $v = new xmlrpcval(-1);
$u = new xmlrpcval();
+ $v = new xmlrpcval(-1);
$this->assertEquals($u->scalarval(), $v->scalarval());
}
@@ -51,7 +68,7 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase
$m = $this->newMsg('dummy');
$r = $m->parseResponse($r);
$v = $r->value();
- $this->assertEquals($v->structmemexists($str), true);
+ $this->assertEquals(true, $v->structmemexists($str));
}
public function testUnicodeInErrorString()
@@ -439,7 +456,7 @@ and there they were.postid7414222
$v = $v['content'];
$this->assertEquals($string, $v);
- $f = 'userid311127
+ $f = 'userid311127
dateCreated20011126T09:17:52content' . utf8_encode($string) . 'postid7414222
';
$r = $s->parseResponse($f, false, 'phpvals');
@@ -466,7 +483,7 @@ and there they were.postid7414222
$v = $v['content'];
$this->assertEquals($string, $v);
- $f = 'userid311127
+ $f = 'userid311127
dateCreated20011126T09:17:52content' . $string . 'postid7414222
';
$r = $s->parseResponse($f, false, 'phpvals');
@@ -537,7 +554,7 @@ and there they were.postid7414222
$this->assertequals(2, $r->faultCode());
}
- public function TestLocale()
+ 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...
@@ -555,4 +572,31 @@ and there they were.postid7414222
$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));
+ }
+ }
}