Issues (321)

tests/04ParsingTest.php (36 issues)

1
<?php
2
3
include_once __DIR__ . '/LoggerAwareTestCase.php';
4
5
/**
6
 * Tests involving xml parsing.
7
 *
8
 * @todo some tests are here even though they logically belong elsewhere...
9
 */
10
class ParsingTest extends PhpXmlRpc_LoggerAwareTestCase
11
{
12
    protected function newRequest($methodName, $params = array())
13
    {
14
        $msg = new xmlrpcmsg($methodName, $params);
15
        $msg->setDebug($this->args['DEBUG']);
16
        return $msg;
17
    }
18
19
    public function testValidNumbers()
20
    {
21
        $m = $this->newRequest('dummy');
22
        $fp =
23
            '<?xml version="1.0"?>
24
<methodResponse>
25
<params>
26
<param>
27
<value>
28
<struct>
29
<member><name>integer1</name><value><int>01</int></value></member>
30
<member><name>integer2</name><value><int>+1</int></value></member>
31
<member><name>integer3</name><value><i4>1</i4></value></member>
32
<member><name>integer4</name><value><int> 1 </int></value></member>
33
<member><name>float1</name><value><double>01.10</double></value></member>
34
<member><name>float2</name><value><double>+1.10</double></value></member>
35
<member><name>float3</name><value><double>-1.10e2</double></value></member>
36
<member><name>float4</name><value><double> -1.10e2 </double></value></member>
37
</struct>
38
</value>
39
</param>
40
</params>
41
</methodResponse>';
42
        $r = $m->parseResponse($fp);
43
        $v = $r->value();
44
        $s = $v->structmem('integer1');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

44
        $s = /** @scrutinizer ignore-deprecated */ $v->structmem('integer1');

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.

Loading history...
45
        $t = $v->structmem('integer2');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

45
        $t = /** @scrutinizer ignore-deprecated */ $v->structmem('integer2');

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.

Loading history...
46
        $u = $v->structmem('integer3');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

46
        $u = /** @scrutinizer ignore-deprecated */ $v->structmem('integer3');

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.

Loading history...
47
        $u2 = $v->structmem('integer4');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

47
        $u2 = /** @scrutinizer ignore-deprecated */ $v->structmem('integer4');

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.

Loading history...
48
        $x = $v->structmem('float1');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

48
        $x = /** @scrutinizer ignore-deprecated */ $v->structmem('float1');

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.

Loading history...
49
        $y = $v->structmem('float2');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

49
        $y = /** @scrutinizer ignore-deprecated */ $v->structmem('float2');

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.

Loading history...
50
        $z = $v->structmem('float3');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

50
        $z = /** @scrutinizer ignore-deprecated */ $v->structmem('float3');

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.

Loading history...
51
        $z2 = $v->structmem('float4');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

51
        $z2 = /** @scrutinizer ignore-deprecated */ $v->structmem('float4');

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.

Loading history...
52
        $this->assertEquals(1, $s->scalarval());
53
        $this->assertEquals(1, $t->scalarval());
54
        $this->assertEquals(1, $u->scalarval());
55
        $this->assertEquals(1, $u2->scalarval());
56
        $this->assertEquals('int', $u->scalartyp());
57
58
        $this->assertEquals(1.1, $x->scalarval());
59
        $this->assertEquals(1.1, $y->scalarval());
60
        $this->assertEquals(-110.0, $z->scalarval());
61
        $this->assertEquals(-110.0, $z2->scalarval());
62
    }
63
64
    public function testBooleans()
65
    {
66
        $m = $this->newRequest('dummy');
67
        $fp =
68
            '<?xml version="1.0"?>
69
<methodResponse><params><param><value><struct>
70
<member><name>b1</name>
71
<value><boolean>1</boolean></value></member>
72
<member><name>b2</name>
73
<value><boolean> 1 </boolean></value></member>
74
<member><name>b3</name>
75
<value><boolean>tRuE</boolean></value></member>
76
<member><name>b4</name>
77
<value><boolean>0</boolean></value></member>
78
<member><name>b5</name>
79
<value><boolean> 0 </boolean></value></member>
80
<member><name>b6</name>
81
<value><boolean>fAlSe</boolean></value></member>
82
</struct></value></param></params></methodResponse>';
83
        $r = $m->parseResponse($fp);
84
        $v = $r->value();
85
86
        $s = $v->structmem('b1');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

86
        $s = /** @scrutinizer ignore-deprecated */ $v->structmem('b1');

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.

Loading history...
87
        $t = $v->structmem('b2');
0 ignored issues
show
The assignment to $t is dead and can be removed.
Loading history...
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

87
        $t = /** @scrutinizer ignore-deprecated */ $v->structmem('b2');

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.

Loading history...
88
        $u = $v->structmem('b3');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

88
        $u = /** @scrutinizer ignore-deprecated */ $v->structmem('b3');

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.

Loading history...
89
        $x = $v->structmem('b4');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

89
        $x = /** @scrutinizer ignore-deprecated */ $v->structmem('b4');

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.

Loading history...
90
        $y = $v->structmem('b5');
0 ignored issues
show
The assignment to $y is dead and can be removed.
Loading history...
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

90
        $y = /** @scrutinizer ignore-deprecated */ $v->structmem('b5');

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.

Loading history...
91
        $z = $v->structmem('b6');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

91
        $z = /** @scrutinizer ignore-deprecated */ $v->structmem('b6');

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.

Loading history...
92
93
        /// @todo this test fails with phpunit, but the same code works elsewhere! It makes string-int casting stricter??
94
        $this->assertEquals(true, $s->scalarval());
95
        //$this->assertEquals(true, $t->scalarval());
96
        $this->assertEquals(true, $u->scalarval());
97
        $this->assertEquals(false, $x->scalarval());
98
        //$this->assertEquals(false, $y->scalarval());
99
        $this->assertEquals(false, $z->scalarval());
100
    }
101
102
    public function testI8()
103
    {
104
        if (PHP_INT_SIZE == 4 ) {
105
            $this->markTestSkipped('Can not test i8 as php is compiled in 32 bit mode');
106
            return;
107
        }
108
109
        $m = $this->newRequest('dummy');
110
        $fp =
111
            '<?xml version="1.0"?>
112
<methodResponse>
113
<params>
114
<param>
115
<value>
116
<struct>
117
<member>
118
<name>integer1</name>
119
<value><i8>1</i8></value>
120
</member>
121
<member>
122
<name>integer2</name>
123
<value><ex:i8>1</ex:i8></value>
124
</member>
125
</struct>
126
</value>
127
</param>
128
</params>
129
</methodResponse>';
130
        $r = $m->parseResponse($fp);
131
        $v = $r->value();
132
        $s = $v->structmem('integer1');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

132
        $s = /** @scrutinizer ignore-deprecated */ $v->structmem('integer1');

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.

Loading history...
133
        $this->assertEquals(1, $s->scalarval());
134
        $s = $v->structmem('integer2');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

134
        $s = /** @scrutinizer ignore-deprecated */ $v->structmem('integer2');

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.

Loading history...
135
        $this->assertEquals(1, $s->scalarval());
136
        $this->assertEquals('i8', $s->scalartyp());
137
    }
138
139
    // struct with value before name, with no name, with no value, etc...
140
    public function testQuirkyStruct()
141
    {
142
        $m = $this->newRequest('dummy');
143
        $fp =
144
            '<?xml version="1.0"?>
145
<methodResponse>
146
<params>
147
<param>
148
<value>
149
<struct>
150
<member>
151
<value><int>1</int></value>
152
<name>Gollum</name>
153
</member>
154
<member>
155
<name>Bilbo</name>
156
</member>
157
<member>
158
<value><int>9</int></value>
159
</member>
160
<member>
161
<value><int>1</int></value>
162
</member>
163
</struct>
164
</value>
165
</param>
166
</params>
167
</methodResponse>';
168
        $r = $m->parseResponse($fp);
169
        $v = $r->value();
170
        $this->assertEquals(2, count($v));
0 ignored issues
show
It seems like $v can also be of type string; however, parameter $value of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

170
        $this->assertEquals(2, count(/** @scrutinizer ignore-type */ $v));
Loading history...
171
        $s = $v['Gollum'];
172
        $this->assertEquals(1, $s->scalarval());
0 ignored issues
show
The method scalarval() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

172
        $this->assertEquals(1, $s->/** @scrutinizer ignore-call */ scalarval());

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.

Loading history...
173
        $s = $v[''];
174
        $this->assertEquals(1, $s->scalarval());
175
    }
176
177
    public function testUnicodeInMemberName()
178
    {
179
        $str = "G" . chr(252) . "nter, El" . chr(232) . "ne";
180
        $v = array($str => new xmlrpcval(1));
181
        $r = new xmlrpcresp(new xmlrpcval($v, 'struct'));
182
        $r = $r->serialize();
183
        $m = $this->newRequest('dummy');
184
        $r = $m->parseResponse($r);
185
        $v = $r->value();
186
        $this->assertEquals(true, $v->structmemexists($str));
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMemExists() has been deprecated: use array access, e.g. isset($val[$key]) ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

186
        $this->assertEquals(true, /** @scrutinizer ignore-deprecated */ $v->structmemexists($str));

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.

Loading history...
187
    }
188
189
    public function testUnicodeInErrorString()
190
    {
191
        // the warning suppression is due to utf8_decode being deprecated in php 8.2
192
        $response = @utf8_encode(
193
            '<?xml version="1.0"?>
194
<!-- covers what happens when lib receives UTF8 chars in response text and comments -->
195
<!-- ' . chr(224) . chr(252) . chr(232) . '&#224;&#252;&#232; -->
196
<methodResponse>
197
<fault>
198
<value>
199
<struct>
200
<member>
201
<name>faultCode</name>
202
<value><int>888</int></value>
203
</member>
204
<member>
205
<name>faultString</name>
206
<value><string>' . chr(224) . chr(252) . chr(232) . '&#224;&#252;&#232;</string></value>
207
</member>
208
</struct>
209
</value>
210
</fault>
211
</methodResponse>');
212
        $m = $this->newRequest('dummy');
213
        $r = $m->parseResponse($response);
214
        $v = $r->faultString();
215
        $this->assertEquals(chr(224) . chr(252) . chr(232) . chr(224) . chr(252) . chr(232), $v);
216
    }
217
218
    public function testBrokenRequests()
219
    {
220
        $s = new xmlrpc_server();
221
222
        // omitting the 'methodName' tag: not tolerated by the lib anymore
223
        $f = '<?xml version="1.0"?>
224
<methodCall>
225
<params>
226
<value><string>system.methodHelp</string></value>
227
</params>
228
</methodCall>';
229
        $r = $s->parserequest($f);
230
        $this->assertEquals(15, $r->faultCode());
231
232
        // omitting the 'params' tag: not tolerated by the lib anymore
233
        $f = '<?xml version="1.0"?>
234
<methodCall>
235
<methodName>system.methodHelp</methodName>
236
<param>
237
<value><string>system.methodHelp</string></value>
238
</param>
239
</methodCall>';
240
        $r = $s->parserequest($f);
241
        $this->assertEquals(15, $r->faultCode());
242
243
        // omitting a 'param' tag
244
        $f = '<?xml version="1.0"?>
245
<methodCall>
246
<methodName>system.methodHelp</methodName>
247
<params>
248
<value><string>system.methodHelp</string></value>
249
</params>
250
</methodCall>';
251
        $r = $s->parserequest($f);
252
        $this->assertEquals(15, $r->faultCode());
253
254
        // omitting a 'value' tag
255
        $f = '<?xml version="1.0"?>
256
<methodCall>
257
<methodName>system.methodHelp</methodName>
258
<params>
259
<param><string>system.methodHelp</string></param>
260
</params>
261
</methodCall>';
262
        $r = $s->parserequest($f);
263
        $this->assertEquals(15, $r->faultCode());
264
    }
265
266
    public function testBrokenResponses()
267
    {
268
        $m = $this->newRequest('dummy');
269
270
        // omitting the 'params' tag: no more tolerated by the lib...
271
        $f = '<?xml version="1.0"?>
272
<methodResponse>
273
</methodResponse>';
274
        $r = $m->parseResponse($f);
275
        $this->assertEquals(2, $r->faultCode());
276
        $f = '<?xml version="1.0"?>
277
<methodResponse>
278
<param>
279
<value><string>system.methodHelp</string></value>
280
</param>
281
</methodResponse>';
282
        $r = $m->parseResponse($f);
283
        $this->assertEquals(2, $r->faultCode());
284
285
        // omitting the 'param' tag: no more tolerated by the lib...
286
        $f = '<?xml version="1.0"?>
287
<methodResponse>
288
<params>
289
</params>
290
</methodResponse>';
291
        $r = $m->parseResponse($f);
292
        $this->assertEquals(2, $r->faultCode());
293
        $f = '<?xml version="1.0"?>
294
<methodResponse>
295
<params>
296
<value><string>system.methodHelp</string></value>
297
</params>
298
</methodResponse>';
299
        $r = $m->parseResponse($f);
300
        $this->assertEquals(2, $r->faultCode());
301
302
        // omitting a 'value' tag: KO
303
        $f = '<?xml version="1.0"?>
304
<methodResponse>
305
<params>
306
<param><string>system.methodHelp</string></param>
307
</params>
308
</methodResponse>';
309
        $r = $m->parseResponse($f);
310
        $this->assertEquals(2, $r->faultCode());
311
312
        // having both 'params' and 'fault'
313
        $f = '<?xml version="1.0"?>
314
<methodResponse>
315
<params>
316
<param><value><string>system.methodHelp</string></value></param>
317
</params>
318
<fault><value><struct>
319
<member><name>faultCode</name><value><int>888</int></value></member>
320
<member><name>faultString</name><value><string>yolo</string></value></member>
321
</struct></value></fault>
322
</methodResponse>';
323
        $r = $m->parseResponse($f);
324
        $this->assertEquals(2, $r->faultCode());
325
    }
326
327
    public function testBuggyXML()
328
    {
329
        $m = $this->newRequest('dummy');
330
        $r = $m->parseResponse("<\000\000\000\au\006");
331
        $this->assertEquals(2, $r->faultCode());
332
        //$this->assertStringContainsString('XML error', $r->faultString());
333
    }
334
335
    public function testBuggyHttp()
336
    {
337
        $s = $this->newRequest('dummy');
338
        $f = 'HTTP/1.1 100 Welcome to the jungle
339
340
HTTP/1.0 200 OK
341
X-Content-Marx-Brothers: Harpo
342
        Chico and Groucho
343
Content-Length: who knows?
344
345
346
347
<?xml version="1.0"?>
348
<!-- First of all, let\'s check out if the lib properly handles a commented </methodResponse> tag... -->
349
<methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
350
<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow
351
352
353
and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
354
<script type="text\javascript">document.write(\'Hello, my name is added nag, I\\\'m happy to serve your content for free\');</script>
355
 ';
356
        $r = $s->parseResponse($f);
357
        $v = $r->value();
358
        $s = $v->structmem('content');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

358
        $s = /** @scrutinizer ignore-deprecated */ $v->structmem('content');

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.

Loading history...
359
        $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s->scalarval());
360
    }
361
362
    public function testStringBug()
363
    {
364
        $s = $this->newRequest('dummy');
365
        $f = '<?xml version="1.0"?>
366
<!-- found by [email protected], amongst others covers what happens when there\'s character data after </string>
367
 and before </value> -->
368
<methodResponse>
369
<params>
370
<param>
371
<value>
372
<struct>
373
<member>
374
<name>success</name>
375
<value>
376
<boolean>1</boolean>
377
</value>
378
</member>
379
<member>
380
<name>sessionID</name>
381
<value>
382
<string>S300510007I</string>
383
</value>
384
</member>
385
</struct>
386
</value>
387
</param>
388
</params>
389
</methodResponse> ';
390
        $r = $s->parseResponse($f);
391
        $v = $r->value();
392
        $s = $v->structmem('sessionID');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

392
        $s = /** @scrutinizer ignore-deprecated */ $v->structmem('sessionID');

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.

Loading history...
393
        $this->assertEquals('S300510007I', $s->scalarval());
394
    }
395
396
    public function testBase64()
397
    {
398
        $s = $this->newRequest('dummy');
399
        $f = '<?xml version="1.0"?><methodResponse><params><param><value><base64>
400
aGk=
401
</base64></value></param></params></methodResponse> ';
402
        $r = $s->parseResponse($f);
403
        $v = $r->value();
404
        $this->assertEquals('hi', $v->scalarval());
405
    }
406
407
    public function testInvalidValues()
408
    {
409
        $s = $this->newRequest('dummy');
410
        $f = '<?xml version="1.0"?><methodResponse><params><param><value><struct>
411
<member>
412
<name>bool</name>
413
<value><boolean>
414
yes
415
</boolean></value>
416
</member>
417
<member>
418
<name>double</name>
419
<value><double>
420
1.01
421
</double></value>
422
</member>
423
<member>
424
<name>int</name>
425
<value><int>
426
1
427
</int></value>
428
</member>
429
<member>
430
<name>date</name>
431
<value><dateTime.iso8601>
432
20011126T09:17:52
433
</dateTime.iso8601></value>
434
</member>
435
<member>
436
<name>base64</name>
437
<value><base64>
438
!
439
</base64></value>
440
</member>
441
</struct></value></param></params></methodResponse> ';
442
        $r = $s->parseResponse($f);
443
        $v = $r->value();
444
        // NB: this is the status-quo of the xml parser, rather than something we want the library to always be returning...
445
        $this->assertEquals(false, $v['bool']->scalarval());
0 ignored issues
show
The method scalarval() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

445
        $this->assertEquals(false, $v['bool']->/** @scrutinizer ignore-call */ scalarval());

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.

Loading history...
446
        $this->assertEquals("ERROR_NON_NUMERIC_FOUND", $v['double']->scalarval());
0 ignored issues
show
The method scalarval() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

446
        $this->assertEquals("ERROR_NON_NUMERIC_FOUND", $v['double']->/** @scrutinizer ignore-call */ scalarval());

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.

Loading history...
447
        $this->assertEquals("ERROR_NON_NUMERIC_FOUND", $v['int']->scalarval());
0 ignored issues
show
The method scalarval() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

447
        $this->assertEquals("ERROR_NON_NUMERIC_FOUND", $v['int']->/** @scrutinizer ignore-call */ scalarval());

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.

Loading history...
448
        $this->assertEquals("\n20011126T09:17:52\n", $v['date']->scalarval());
0 ignored issues
show
The method scalarval() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

448
        $this->assertEquals("\n20011126T09:17:52\n", $v['date']->/** @scrutinizer ignore-call */ scalarval());

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.

Loading history...
449
        $this->assertEquals("", $v['base64']->scalarval());
0 ignored issues
show
The method scalarval() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

449
        $this->assertEquals("", $v['base64']->/** @scrutinizer ignore-call */ scalarval());

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.

Loading history...
450
    }
451
452
    public function testInvalidValuesStrictMode()
453
    {
454
        $s = $this->newRequest('dummy');
455
456
        $values = array(
457
            '<boolean>x</boolean>',
458
            '<double>x</double>',
459
            '<double>1..</double>',
460
            '<double>..1</double>',
461
            '<double>1.0.1</double>',
462
            '<int>x</int>',
463
            '<int>1.0</int>',
464
            '<dateTime.iso8601> 20011126T09:17:52</dateTime.iso8601>',
465
            '<dateTime.iso8601>20011126T09:17:52 </dateTime.iso8601>',
466
            '<base64>!</base64>'
467
        );
468
469
        $i = \PhpXmlRpc\PhpXmlRpc::$xmlrpc_reject_invalid_values;
470
        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_reject_invalid_values = true;
471
472
        foreach($values as $value) {
473
            $f = '<?xml version="1.0"?><methodResponse><params><param><value>' . $value . '</value></param></params></methodResponse> ';
474
            $r = $s->parseResponse($f);
475
            $v = $r->faultCode();
476
            $this->assertEquals(2, $v, "Testing $value");
477
        }
478
479
        /// @todo move to tear_down(), so that we reset this even in case of test failure
480
        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_reject_invalid_values = $i;
481
    }
482
483
    public function testNewlines()
484
    {
485
        $s = $this->newRequest('dummy');
486
        $f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
487
<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow
488
489
490
and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
491
';
492
        $r = $s->parseResponse($f);
493
        $v = $r->value();
494
        $s = $v->structmem('content');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

494
        $s = /** @scrutinizer ignore-deprecated */ $v->structmem('content');

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.

Loading history...
495
        $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s->scalarval());
496
    }
497
498
    public function testDoubleDataInArrayTag()
499
    {
500
        $s = $this->newRequest('dummy');
501
        $f = '<?xml version="1.0"?><methodResponse><params><param><value><array>
502
<data></data>
503
<data></data>
504
</array></value></param></params></methodResponse>
505
';
506
        $r = $s->parseResponse($f);
507
        $v = $r->faultCode();
508
        $this->assertEquals(2, $v);
509
        $f = '<?xml version="1.0"?><methodResponse><params><param><value><array>
510
<data><value>Hello world</value></data>
511
<data></data>
512
</array></value></param></params></methodResponse>
513
';
514
        $r = $s->parseResponse($f);
515
        $v = $r->faultCode();
516
        $this->assertEquals(2, $v);
517
    }
518
519
    public function testDoubleStuffInValueTag()
520
    {
521
        $s = $this->newRequest('dummy');
522
        $f = '<?xml version="1.0"?><methodResponse><params><param><value>
523
<string>hello world</string>
524
<array><data></data></array>
525
</value></param></params></methodResponse>
526
';
527
        $r = $s->parseResponse($f);
528
        $v = $r->faultCode();
529
        $this->assertEquals(2, $v);
530
        $f = '<?xml version="1.0"?><methodResponse><params><param><value>
531
<string>hello</string>
532
<string>world</string>
533
</value></param></params></methodResponse>
534
';
535
        $r = $s->parseResponse($f);
536
        $v = $r->faultCode();
537
        $this->assertEquals(2, $v);
538
        $f = '<?xml version="1.0"?><methodResponse><params><param><value>
539
<string>hello</string>
540
<struct><member><name>hello><value>world</value></member></struct>
541
</value></param></params></methodResponse>
542
';
543
        $r = $s->parseResponse($f);
544
        $v = $r->faultCode();
545
        $this->assertEquals(2, $v);
546
    }
547
548
    public function testAutoDecodeResponse()
549
    {
550
        $s = $this->newRequest('dummy');
551
        $f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
552
<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 3 newlines follow
553
554
555
and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
556
';
557
        $r = $s->parseResponse($f, true, 'phpvals');
558
        $v = $r->value();
559
        $s = $v['content'];
560
        $this->assertEquals("hello world. 3 newlines follow\n\n\nand there they were.", $s);
561
    }
562
563
    public function testNoDecodeResponse()
564
    {
565
        $s = $this->newRequest('dummy');
566
        $f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
567
<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 3 newlines follow
568
569
570
and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>';
571
        $r = $s->parseResponse($f, true, 'xml');
572
        $v = $r->value();
573
        $this->assertEquals($f, $v);
574
    }
575
576
    public function testUTF8Response()
577
    {
578
        $string = chr(224) . chr(252) . chr(232);
579
580
        $s = $this->newRequest('dummy');
581
        $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>
582
<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>
583
';
584
        $r = $s->parseResponse($f, false, 'phpvals');
585
        $v = $r->value();
586
        $v = $v['content'];
587
        $this->assertEquals($string, $v);
588
589
        $f = '<?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
590
<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>
591
';
592
        $r = $s->parseResponse($f, false, 'phpvals');
593
        $v = $r->value();
594
        $v = $v['content'];
595
        $this->assertEquals($string, $v);
596
597
        /// @todo move to EncoderTest
598
        $r = php_xmlrpc_decode_xml($f);
599
        $v = $r->value();
0 ignored issues
show
The method value() does not exist on PhpXmlRpc\Value. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

599
        /** @scrutinizer ignore-call */ 
600
        $v = $r->value();

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.

Loading history...
The method value() does not exist on PhpXmlRpc\Request. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

599
        /** @scrutinizer ignore-call */ 
600
        $v = $r->value();

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.

Loading history...
600
        $v = $v->structmem('content')->scalarval();
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

600
        $v = /** @scrutinizer ignore-deprecated */ $v->structmem('content')->scalarval();

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.

Loading history...
601
        $this->assertEquals($string, $v);
602
    }
603
604
    public function testLatin1Response()
605
    {
606
        $string = chr(224) . chr(252) . chr(232);
607
608
        $s = $this->newRequest('dummy');
609
        $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>
610
<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>
611
';
612
        $r = $s->parseResponse($f, false, 'phpvals');
613
        $v = $r->value();
614
        $v = $v['content'];
615
        $this->assertEquals($string, $v);
616
617
        $f = '<?xml version="1.0" encoding="ISO-8859-1"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
618
<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>
619
';
620
        $r = $s->parseResponse($f, false, 'phpvals');
621
        $v = $r->value();
622
        $v = $v['content'];
623
        $this->assertEquals($string, $v);
624
625
        /// @todo move to EncoderTest
626
        $r = php_xmlrpc_decode_xml($f);
627
        $v = $r->value();
628
        $v = $v->structmem('content')->scalarval();
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structMem() has been deprecated: use array access, e.g. $val[$key] ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

628
        $v = /** @scrutinizer ignore-deprecated */ $v->structmem('content')->scalarval();

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.

Loading history...
629
        $this->assertEquals($string, $v);
630
    }
631
632
    public function testDatetimeAsObject()
633
    {
634
        $s = $this->newRequest('dummy');
635
        $f = '<?xml version="1.0"?>
636
<methodResponse><params><param><value>
637
<dateTime.iso8601>20011126T09:17:52</dateTime.iso8601>
638
</value></param></params></methodResponse>';
639
640
        $o = \PhpXmlRpc\PhpXmlRpc::$xmlrpc_return_datetimes;
641
        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_return_datetimes = true;
642
643
        $r = $s->parseResponse($f);
644
        $v = $r->value();
645
        $this->assertInstanceOf('\DateTime', $v->scalarval());
646
647
        /// @todo move to tear_down(), so that we reset this even in case of test failure
648
        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_return_datetimes = $o;
649
    }
650
651
    public function testCustomDatetimeFormat()
652
    {
653
        $s = $this->newRequest('dummy');
654
        $f = '<?xml version="1.0"?>
655
<methodResponse><params><param><value>
656
<dateTime.iso8601>20011126T09:17:52+01:00</dateTime.iso8601>
657
</value></param></params></methodResponse>';
658
659
        $o = \PhpXmlRpc\PhpXmlRpc::$xmlrpc_return_datetimes;
660
        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_return_datetimes = true;
661
        $i = \PhpXmlRpc\PhpXmlRpc::$xmlrpc_reject_invalid_values;
662
        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_reject_invalid_values = true;
663
664
        $r = $s->parseResponse($f);
665
        $v = $r->faultCode();
666
        $this->assertNotEquals(0, $v);
667
668
        $d = \PhpXmlRpc\PhpXmlRpc::$xmlrpc_datetime_format;
669
        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_datetime_format = '/^([0-9]{4})(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-4]):([0-5][0-9]):([0-5][0-9]|60)(Z|[+-][0-9]{2}(:?[0-9]{2})?)?$/';
670
671
        $r = $s->parseResponse($f);
672
        $v = $r->value();
673
        $this->assertInstanceOf('\DateTime', $v->scalarval());
674
675
        /// @todo move to tear_down(), so that we reset these even in case of test failure
676
        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_return_datetimes = $o;
677
        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_reject_invalid_values = $i;
678
        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_datetime_format = $d;
679
    }
680
681
    /// @todo can we change this test to purely using the Value class ?
682
    /// @todo move test to its own class
683
    public function testNilSupport()
684
    {
685
        // default case: we do not accept nil values received
686
        $v = new xmlrpcval('hello', 'null');
687
        $r = new xmlrpcresp($v);
688
        $s = $r->serialize();
689
        $m = $this->newRequest('dummy');
690
        $r = $m->parseresponse($s);
691
        $this->assertequals(2, $r->faultCode());
692
        // enable reception of nil values
693
        $GLOBALS['xmlrpc_null_extension'] = true;
694
        \PhpXmlRpc\PhpXmlRpc::importGlobals();
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\PhpXmlRpc::importGlobals() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

694
        /** @scrutinizer ignore-deprecated */ \PhpXmlRpc\PhpXmlRpc::importGlobals();
Loading history...
695
        $r = $m->parseresponse($s);
696
        $v = $r->value();
697
        $this->assertequals('null', $v->scalartyp());
698
        // test with the apache version: EX:NIL
699
        $GLOBALS['xmlrpc_null_apache_encoding'] = true;
700
        \PhpXmlRpc\PhpXmlRpc::importGlobals();
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\PhpXmlRpc::importGlobals() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

700
        /** @scrutinizer ignore-deprecated */ \PhpXmlRpc\PhpXmlRpc::importGlobals();
Loading history...
701
        // serialization
702
        $v = new xmlrpcval('hello', 'null');
703
        $s = $v->serialize();
704
        $this->assertequals(1, preg_match('#<value><ex:nil/></value>#', $s));
705
        // deserialization
706
        $r = new xmlrpcresp($v);
707
        $s = $r->serialize();
708
        $r = $m->parseresponse($s);
709
        $v = $r->value();
710
        $this->assertequals('null', $v->scalartyp());
711
        $GLOBALS['xmlrpc_null_extension'] = false;
712
        \PhpXmlRpc\PhpXmlRpc::importGlobals();
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\PhpXmlRpc::importGlobals() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

712
        /** @scrutinizer ignore-deprecated */ \PhpXmlRpc\PhpXmlRpc::importGlobals();
Loading history...
713
        $r = $m->parseresponse($s);
714
        $this->assertequals(2, $r->faultCode());
715
    }
716
717
    public function testXXE()
718
    {
719
        $xml = '<?xml version="1.0" encoding="UTF-8"?>
720
<!DOCTYPE foo [
721
    <!ENTITY xxe SYSTEM "https://www.google.com/favicon.ico">
722
]>
723
<methodResponse>
724
    <params>
725
        <param>
726
            <value><string>&xxe;</string></value>
727
        </param>
728
    </params>
729
</methodResponse>
730
';
731
        $req = new \PhpXmlRpc\Request('hi');
732
        $resp = $req->parseResponse($xml, true);
733
        $val = $resp->value();
734
        if (version_compare(PHP_VERSION, '5.6.0', '>=')) {
735
            $this->assertequals('', $val->scalarVal());
736
        } else {
737
            $this->assertequals('&xxe;', $val->scalarVal());
738
        }
739
    }
740
}
741