3 include_once __DIR__ . '/../lib/xmlrpc.inc';
4 include_once __DIR__ . '/../lib/xmlrpcs.inc';
6 include_once __DIR__ . '/parse_args.php';
8 include_once __DIR__ . '/PolyfillTestCase.php';
10 use PHPUnit\Runner\BaseTestRunner;
13 * Tests involving automatic encoding/decoding of php values into xmlrpc values
14 * @todo add tests for encoding options: 'encode_php_objs', 'auto_dates', 'null_extension' and 'extension_api'
15 * @todo add tests for php_xmlrpc_decode options
17 class EncoderTests extends PhpXmlRpc_PolyfillTestCase
19 public $args = array();
21 protected function set_up()
23 $this->args = argParser::getArgs();
24 if ($this->args['DEBUG'] == 1)
28 protected function tear_down()
30 if ($this->args['DEBUG'] != 1)
32 $out = ob_get_clean();
33 $status = $this->getStatus();
34 if ($status == BaseTestRunner::STATUS_ERROR
35 || $status == BaseTestRunner::STATUS_FAILURE) {
40 public function testEncodeArray()
42 $v = php_xmlrpc_encode(array());
43 $this->assertEquals('array', $v->kindof());
46 $v = php_xmlrpc_encode($r);
47 $this->assertEquals('array', $v->kindof());
50 $v = php_xmlrpc_encode($r);
51 $this->assertEquals('struct', $v->kindof());
54 public function testEncodeDate()
57 $v = php_xmlrpc_encode($r);
58 $this->assertEquals('dateTime.iso8601', $v->scalartyp());
61 public function testEncodeRecursive()
63 $v = php_xmlrpc_encode(php_xmlrpc_encode('a simple string'));
64 $this->assertEquals('scalar', $v->kindof());
67 public function testAutoCoDec()
69 $data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00');
70 $data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1);
71 $data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2);
72 //$keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
73 $v1 = php_xmlrpc_encode($data, array('auto_dates'));
74 $v2 = php_xmlrpc_decode_xml($v1->serialize());
75 $this->assertEquals($v1, $v2);
76 $r1 = new PhpXmlRpc\Response($v1);
77 $r2 = php_xmlrpc_decode_xml($r1->serialize());
78 $r2->serialize(); // needed to set internal member payload
79 $this->assertEquals($r1, $r2);
80 $m1 = new PhpXmlRpc\Request('hello dolly', array($v1));
81 $m2 = php_xmlrpc_decode_xml($m1->serialize());
82 $m2->serialize(); // needed to set internal member payload
83 $this->assertEquals($m1, $m2);