1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
include_once __DIR__ . '/LoggerAwareTestCase.php'; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Tests involving the Value class. |
7
|
|
|
* NB: these tests do not involve the parsing of xml into Value objects - look in 04ParsingTest for that |
8
|
|
|
*/ |
9
|
|
|
class ValueTest extends PhpXmlRpc_LoggerAwareTestCase |
10
|
|
|
{ |
11
|
|
|
public function testMinusOneString() |
12
|
|
|
{ |
13
|
|
|
$v = new xmlrpcval('-1'); |
14
|
|
|
$u = new xmlrpcval('-1', 'string'); |
15
|
|
|
$t = new xmlrpcval(-1, 'string'); |
16
|
|
|
$this->assertEquals($v->scalarval(), $u->scalarval()); |
17
|
|
|
$this->assertEquals($v->scalarval(), $t->scalarval()); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* This looks funny, and we might call it a bug. But we strive for 100 backwards compat... |
22
|
|
|
*/ |
23
|
|
|
public function testMinusOneInt() |
24
|
|
|
{ |
25
|
|
|
$u = new xmlrpcval(); |
26
|
|
|
$v = new xmlrpcval(-1); |
27
|
|
|
$this->assertEquals($u->scalarval(), $v->scalarval()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testAddScalarToStruct() |
31
|
|
|
{ |
32
|
|
|
$v = new xmlrpcval(array('a' => 'b'), 'struct'); |
33
|
|
|
$r = $v->addscalar('c'); |
34
|
|
|
$this->assertEquals(0, $r); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testAddStructToStruct() |
38
|
|
|
{ |
39
|
|
|
$v = new xmlrpcval(array('a' => new xmlrpcval('b')), 'struct'); |
40
|
|
|
$r = $v->addstruct(array('b' => new xmlrpcval('c'))); |
41
|
|
|
$this->assertEquals(2, $v->structsize()); |
|
|
|
|
42
|
|
|
$this->assertEquals(1, $r); |
43
|
|
|
$r = $v->addstruct(array('b' => new xmlrpcval('b'))); |
|
|
|
|
44
|
|
|
$this->assertEquals(2, $v->structsize()); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testAddArrayToArray() |
48
|
|
|
{ |
49
|
|
|
$v = new xmlrpcval(array(new xmlrpcval('a'), new xmlrpcval('b')), 'array'); |
50
|
|
|
$r = $v->addarray(array(new xmlrpcval('b'), new xmlrpcval('c'))); |
51
|
|
|
$this->assertEquals(4, $v->arraysize()); |
|
|
|
|
52
|
|
|
$this->assertEquals(1, $r); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/// @todo does this test check something useful at all? |
56
|
|
|
public function testUTF8IntString() |
57
|
|
|
{ |
58
|
|
|
$v = new xmlrpcval(100, 'int'); |
59
|
|
|
$s = $v->serialize('UTF-8'); |
60
|
|
|
$this->assertequals("<value><int>100</int></value>\n", $s); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testUTF8String() |
64
|
|
|
{ |
65
|
|
|
$sendstring = 'κόσμε'; // Greek word 'kosme' |
66
|
|
|
$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8'; |
67
|
|
|
\PhpXmlRpc\PhpXmlRpc::importGlobals(); |
|
|
|
|
68
|
|
|
$f = new xmlrpcval($sendstring, 'string'); |
69
|
|
|
$v = $f->serialize(); |
70
|
|
|
$this->assertEquals("<value><string>κόσμε</string></value>\n", $v); |
71
|
|
|
$v = $f->serialize('UTF-8'); |
72
|
|
|
$this->assertEquals("<value><string>$sendstring</string></value>\n", $v); |
73
|
|
|
$GLOBALS['xmlrpc_internalencoding'] = 'ISO-8859-1'; |
74
|
|
|
\PhpXmlRpc\PhpXmlRpc::importGlobals(); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testStringInt() |
78
|
|
|
{ |
79
|
|
|
$v = new xmlrpcval('hello world', 'int'); |
80
|
|
|
$s = $v->serialize(); |
81
|
|
|
$this->assertequals("<value><int>0</int></value>\n", $s); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testDate() |
85
|
|
|
{ |
86
|
|
|
$tz = date_default_timezone_get(); |
87
|
|
|
date_default_timezone_set('UTC'); |
88
|
|
|
|
89
|
|
|
$ts = 86401; |
90
|
|
|
$dt = new DateTime('@86401'); |
91
|
|
|
|
92
|
|
|
$v = new xmlrpcval(86401, 'dateTime.iso8601'); |
93
|
|
|
$s = $v->serialize(); |
94
|
|
|
$this->assertequals("<value><dateTime.iso8601>19700102T00:00:01</dateTime.iso8601></value>\n", $s); |
95
|
|
|
|
96
|
|
|
$v = new xmlrpcval($dt, 'dateTime.iso8601'); |
97
|
|
|
$s = $v->serialize(); |
98
|
|
|
$this->assertequals("<value><dateTime.iso8601>19700102T00:00:01</dateTime.iso8601></value>\n", $s); |
99
|
|
|
|
100
|
|
|
$v = new xmlrpcval(\PhpXmlRpc\Helper\Date::iso8601Encode($ts), 'dateTime.iso8601'); |
101
|
|
|
$s = $v->serialize(); |
102
|
|
|
$this->assertequals("<value><dateTime.iso8601>19700102T00:00:01</dateTime.iso8601></value>\n", $s); |
103
|
|
|
|
104
|
|
|
$v = new xmlrpcval(\PhpXmlRpc\Helper\Date::iso8601Encode($dt), 'dateTime.iso8601'); |
105
|
|
|
$s = $v->serialize(); |
106
|
|
|
$this->assertequals("<value><dateTime.iso8601>19700102T00:00:01</dateTime.iso8601></value>\n", $s); |
107
|
|
|
|
108
|
|
|
date_default_timezone_set($tz); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/// @todo is this included in the above? |
112
|
|
|
public function testDateTime() |
113
|
|
|
{ |
114
|
|
|
$time = time(); |
115
|
|
|
$t1 = new xmlrpcval($time, 'dateTime.iso8601'); |
116
|
|
|
$t2 = new xmlrpcval(iso8601_encode($time), 'dateTime.iso8601'); |
117
|
|
|
$this->assertEquals($t1->serialize(), $t2->serialize()); |
118
|
|
|
$datetime = new DateTime(); |
119
|
|
|
$t3 = new xmlrpcval($datetime->setTimestamp($time), 'dateTime.iso8601'); |
120
|
|
|
$this->assertEquals($t1->serialize(), $t3->serialize()); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function testStructMemExists() |
124
|
|
|
{ |
125
|
|
|
$v = new xmlrpcval(array('hello' => new xmlrpcval('world')), 'struct'); |
126
|
|
|
$b = $v->structmemexists('hello'); |
|
|
|
|
127
|
|
|
$this->assertequals(true, $b); |
128
|
|
|
$b = $v->structmemexists('world'); |
|
|
|
|
129
|
|
|
$this->assertequals(false, $b); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function testLocale() |
133
|
|
|
{ |
134
|
|
|
$locale = setlocale(LC_NUMERIC, 0); |
135
|
|
|
/// @todo on php 5.3/win, possibly later versions, setting locale to german does not seem to set decimal separator to comma... |
136
|
|
|
if (setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false) { |
137
|
|
|
$v = new xmlrpcval(1.1, 'double'); |
138
|
|
|
if (strpos($v->scalarval(), ',') == 1) { |
139
|
|
|
$r = $v->serialize(); |
140
|
|
|
$this->assertequals(false, strpos($r, ',')); |
141
|
|
|
setlocale(LC_NUMERIC, $locale); |
142
|
|
|
} else { |
143
|
|
|
setlocale(LC_NUMERIC, $locale); |
144
|
|
|
$this->markTestSkipped('did not find a locale which sets decimal separator to comma'); |
145
|
|
|
} |
146
|
|
|
} else { |
147
|
|
|
$this->markTestSkipped('did not find a locale which sets decimal separator to comma'); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function testArrayAccess() |
152
|
|
|
{ |
153
|
|
|
$v1 = new xmlrpcval(array(new xmlrpcval('one'), new xmlrpcval('two')), 'array'); |
154
|
|
|
$this->assertequals(1, count($v1)); |
155
|
|
|
$out = array('me' => array(), 'mytype' => 2, '_php_class' => null); |
156
|
|
|
|
157
|
|
|
foreach($v1 as $key => $val) |
158
|
|
|
{ |
159
|
|
|
$this->assertArrayHasKey($key, $out); |
160
|
|
|
$expected = $out[$key]; |
161
|
|
|
if (gettype($expected) == 'array') { |
162
|
|
|
$this->assertequals('array', gettype($val)); |
163
|
|
|
} else { |
164
|
|
|
$this->assertequals($expected, $val); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
$v2 = new \PhpXmlRpc\Value(array(new \PhpXmlRpc\Value('one'), new \PhpXmlRpc\Value('two')), 'array'); |
169
|
|
|
$this->assertequals(2, count($v2)); |
170
|
|
|
$out = array(array('key' => 0, 'value' => 'object'), array('key' => 1, 'value' => 'object')); |
171
|
|
|
$i = 0; |
172
|
|
|
foreach($v2 as $key => $val) |
173
|
|
|
{ |
174
|
|
|
$expected = $out[$i]; |
175
|
|
|
$this->assertequals($expected['key'], $key); |
176
|
|
|
$this->assertequals($expected['value'], gettype($val)); |
177
|
|
|
$i++; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
$v3 = new \PhpXmlRpc\Value(10, 'i4'); |
181
|
|
|
$this->assertEquals(1, count($v3)); |
182
|
|
|
$this->assertEquals(true, isset($v3['int'])); |
183
|
|
|
$this->assertEquals(true, isset($v3['i4'])); |
184
|
|
|
$this->assertEquals(10, $v3['int']); |
185
|
|
|
$this->assertEquals(10, $v3['i4']); |
186
|
|
|
$v3['int'] = 100; |
187
|
|
|
$this->assertEquals(100, $v3['int']); |
188
|
|
|
$this->assertEquals(100, $v3['i4']); |
189
|
|
|
$v3['i4'] = 1000; |
190
|
|
|
$this->assertEquals(1000, $v3['int']); |
191
|
|
|
$this->assertEquals(1000, $v3['i4']); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/// @todo do not use \PhpXmlRpc\Encoder for this test |
195
|
|
|
public function testBigXML() |
196
|
|
|
{ |
197
|
|
|
// nb: make sure that the serialized xml corresponding to this is > 10MB in size |
198
|
|
|
$data = array(); |
199
|
|
|
for ($i = 0; $i < 500000; $i++ ) { |
200
|
|
|
$data[] = 'hello world'; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
$encoder = new \PhpXmlRpc\Encoder(); |
204
|
|
|
$val = $encoder->encode($data); |
205
|
|
|
$req = new \PhpXmlRpc\Request('test', array($val)); |
206
|
|
|
$xml = $req->serialize(); |
207
|
|
|
$parser = new \PhpXmlRpc\Helper\XMLParser(); |
208
|
|
|
$_xh = $parser->parse($xml); |
209
|
|
|
|
210
|
|
|
$this->assertequals(0, $_xh['isf']); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function testLatin15InternalEncoding() |
214
|
|
|
{ |
215
|
|
|
if (!function_exists('mb_convert_encoding')) { |
216
|
|
|
$this->markTestSkipped('Miss mbstring extension to test exotic charsets'); |
217
|
|
|
return; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
$string = chr(164); |
221
|
|
|
$v = new \PhpXmlRpc\Value($string); |
222
|
|
|
|
223
|
|
|
$originalEncoding = \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding; |
224
|
|
|
\PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'ISO-8859-15'; |
225
|
|
|
|
226
|
|
|
$this->assertEquals("<value><string>€</string></value>", trim($v->serialize('US-ASCII'))); |
227
|
|
|
$this->assertEquals("<value><string>$string</string></value>", trim($v->serialize('ISO-8859-15'))); |
228
|
|
|
$this->assertEquals("<value><string>€</string></value>", trim($v->serialize('UTF-8'))); |
229
|
|
|
|
230
|
|
|
\PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = $originalEncoding; |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.