1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
include_once __DIR__ . '/LoggerAwareTestCase.php'; |
4
|
|
|
|
5
|
|
|
use PhpXmlRpc\Encoder; |
6
|
|
|
use PhpXmlRpc\Request; |
7
|
|
|
use PhpXmlRpc\Response; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Tests involving automatic encoding/decoding of php values into xmlrpc values (the Encoder class). |
11
|
|
|
* |
12
|
|
|
* @todo add tests for encoding options: 'encode_php_objs', 'auto_dates', 'null_extension' and 'extension_api' |
13
|
|
|
* @todo add tests for php_xmlrpc_decode options |
14
|
|
|
*/ |
15
|
|
|
class EncoderTest extends PhpXmlRpc_LoggerAwareTestCase |
16
|
|
|
{ |
17
|
|
|
public function testEncodeArray() |
18
|
|
|
{ |
19
|
|
|
$v = php_xmlrpc_encode(array()); |
20
|
|
|
$this->assertEquals('array', $v->kindof()); |
21
|
|
|
|
22
|
|
|
$r = range(1, 10); |
23
|
|
|
$v = php_xmlrpc_encode($r); |
24
|
|
|
$this->assertEquals('array', $v->kindof()); |
25
|
|
|
|
26
|
|
|
$r['.'] = '...'; |
27
|
|
|
$v = php_xmlrpc_encode($r); |
28
|
|
|
$this->assertEquals('struct', $v->kindof()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testEncodeDate() |
32
|
|
|
{ |
33
|
|
|
$r = new DateTime(); |
34
|
|
|
$v = php_xmlrpc_encode($r); |
35
|
|
|
$this->assertEquals('dateTime.iso8601', $v->scalartyp()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testEncodeRecursive() |
39
|
|
|
{ |
40
|
|
|
$v = php_xmlrpc_encode(php_xmlrpc_encode('a simple string')); |
41
|
|
|
$this->assertEquals('scalar', $v->kindof()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testAutoCoDec() |
45
|
|
|
{ |
46
|
|
|
$data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00'); |
47
|
|
|
$data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1); |
48
|
|
|
$data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2); |
49
|
|
|
//$keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'); |
50
|
|
|
$v1 = php_xmlrpc_encode($data, array('auto_dates')); |
51
|
|
|
$v2 = php_xmlrpc_decode_xml($v1->serialize()); |
52
|
|
|
$this->assertEquals($v1, $v2); |
53
|
|
|
$r1 = new Response($v1); |
54
|
|
|
$r2 = php_xmlrpc_decode_xml($r1->serialize()); |
55
|
|
|
$r2->serialize(); // needed to set internal member payload |
56
|
|
|
$this->assertEquals($r1, $r2); |
57
|
|
|
$m1 = new Request('hello dolly', array($v1)); |
58
|
|
|
$m2 = php_xmlrpc_decode_xml($m1->serialize()); |
59
|
|
|
$m2->serialize(); // needed to set internal member payload |
60
|
|
|
$this->assertEquals($m1, $m2); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testLatin15InternalEncoding() |
64
|
|
|
{ |
65
|
|
|
if (!function_exists('mb_convert_encoding')) { |
66
|
|
|
$this->markTestSkipped('Miss mbstring extension to test exotic charsets'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$string = chr(164); |
70
|
|
|
$e = new Encoder(); |
71
|
|
|
|
72
|
|
|
$originalEncoding = \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding; |
73
|
|
|
\PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'ISO-8859-15'; |
74
|
|
|
|
75
|
|
|
$a = $e->decodeXml('<?xml version="1.0" encoding="US-ASCII" ?><value><string>€</string></value>'); |
76
|
|
|
$this->assertEquals($string, $a->scalarVal()); |
|
|
|
|
77
|
|
|
|
78
|
|
|
/// @todo it seems that old php versions can not automatically transform latin to utf8 upon xml parsing. |
79
|
|
|
/// We should fix that, then re-enable this test |
80
|
|
|
if (version_compare(PHP_VERSION, '5.6.0', '>=')) { |
81
|
|
|
$i = $e->decodeXml('<?xml version="1.0" encoding="ISO-8859-15" ?><value><string>' . $string . '</string></value>'); |
82
|
|
|
$this->assertEquals($string, $i->scalarVal()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$u = $e->decodeXml('<?xml version="1.0" encoding="UTF-8" ?><value><string>€</string></value>'); |
86
|
|
|
$this->assertEquals($string, $u->scalarVal()); |
87
|
|
|
|
88
|
|
|
/// @todo move to tear_down(), so that we reset this even in case of test failure |
89
|
|
|
\PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = $originalEncoding; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.