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