|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* NB: do not let your IDE fool you. The correct encoding for this file is NOT UTF8. |
|
4
|
|
|
*/ |
|
5
|
|
|
include_once __DIR__ . '/../lib/xmlrpc.inc'; |
|
6
|
|
|
include_once __DIR__ . '/../lib/xmlrpcs.inc'; |
|
7
|
|
|
|
|
8
|
|
|
include_once __DIR__ . '/parse_args.php'; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Tests involving parsing of xml and handling of xmlrpc values |
|
12
|
|
|
*/ |
|
13
|
|
|
class ParsingBugsTests extends PHPUnit_Framework_TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
public $args = array(); |
|
16
|
|
|
|
|
17
|
|
|
protected function setUp() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->args = argParser::getArgs(); |
|
20
|
|
|
if ($this->args['DEBUG'] == 1) |
|
21
|
|
|
ob_start(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
protected function tearDown() |
|
25
|
|
|
{ |
|
26
|
|
|
if ($this->args['DEBUG'] != 1) |
|
27
|
|
|
return; |
|
28
|
|
|
$out = ob_get_clean(); |
|
29
|
|
|
$status = $this->getStatus(); |
|
30
|
|
|
if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR |
|
31
|
|
|
|| $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) { |
|
32
|
|
|
echo $out; |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
protected function newMsg($methodName, $params = array()) |
|
37
|
|
|
{ |
|
38
|
|
|
$msg = new xmlrpcmsg($methodName, $params); |
|
39
|
|
|
$msg->setDebug($this->args['DEBUG']); |
|
40
|
|
|
return $msg; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testMinusOneString() |
|
44
|
|
|
{ |
|
45
|
|
|
$v = new xmlrpcval('-1'); |
|
46
|
|
|
$u = new xmlrpcval('-1', 'string'); |
|
47
|
|
|
$t = new xmlrpcval(-1, 'string'); |
|
48
|
|
|
$this->assertEquals($v->scalarval(), $u->scalarval()); |
|
49
|
|
|
$this->assertEquals($v->scalarval(), $t->scalarval()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* This looks funny, and we might call it a bug. But we strive for 100 backwards compat... |
|
54
|
|
|
*/ |
|
55
|
|
|
public function testMinusOneInt() |
|
56
|
|
|
{ |
|
57
|
|
|
$u = new xmlrpcval(); |
|
58
|
|
|
$v = new xmlrpcval(-1); |
|
59
|
|
|
$this->assertEquals($u->scalarval(), $v->scalarval()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testUnicodeInMemberName() |
|
63
|
|
|
{ |
|
64
|
|
|
$str = "G" . chr(252) . "nter, El" . chr(232) . "ne"; |
|
65
|
|
|
$v = array($str => new xmlrpcval(1)); |
|
66
|
|
|
$r = new xmlrpcresp(new xmlrpcval($v, 'struct')); |
|
67
|
|
|
$r = $r->serialize(); |
|
68
|
|
|
$m = $this->newMsg('dummy'); |
|
69
|
|
|
$r = $m->parseResponse($r); |
|
70
|
|
|
$v = $r->value(); |
|
71
|
|
|
$this->assertEquals(true, $v->structmemexists($str)); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testUnicodeInErrorString() |
|
75
|
|
|
{ |
|
76
|
|
|
$response = utf8_encode( |
|
77
|
|
|
'<?xml version="1.0"?> |
|
78
|
|
|
<!-- $Id --> |
|
79
|
|
|
<!-- found by G. Giunta, covers what happens when lib receives UTF8 chars in response text and comments --> |
|
80
|
|
|
<!-- ' . chr(224) . chr(252) . chr(232) . 'àüè --> |
|
81
|
|
|
<methodResponse> |
|
82
|
|
|
<fault> |
|
83
|
|
|
<value> |
|
84
|
|
|
<struct> |
|
85
|
|
|
<member> |
|
86
|
|
|
<name>faultCode</name> |
|
87
|
|
|
<value><int>888</int></value> |
|
88
|
|
|
</member> |
|
89
|
|
|
<member> |
|
90
|
|
|
<name>faultString</name> |
|
91
|
|
|
<value><string>' . chr(224) . chr(252) . chr(232) . 'àüè</string></value> |
|
92
|
|
|
</member> |
|
93
|
|
|
</struct> |
|
94
|
|
|
</value> |
|
95
|
|
|
</fault> |
|
96
|
|
|
</methodResponse>'); |
|
97
|
|
|
$m = $this->newMsg('dummy'); |
|
98
|
|
|
$r = $m->parseResponse($response); |
|
99
|
|
|
$v = $r->faultString(); |
|
100
|
|
|
$this->assertEquals(chr(224) . chr(252) . chr(232) . chr(224) . chr(252) . chr(232), $v); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function testValidNumbers() |
|
104
|
|
|
{ |
|
105
|
|
|
$m = $this->newMsg('dummy'); |
|
106
|
|
|
$fp = |
|
107
|
|
|
'<?xml version="1.0"?> |
|
108
|
|
|
<methodResponse> |
|
109
|
|
|
<params> |
|
110
|
|
|
<param> |
|
111
|
|
|
<value> |
|
112
|
|
|
<struct> |
|
113
|
|
|
<member> |
|
114
|
|
|
<name>integer1</name> |
|
115
|
|
|
<value><int>01</int></value> |
|
116
|
|
|
</member> |
|
117
|
|
|
<member> |
|
118
|
|
|
<name>integer2</name> |
|
119
|
|
|
<value><int>+1</int></value> |
|
120
|
|
|
</member> |
|
121
|
|
|
<member> |
|
122
|
|
|
<name>integer3</name> |
|
123
|
|
|
<value><i4>1</i4></value> |
|
124
|
|
|
</member> |
|
125
|
|
|
<member> |
|
126
|
|
|
<name>float1</name> |
|
127
|
|
|
<value><double>01.10</double></value> |
|
128
|
|
|
</member> |
|
129
|
|
|
<member> |
|
130
|
|
|
<name>float2</name> |
|
131
|
|
|
<value><double>+1.10</double></value> |
|
132
|
|
|
</member> |
|
133
|
|
|
<member> |
|
134
|
|
|
<name>float3</name> |
|
135
|
|
|
<value><double>-1.10e2</double></value> |
|
136
|
|
|
</member> |
|
137
|
|
|
</struct> |
|
138
|
|
|
</value> |
|
139
|
|
|
</param> |
|
140
|
|
|
</params> |
|
141
|
|
|
</methodResponse>'; |
|
142
|
|
|
$r = $m->parseResponse($fp); |
|
143
|
|
|
$v = $r->value(); |
|
144
|
|
|
$s = $v->structmem('integer1'); |
|
145
|
|
|
$t = $v->structmem('integer2'); |
|
146
|
|
|
$u = $v->structmem('integer3'); |
|
147
|
|
|
$x = $v->structmem('float1'); |
|
148
|
|
|
$y = $v->structmem('float2'); |
|
149
|
|
|
$z = $v->structmem('float3'); |
|
150
|
|
|
$this->assertEquals(1, $s->scalarval()); |
|
151
|
|
|
$this->assertEquals(1, $t->scalarval()); |
|
152
|
|
|
$this->assertEquals(1, $u->scalarval()); |
|
153
|
|
|
|
|
154
|
|
|
$this->assertEquals(1.1, $x->scalarval()); |
|
155
|
|
|
$this->assertEquals(1.1, $y->scalarval()); |
|
156
|
|
|
$this->assertEquals(-110.0, $z->scalarval()); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public function testI8() |
|
160
|
|
|
{ |
|
161
|
|
|
if (PHP_INT_SIZE == 4 ) { |
|
162
|
|
|
$this->markTestSkipped('did not find a locale which sets decimal separator to comma'); |
|
163
|
|
|
return; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
$m = $this->newMsg('dummy'); |
|
167
|
|
|
$fp = |
|
168
|
|
|
'<?xml version="1.0"?> |
|
169
|
|
|
<methodResponse> |
|
170
|
|
|
<params> |
|
171
|
|
|
<param> |
|
172
|
|
|
<value> |
|
173
|
|
|
<struct> |
|
174
|
|
|
<member> |
|
175
|
|
|
<name>integer1</name> |
|
176
|
|
|
<value><i8>1</i8></value> |
|
177
|
|
|
</member> |
|
178
|
|
|
</struct> |
|
179
|
|
|
</value> |
|
180
|
|
|
</param> |
|
181
|
|
|
</params> |
|
182
|
|
|
</methodResponse>'; |
|
183
|
|
|
$r = $m->parseResponse($fp); |
|
184
|
|
|
$v = $r->value(); |
|
185
|
|
|
$s = $v->structmem('integer1'); |
|
186
|
|
|
$this->assertEquals(1, $s->scalarval()); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
public function testAddScalarToStruct() |
|
190
|
|
|
{ |
|
191
|
|
|
$v = new xmlrpcval(array('a' => 'b'), 'struct'); |
|
192
|
|
|
// use @ operator in case error_log gets on screen |
|
193
|
|
|
$r = @$v->addscalar('c'); |
|
194
|
|
|
$this->assertEquals(0, $r); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
public function testAddStructToStruct() |
|
198
|
|
|
{ |
|
199
|
|
|
$v = new xmlrpcval(array('a' => new xmlrpcval('b')), 'struct'); |
|
200
|
|
|
$r = $v->addstruct(array('b' => new xmlrpcval('c'))); |
|
201
|
|
|
$this->assertEquals(2, $v->structsize()); |
|
|
|
|
|
|
202
|
|
|
$this->assertEquals(1, $r); |
|
203
|
|
|
$r = $v->addstruct(array('b' => new xmlrpcval('b'))); |
|
|
|
|
|
|
204
|
|
|
$this->assertEquals(2, $v->structsize()); |
|
|
|
|
|
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
public function testAddArrayToArray() |
|
208
|
|
|
{ |
|
209
|
|
|
$v = new xmlrpcval(array(new xmlrpcval('a'), new xmlrpcval('b')), 'array'); |
|
210
|
|
|
$r = $v->addarray(array(new xmlrpcval('b'), new xmlrpcval('c'))); |
|
211
|
|
|
$this->assertEquals(4, $v->arraysize()); |
|
|
|
|
|
|
212
|
|
|
$this->assertEquals(1, $r); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
public function testEncodeArray() |
|
216
|
|
|
{ |
|
217
|
|
|
$r = range(1, 100); |
|
218
|
|
|
$v = php_xmlrpc_encode($r); |
|
219
|
|
|
$this->assertEquals('array', $v->kindof()); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
public function testEncodeRecursive() |
|
223
|
|
|
{ |
|
224
|
|
|
$v = php_xmlrpc_encode(php_xmlrpc_encode('a simple string')); |
|
225
|
|
|
$this->assertEquals('scalar', $v->kindof()); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
public function testBrokenRequests() |
|
229
|
|
|
{ |
|
230
|
|
|
$s = new xmlrpc_server(); |
|
231
|
|
|
// omitting the 'params' tag: not tolerated by the lib anymore |
|
232
|
|
|
$f = '<?xml version="1.0"?> |
|
233
|
|
|
<methodCall> |
|
234
|
|
|
<methodName>system.methodHelp</methodName> |
|
235
|
|
|
<param> |
|
236
|
|
|
<value><string>system.methodHelp</string></value> |
|
237
|
|
|
</param> |
|
238
|
|
|
</methodCall>'; |
|
239
|
|
|
$r = $s->parserequest($f); |
|
240
|
|
|
$this->assertEquals(15, $r->faultCode()); |
|
241
|
|
|
// omitting a 'param' tag |
|
242
|
|
|
$f = '<?xml version="1.0"?> |
|
243
|
|
|
<methodCall> |
|
244
|
|
|
<methodName>system.methodHelp</methodName> |
|
245
|
|
|
<params> |
|
246
|
|
|
<value><string>system.methodHelp</string></value> |
|
247
|
|
|
</params> |
|
248
|
|
|
</methodCall>'; |
|
249
|
|
|
$r = $s->parserequest($f); |
|
250
|
|
|
$this->assertEquals(15, $r->faultCode()); |
|
251
|
|
|
// omitting a 'value' tag |
|
252
|
|
|
$f = '<?xml version="1.0"?> |
|
253
|
|
|
<methodCall> |
|
254
|
|
|
<methodName>system.methodHelp</methodName> |
|
255
|
|
|
<params> |
|
256
|
|
|
<param><string>system.methodHelp</string></param> |
|
257
|
|
|
</params> |
|
258
|
|
|
</methodCall>'; |
|
259
|
|
|
$r = $s->parserequest($f); |
|
260
|
|
|
$this->assertEquals(15, $r->faultCode()); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
public function testBrokenResponses() |
|
264
|
|
|
{ |
|
265
|
|
|
$m = $this->newMsg('dummy'); |
|
266
|
|
|
// omitting the 'params' tag: no more tolerated by the lib... |
|
267
|
|
|
$f = '<?xml version="1.0"?> |
|
268
|
|
|
<methodResponse> |
|
269
|
|
|
<param> |
|
270
|
|
|
<value><string>system.methodHelp</string></value> |
|
271
|
|
|
</param> |
|
272
|
|
|
</methodResponse>'; |
|
273
|
|
|
$r = $m->parseResponse($f); |
|
274
|
|
|
$this->assertEquals(2, $r->faultCode()); |
|
275
|
|
|
// omitting the 'param' tag: no more tolerated by the lib... |
|
276
|
|
|
$f = '<?xml version="1.0"?> |
|
277
|
|
|
<methodResponse> |
|
278
|
|
|
<params> |
|
279
|
|
|
<value><string>system.methodHelp</string></value> |
|
280
|
|
|
</params> |
|
281
|
|
|
</methodResponse>'; |
|
282
|
|
|
$r = $m->parseResponse($f); |
|
283
|
|
|
$this->assertEquals(2, $r->faultCode()); |
|
284
|
|
|
// omitting a 'value' tag: KO |
|
285
|
|
|
$f = '<?xml version="1.0"?> |
|
286
|
|
|
<methodResponse> |
|
287
|
|
|
<params> |
|
288
|
|
|
<param><string>system.methodHelp</string></param> |
|
289
|
|
|
</params> |
|
290
|
|
|
</methodResponse>'; |
|
291
|
|
|
$r = $m->parseResponse($f); |
|
292
|
|
|
$this->assertEquals(2, $r->faultCode()); |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
public function testBuggyHttp() |
|
296
|
|
|
{ |
|
297
|
|
|
$s = $this->newMsg('dummy'); |
|
298
|
|
|
$f = 'HTTP/1.1 100 Welcome to the jungle |
|
299
|
|
|
|
|
300
|
|
|
HTTP/1.0 200 OK |
|
301
|
|
|
X-Content-Marx-Brothers: Harpo |
|
302
|
|
|
Chico and Groucho |
|
303
|
|
|
Content-Length: who knows? |
|
304
|
|
|
|
|
305
|
|
|
|
|
306
|
|
|
|
|
307
|
|
|
<?xml version="1.0"?> |
|
308
|
|
|
<!-- First of all, let\'s check out if the lib properly handles a commented </methodResponse> tag... --> |
|
309
|
|
|
<methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member> |
|
310
|
|
|
<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow |
|
311
|
|
|
|
|
312
|
|
|
|
|
313
|
|
|
and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse> |
|
314
|
|
|
<script type="text\javascript">document.write(\'Hello, my name is added nag, I\\\'m happy to serve your content for free\');</script> |
|
315
|
|
|
'; |
|
316
|
|
|
$r = $s->parseResponse($f); |
|
317
|
|
|
$v = $r->value(); |
|
318
|
|
|
$s = $v->structmem('content'); |
|
319
|
|
|
$this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s->scalarval()); |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
public function testStringBug() |
|
323
|
|
|
{ |
|
324
|
|
|
$s = $this->newMsg('dummy'); |
|
325
|
|
|
$f = '<?xml version="1.0"?> |
|
326
|
|
|
<!-- $Id --> |
|
327
|
|
|
<!-- found by [email protected], amongst others |
|
328
|
|
|
covers what happens when there\'s character data after </string> |
|
329
|
|
|
and before </value> --> |
|
330
|
|
|
<methodResponse> |
|
331
|
|
|
<params> |
|
332
|
|
|
<param> |
|
333
|
|
|
<value> |
|
334
|
|
|
<struct> |
|
335
|
|
|
<member> |
|
336
|
|
|
<name>success</name> |
|
337
|
|
|
<value> |
|
338
|
|
|
<boolean>1</boolean> |
|
339
|
|
|
</value> |
|
340
|
|
|
</member> |
|
341
|
|
|
<member> |
|
342
|
|
|
<name>sessionID</name> |
|
343
|
|
|
<value> |
|
344
|
|
|
<string>S300510007I</string> |
|
345
|
|
|
</value> |
|
346
|
|
|
</member> |
|
347
|
|
|
</struct> |
|
348
|
|
|
</value> |
|
349
|
|
|
</param> |
|
350
|
|
|
</params> |
|
351
|
|
|
</methodResponse> '; |
|
352
|
|
|
$r = $s->parseResponse($f); |
|
353
|
|
|
$v = $r->value(); |
|
354
|
|
|
$s = $v->structmem('sessionID'); |
|
355
|
|
|
$this->assertEquals('S300510007I', $s->scalarval()); |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
public function testWhiteSpace() |
|
359
|
|
|
{ |
|
360
|
|
|
$s = $this->newMsg('dummy'); |
|
361
|
|
|
$f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member> |
|
362
|
|
|
<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow |
|
363
|
|
|
|
|
364
|
|
|
|
|
365
|
|
|
and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse> |
|
366
|
|
|
'; |
|
367
|
|
|
$r = $s->parseResponse($f); |
|
368
|
|
|
$v = $r->value(); |
|
369
|
|
|
$s = $v->structmem('content'); |
|
370
|
|
|
$this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s->scalarval()); |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
public function testDoubleDataInArrayTag() |
|
374
|
|
|
{ |
|
375
|
|
|
$s = $this->newMsg('dummy'); |
|
376
|
|
|
$f = '<?xml version="1.0"?><methodResponse><params><param><value><array> |
|
377
|
|
|
<data></data> |
|
378
|
|
|
<data></data> |
|
379
|
|
|
</array></value></param></params></methodResponse> |
|
380
|
|
|
'; |
|
381
|
|
|
$r = $s->parseResponse($f); |
|
382
|
|
|
$v = $r->faultCode(); |
|
383
|
|
|
$this->assertEquals(2, $v); |
|
384
|
|
|
$f = '<?xml version="1.0"?><methodResponse><params><param><value><array> |
|
385
|
|
|
<data><value>Hello world</value></data> |
|
386
|
|
|
<data></data> |
|
387
|
|
|
</array></value></param></params></methodResponse> |
|
388
|
|
|
'; |
|
389
|
|
|
$r = $s->parseResponse($f); |
|
390
|
|
|
$v = $r->faultCode(); |
|
391
|
|
|
$this->assertEquals(2, $v); |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
public function testDoubleStuffInValueTag() |
|
395
|
|
|
{ |
|
396
|
|
|
$s = $this->newMsg('dummy'); |
|
397
|
|
|
$f = '<?xml version="1.0"?><methodResponse><params><param><value> |
|
398
|
|
|
<string>hello world</string> |
|
399
|
|
|
<array><data></data></array> |
|
400
|
|
|
</value></param></params></methodResponse> |
|
401
|
|
|
'; |
|
402
|
|
|
$r = $s->parseResponse($f); |
|
403
|
|
|
$v = $r->faultCode(); |
|
404
|
|
|
$this->assertEquals(2, $v); |
|
405
|
|
|
$f = '<?xml version="1.0"?><methodResponse><params><param><value> |
|
406
|
|
|
<string>hello</string> |
|
407
|
|
|
<string>world</string> |
|
408
|
|
|
</value></param></params></methodResponse> |
|
409
|
|
|
'; |
|
410
|
|
|
$r = $s->parseResponse($f); |
|
411
|
|
|
$v = $r->faultCode(); |
|
412
|
|
|
$this->assertEquals(2, $v); |
|
413
|
|
|
$f = '<?xml version="1.0"?><methodResponse><params><param><value> |
|
414
|
|
|
<string>hello</string> |
|
415
|
|
|
<struct><member><name>hello><value>world</value></member></struct> |
|
416
|
|
|
</value></param></params></methodResponse> |
|
417
|
|
|
'; |
|
418
|
|
|
$r = $s->parseResponse($f); |
|
419
|
|
|
$v = $r->faultCode(); |
|
420
|
|
|
$this->assertEquals(2, $v); |
|
421
|
|
|
} |
|
422
|
|
|
|
|
423
|
|
|
public function testAutodecodeResponse() |
|
424
|
|
|
{ |
|
425
|
|
|
$s = $this->newMsg('dummy'); |
|
426
|
|
|
$f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member> |
|
427
|
|
|
<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow |
|
428
|
|
|
|
|
429
|
|
|
|
|
430
|
|
|
and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse> |
|
431
|
|
|
'; |
|
432
|
|
|
$r = $s->parseResponse($f, true, 'phpvals'); |
|
433
|
|
|
$v = $r->value(); |
|
434
|
|
|
$s = $v['content']; |
|
435
|
|
|
$this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s); |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
public function testNoDecodeResponse() |
|
439
|
|
|
{ |
|
440
|
|
|
$s = $this->newMsg('dummy'); |
|
441
|
|
|
$f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member> |
|
442
|
|
|
<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow |
|
443
|
|
|
|
|
444
|
|
|
|
|
445
|
|
|
and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>'; |
|
446
|
|
|
$r = $s->parseResponse($f, true, 'xml'); |
|
447
|
|
|
$v = $r->value(); |
|
448
|
|
|
$this->assertEquals($f, $v); |
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
public function testAutoCoDec() |
|
452
|
|
|
{ |
|
453
|
|
|
$data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00'); |
|
454
|
|
|
$data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1); |
|
455
|
|
|
$data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2); |
|
456
|
|
|
//$keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'); |
|
457
|
|
|
$v1 = php_xmlrpc_encode($data, array('auto_dates')); |
|
458
|
|
|
$v2 = php_xmlrpc_decode_xml($v1->serialize()); |
|
459
|
|
|
$this->assertEquals($v1, $v2); |
|
460
|
|
|
$r1 = new PhpXmlRpc\Response($v1); |
|
461
|
|
|
$r2 = php_xmlrpc_decode_xml($r1->serialize()); |
|
462
|
|
|
$r2->serialize(); // needed to set internal member payload |
|
463
|
|
|
$this->assertEquals($r1, $r2); |
|
464
|
|
|
$m1 = new PhpXmlRpc\Request('hello dolly', array($v1)); |
|
465
|
|
|
$m2 = php_xmlrpc_decode_xml($m1->serialize()); |
|
466
|
|
|
$m2->serialize(); // needed to set internal member payload |
|
467
|
|
|
$this->assertEquals($m1, $m2); |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
|
public function testUTF8Request() |
|
471
|
|
|
{ |
|
472
|
|
|
$sendstring = 'κόσμε'; // Greek word 'kosme'. NB: NOT a valid ISO8859 string! |
|
473
|
|
|
$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8'; |
|
474
|
|
|
\PhpXmlRpc\PhpXmlRpc::importGlobals(); |
|
475
|
|
|
$f = new xmlrpcval($sendstring, 'string'); |
|
476
|
|
|
$v = $f->serialize(); |
|
477
|
|
|
$this->assertEquals("<value><string>κόσμε</string></value>\n", $v); |
|
478
|
|
|
$GLOBALS['xmlrpc_internalencoding'] = 'ISO-8859-1'; |
|
479
|
|
|
\PhpXmlRpc\PhpXmlRpc::importGlobals(); |
|
480
|
|
|
} |
|
481
|
|
|
|
|
482
|
|
|
public function testUTF8Response() |
|
483
|
|
|
{ |
|
484
|
|
|
$string = chr(224) . chr(252) . chr(232); |
|
485
|
|
|
|
|
486
|
|
|
$s = $this->newMsg('dummy'); |
|
487
|
|
|
$f = "HTTP/1.1 200 OK\r\nContent-type: text/xml; charset=UTF-8\r\n\r\n" . '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member> |
|
488
|
|
|
<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>' . utf8_encode($string) . '</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse> |
|
489
|
|
|
'; |
|
490
|
|
|
$r = $s->parseResponse($f, false, 'phpvals'); |
|
491
|
|
|
$v = $r->value(); |
|
492
|
|
|
$v = $v['content']; |
|
493
|
|
|
$this->assertEquals($string, $v); |
|
494
|
|
|
|
|
495
|
|
|
$f = '<?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member> |
|
496
|
|
|
<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>' . utf8_encode($string) . '</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse> |
|
497
|
|
|
'; |
|
498
|
|
|
$r = $s->parseResponse($f, false, 'phpvals'); |
|
499
|
|
|
$v = $r->value(); |
|
500
|
|
|
$v = $v['content']; |
|
501
|
|
|
$this->assertEquals($string, $v); |
|
502
|
|
|
|
|
503
|
|
|
$r = php_xmlrpc_decode_xml($f); |
|
504
|
|
|
$v = $r->value(); |
|
|
|
|
|
|
505
|
|
|
$v = $v->structmem('content')->scalarval(); |
|
506
|
|
|
$this->assertEquals($string, $v); |
|
507
|
|
|
} |
|
508
|
|
|
|
|
509
|
|
|
public function testLatin1Response() |
|
510
|
|
|
{ |
|
511
|
|
|
$string = chr(224) . chr(252) . chr(232); |
|
512
|
|
|
|
|
513
|
|
|
$s = $this->newMsg('dummy'); |
|
514
|
|
|
$f = "HTTP/1.1 200 OK\r\nContent-type: text/xml; charset=ISO-8859-1\r\n\r\n" . '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member> |
|
515
|
|
|
<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>' . $string . '</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse> |
|
516
|
|
|
'; |
|
517
|
|
|
$r = $s->parseResponse($f, false, 'phpvals'); |
|
518
|
|
|
$v = $r->value(); |
|
519
|
|
|
$v = $v['content']; |
|
520
|
|
|
$this->assertEquals($string, $v); |
|
521
|
|
|
|
|
522
|
|
|
$f = '<?xml version="1.0" encoding="ISO-8859-1"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member> |
|
523
|
|
|
<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>' . $string . '</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse> |
|
524
|
|
|
'; |
|
525
|
|
|
$r = $s->parseResponse($f, false, 'phpvals'); |
|
526
|
|
|
$v = $r->value(); |
|
527
|
|
|
$v = $v['content']; |
|
528
|
|
|
$this->assertEquals($string, $v); |
|
529
|
|
|
|
|
530
|
|
|
$r = php_xmlrpc_decode_xml($f); |
|
531
|
|
|
$v = $r->value(); |
|
532
|
|
|
$v = $v->structmem('content')->scalarval(); |
|
533
|
|
|
$this->assertEquals($string, $v); |
|
534
|
|
|
} |
|
535
|
|
|
|
|
536
|
|
|
public function testUTF8IntString() |
|
537
|
|
|
{ |
|
538
|
|
|
$v = new xmlrpcval(100, 'int'); |
|
539
|
|
|
$s = $v->serialize('UTF-8'); |
|
540
|
|
|
$this->assertequals("<value><int>100</int></value>\n", $s); |
|
541
|
|
|
} |
|
542
|
|
|
|
|
543
|
|
|
public function testStringInt() |
|
544
|
|
|
{ |
|
545
|
|
|
$v = new xmlrpcval('hello world', 'int'); |
|
546
|
|
|
$s = $v->serialize(); |
|
547
|
|
|
$this->assertequals("<value><int>0</int></value>\n", $s); |
|
548
|
|
|
} |
|
549
|
|
|
|
|
550
|
|
|
public function testStructMemExists() |
|
551
|
|
|
{ |
|
552
|
|
|
$v = php_xmlrpc_encode(array('hello' => 'world')); |
|
553
|
|
|
$b = $v->structmemexists('hello'); |
|
|
|
|
|
|
554
|
|
|
$this->assertequals(true, $b); |
|
555
|
|
|
$b = $v->structmemexists('world'); |
|
|
|
|
|
|
556
|
|
|
$this->assertequals(false, $b); |
|
557
|
|
|
} |
|
558
|
|
|
|
|
559
|
|
|
public function testNilvalue() |
|
560
|
|
|
{ |
|
561
|
|
|
// default case: we do not accept nil values received |
|
562
|
|
|
$v = new xmlrpcval('hello', 'null'); |
|
563
|
|
|
$r = new xmlrpcresp($v); |
|
564
|
|
|
$s = $r->serialize(); |
|
565
|
|
|
$m = $this->newMsg('dummy'); |
|
566
|
|
|
$r = $m->parseresponse($s); |
|
567
|
|
|
$this->assertequals(2, $r->faultCode()); |
|
568
|
|
|
// enable reception of nil values |
|
569
|
|
|
$GLOBALS['xmlrpc_null_extension'] = true; |
|
570
|
|
|
\PhpXmlRpc\PhpXmlRpc::importGlobals(); |
|
571
|
|
|
$r = $m->parseresponse($s); |
|
572
|
|
|
$v = $r->value(); |
|
573
|
|
|
$this->assertequals('null', $v->scalartyp()); |
|
574
|
|
|
// test with the apache version: EX:NIL |
|
575
|
|
|
$GLOBALS['xmlrpc_null_apache_encoding'] = true; |
|
576
|
|
|
\PhpXmlRpc\PhpXmlRpc::importGlobals(); |
|
577
|
|
|
// serialization |
|
578
|
|
|
$v = new xmlrpcval('hello', 'null'); |
|
579
|
|
|
$s = $v->serialize(); |
|
580
|
|
|
$this->assertequals(1, preg_match('#<value><ex:nil/></value>#', $s)); |
|
581
|
|
|
// deserialization |
|
582
|
|
|
$r = new xmlrpcresp($v); |
|
583
|
|
|
$s = $r->serialize(); |
|
584
|
|
|
$r = $m->parseresponse($s); |
|
585
|
|
|
$v = $r->value(); |
|
586
|
|
|
$this->assertequals('null', $v->scalartyp()); |
|
587
|
|
|
$GLOBALS['xmlrpc_null_extension'] = false; |
|
588
|
|
|
\PhpXmlRpc\PhpXmlRpc::importGlobals(); |
|
589
|
|
|
$r = $m->parseresponse($s); |
|
590
|
|
|
$this->assertequals(2, $r->faultCode()); |
|
591
|
|
|
} |
|
592
|
|
|
|
|
593
|
|
|
public function testLocale() |
|
594
|
|
|
{ |
|
595
|
|
|
$locale = setlocale(LC_NUMERIC, 0); |
|
596
|
|
|
/// @todo on php 5.3/win setting locale to german does not seem to set decimal separator to comma... |
|
597
|
|
|
if (setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false) { |
|
598
|
|
|
$v = new xmlrpcval(1.1, 'double'); |
|
599
|
|
|
if (strpos($v->scalarval(), ',') == 1) { |
|
600
|
|
|
$r = $v->serialize(); |
|
601
|
|
|
$this->assertequals(false, strpos($r, ',')); |
|
602
|
|
|
setlocale(LC_NUMERIC, $locale); |
|
603
|
|
|
} else { |
|
604
|
|
|
setlocale(LC_NUMERIC, $locale); |
|
605
|
|
|
$this->markTestSkipped('did not find a locale which sets decimal separator to comma'); |
|
606
|
|
|
} |
|
607
|
|
|
} else { |
|
608
|
|
|
$this->markTestSkipped('did not find a locale which sets decimal separator to comma'); |
|
609
|
|
|
} |
|
610
|
|
|
} |
|
611
|
|
|
|
|
612
|
|
|
public function testArrayAccess() |
|
613
|
|
|
{ |
|
614
|
|
|
$v1 = new xmlrpcval(array(new xmlrpcval('one'), new xmlrpcval('two')), 'array'); |
|
615
|
|
|
$this->assertequals(1, count($v1)); |
|
616
|
|
|
$out = array('me' => array(), 'mytype' => 2, '_php_class' => null); |
|
617
|
|
|
|
|
618
|
|
|
foreach($v1 as $key => $val) |
|
619
|
|
|
{ |
|
620
|
|
|
$this->assertArrayHasKey($key, $out); |
|
621
|
|
|
$expected = $out[$key]; |
|
622
|
|
|
if (gettype($expected) == 'array') { |
|
623
|
|
|
$this->assertequals('array', gettype($val)); |
|
624
|
|
|
} else { |
|
625
|
|
|
$this->assertequals($expected, $val); |
|
626
|
|
|
} |
|
627
|
|
|
} |
|
628
|
|
|
|
|
629
|
|
|
$v2 = new \PhpXmlRpc\Value(array(new \PhpXmlRpc\Value('one'), new \PhpXmlRpc\Value('two')), 'array'); |
|
630
|
|
|
$this->assertequals(2, count($v2)); |
|
631
|
|
|
$out = array(array('key' => 0, 'value' => 'object'), array('key' => 1, 'value' => 'object')); |
|
632
|
|
|
$i = 0; |
|
633
|
|
|
foreach($v2 as $key => $val) |
|
634
|
|
|
{ |
|
635
|
|
|
$expected = $out[$i]; |
|
636
|
|
|
$this->assertequals($expected['key'], $key); |
|
637
|
|
|
$this->assertequals($expected['value'], gettype($val)); |
|
638
|
|
|
$i++; |
|
639
|
|
|
} |
|
640
|
|
|
} |
|
641
|
|
|
|
|
642
|
|
|
function testBigXML() |
|
|
|
|
|
|
643
|
|
|
{ |
|
644
|
|
|
// nb: make sure that the serialized xml corresponding to this is > 10MB in size |
|
645
|
|
|
$data = array(); |
|
646
|
|
|
for ($i = 0; $i < 500000; $i++ ) { |
|
647
|
|
|
$data[] = 'hello world'; |
|
648
|
|
|
} |
|
649
|
|
|
|
|
650
|
|
|
$encoder = new \PhpXmlRpc\Encoder(); |
|
651
|
|
|
$val = $encoder->encode($data); |
|
652
|
|
|
$req = new \PhpXmlRpc\Request('test', array($val)); |
|
653
|
|
|
$xml = $req->serialize(); |
|
654
|
|
|
$parser = new \PhpXmlRpc\Helper\XMLParser(); |
|
655
|
|
|
$parser->parse($xml); |
|
656
|
|
|
|
|
657
|
|
|
$this->assertequals(0, $parser->_xh['isf']); |
|
658
|
|
|
} |
|
659
|
|
|
} |
|
660
|
|
|
|
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.