1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
include_once __DIR__ . '/../lib/xmlrpc.inc'; |
4
|
|
|
include_once __DIR__ . '/../lib/xmlrpcs.inc'; |
5
|
|
|
|
6
|
|
|
include_once __DIR__ . '/parse_args.php'; |
7
|
|
|
|
8
|
|
|
include_once __DIR__ . '/PolyfillTestCase.php'; |
9
|
|
|
|
10
|
|
|
use PHPUnit\Runner\BaseTestRunner; |
11
|
|
|
|
12
|
|
|
/** |
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 |
16
|
|
|
*/ |
17
|
|
|
class EncoderTests extends PhpXmlRpc_PolyfillTestCase |
18
|
|
|
{ |
19
|
|
|
public $args = array(); |
20
|
|
|
|
21
|
|
|
protected function set_up() |
22
|
|
|
{ |
23
|
|
|
$this->args = argParser::getArgs(); |
24
|
|
|
if ($this->args['DEBUG'] == 1) |
25
|
|
|
ob_start(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function tear_down() |
29
|
|
|
{ |
30
|
|
|
if ($this->args['DEBUG'] != 1) |
31
|
|
|
return; |
32
|
|
|
$out = ob_get_clean(); |
33
|
|
|
$status = $this->getStatus(); |
34
|
|
|
if ($status == BaseTestRunner::STATUS_ERROR |
35
|
|
|
|| $status == BaseTestRunner::STATUS_FAILURE) { |
36
|
|
|
echo $out; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testEncodeArray() |
41
|
|
|
{ |
42
|
|
|
$v = php_xmlrpc_encode(array()); |
43
|
|
|
$this->assertEquals('array', $v->kindof()); |
44
|
|
|
|
45
|
|
|
$r = range(1, 10); |
46
|
|
|
$v = php_xmlrpc_encode($r); |
47
|
|
|
$this->assertEquals('array', $v->kindof()); |
48
|
|
|
|
49
|
|
|
$r['.'] = '...'; |
50
|
|
|
$v = php_xmlrpc_encode($r); |
51
|
|
|
$this->assertEquals('struct', $v->kindof()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testEncodeDate() |
55
|
|
|
{ |
56
|
|
|
$r = new DateTime(); |
57
|
|
|
$v = php_xmlrpc_encode($r); |
58
|
|
|
$this->assertEquals('dateTime.iso8601', $v->scalartyp()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testEncodeRecursive() |
62
|
|
|
{ |
63
|
|
|
$v = php_xmlrpc_encode(php_xmlrpc_encode('a simple string')); |
64
|
|
|
$this->assertEquals('scalar', $v->kindof()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testAutoCoDec() |
68
|
|
|
{ |
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); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|