Issues (323)

tests/04ParsingTest.php (37 issues)

1
<?php
2
3
include_once __DIR__ . '/LoggerAwareTestCase.php';
4
5
use \PhpXmlRpc\Request;
0 ignored issues
show
The type \PhpXmlRpc\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
/**
8
 * Tests involving xml parsing.
9
 *
10
 * @todo some tests are here even though they logically belong elsewhere...
11
 */
12
class ParsingTest extends PhpXmlRpc_LoggerAwareTestCase
13
{
14
    protected function newRequest($methodName, $params = array())
15
    {
16
        $msg = new xmlrpcmsg($methodName, $params);
17
        $msg->setDebug($this->args['DEBUG']);
18
        return $msg;
19
    }
20
21
    public function testValidNumbers()
22
    {
23
        $m = $this->newRequest('dummy');
24
        $fp =
25
            '<?xml version="1.0"?>
26
<methodResponse>
27
<params>
28
<param>
29
<value>
30
<struct>
31
<member><name>integer1</name><value><int>01</int></value></member>
32
<member><name>integer2</name><value><int>+1</int></value></member>
33
<member><name>integer3</name><value><i4>1</i4></value></member>
34
<member><name>integer4</name><value><int> 1 </int></value></member>
35
<member><name>float1</name><value><double>01.10</double></value></member>
36
<member><name>float2</name><value><double>+1.10</double></value></member>
37
<member><name>float3</name><value><double>-1.10e2</double></value></member>
38
<member><name>float4</name><value><double> -1.10e2 </double></value></member>
39
</struct>
40
</value>
41
</param>
42
</params>
43
</methodResponse>';
44
        $r = $m->parseResponse($fp);
45
        $v = $r->value();
46
        $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

46
        $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...
47
        $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

47
        $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...
48
        $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

48
        $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...
49
        $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

49
        $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...
50
        $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

50
        $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...
51
        $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

51
        $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...
52
        $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

52
        $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...
53
        $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

53
        $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...
54
        $this->assertEquals(1, $s->scalarval());
55
        $this->assertEquals(1, $t->scalarval());
56
        $this->assertEquals(1, $u->scalarval());
57
        $this->assertEquals(1, $u2->scalarval());
58
        $this->assertEquals('int', $u->scalartyp());
59
60
        $this->assertEquals(1.1, $x->scalarval());
61
        $this->assertEquals(1.1, $y->scalarval());
62
        $this->assertEquals(-110.0, $z->scalarval());
63
        $this->assertEquals(-110.0, $z2->scalarval());
64
    }
65
66
    public function testBooleans()
67
    {
68
        $m = $this->newRequest('dummy');
69
        $fp =
70
            '<?xml version="1.0"?>
71
<methodResponse><params><param><value><struct>
72
<member><name>b1</name>
73
<value><boolean>1</boolean></value></member>
74
<member><name>b2</name>
75
<value><boolean> 1 </boolean></value></member>
76
<member><name>b3</name>
77
<value><boolean>tRuE</boolean></value></member>
78
<member><name>b4</name>
79
<value><boolean>0</boolean></value></member>
80
<member><name>b5</name>
81
<value><boolean> 0 </boolean></value></member>
82
<member><name>b6</name>
83
<value><boolean>fAlSe</boolean></value></member>
84
</struct></value></param></params></methodResponse>';
85
        $r = $m->parseResponse($fp);
86
        $v = $r->value();
87
88
        $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

88
        $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...
89
        $t = $v->structmem('b2');
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
        $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...
The assignment to $t is dead and can be removed.
Loading history...
90
        $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

90
        $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...
91
        $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

91
        $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...
92
        $y = $v->structmem('b5');
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

92
        $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...
The assignment to $y is dead and can be removed.
Loading history...
93
        $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

93
        $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...
94
95
        /// @todo this test fails with phpunit, but the same code works elsewhere! It makes string-int casting stricter??
96
        $this->assertEquals(true, $s->scalarval());
97
        //$this->assertEquals(true, $t->scalarval());
98
        $this->assertEquals(true, $u->scalarval());
99
        $this->assertEquals(false, $x->scalarval());
100
        //$this->assertEquals(false, $y->scalarval());
101
        $this->assertEquals(false, $z->scalarval());
102
    }
103
104
    public function testI8()
105
    {
106
        if (PHP_INT_SIZE == 4 ) {
107
            $this->markTestSkipped('Can not test i8 as php is compiled in 32 bit mode');
108
        }
109
110
        $m = $this->newRequest('dummy');
111
        $fp =
112
            '<?xml version="1.0"?>
113
<methodResponse>
114
<params>
115
<param>
116
<value>
117
<struct>
118
<member>
119
<name>integer1</name>
120
<value><i8>1</i8></value>
121
</member>
122
<member>
123
<name>integer2</name>
124
<value><ex:i8>1</ex:i8></value>
125
</member>
126
</struct>
127
</value>
128
</param>
129
</params>
130
</methodResponse>';
131
        $r = $m->parseResponse($fp);
132
        $v = $r->value();
133
        $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

133
        $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...
134
        $this->assertEquals(1, $s->scalarval());
135
        $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

135
        $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...
136
        $this->assertEquals(1, $s->scalarval());
137
        $this->assertEquals('i8', $s->scalartyp());
138
    }
139
140
    // struct with value before name, with no name, with no value, etc...
141
    public function testQuirkyStruct()
142
    {
143
        $m = $this->newRequest('dummy');
144
        $fp =
145
            '<?xml version="1.0"?>
146
<methodResponse>
147
<params>
148
<param>
149
<value>
150
<struct>
151
<member>
152
<value><int>1</int></value>
153
<name>Gollum</name>
154
</member>
155
<member>
156
<name>Bilbo</name>
157
</member>
158
<member>
159
<value><int>9</int></value>
160
</member>
161
<member>
162
<value><int>1</int></value>
163
</member>
164
</struct>
165
</value>
166
</param>
167
</params>
168
</methodResponse>';
169
        $r = $m->parseResponse($fp);
170
        $v = $r->value();
171
        $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

171
        $this->assertEquals(2, count(/** @scrutinizer ignore-type */ $v));
Loading history...
172
        $s = $v['Gollum'];
173
        $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

173
        $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...
174
        $s = $v[''];
175
        $this->assertEquals(1, $s->scalarval());
176
    }
177
178
    public function testUnicodeInMemberName()
179
    {
180
        $str = "G" . chr(252) . "nter, El" . chr(232) . "ne";
181
        $v = array($str => new xmlrpcval(1));
182
        $r = new xmlrpcresp(new xmlrpcval($v, 'struct'));
183
        $r = $r->serialize();
184
        $m = $this->newRequest('dummy');
185
        $r = $m->parseResponse($r);
186
        $v = $r->value();
187
        $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

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

359
        $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...
360
        $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s->scalarval());
361
    }
362
363
    public function testStringBug()
364
    {
365
        $s = $this->newRequest('dummy');
366
        $f = '<?xml version="1.0"?>
367
<!-- found by [email protected], amongst others covers what happens when there\'s character data after </string>
368
 and before </value> -->
369
<methodResponse>
370
<params>
371
<param>
372
<value>
373
<struct>
374
<member>
375
<name>success</name>
376
<value>
377
<boolean>1</boolean>
378
</value>
379
</member>
380
<member>
381
<name>sessionID</name>
382
<value>
383
<string>S300510007I</string>
384
</value>
385
</member>
386
</struct>
387
</value>
388
</param>
389
</params>
390
</methodResponse> ';
391
        $r = $s->parseResponse($f);
392
        $v = $r->value();
393
        $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

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

446
        $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...
447
        $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

447
        $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...
448
        $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

448
        $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...
449
        $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

449
        $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...
450
        $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

450
        $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...
451
    }
452
453
    public function testInvalidValuesStrictMode()
454
    {
455
        $s = $this->newRequest('dummy');
456
457
        $values = array(
458
            '<boolean>x</boolean>',
459
            '<double>x</double>',
460
            '<double>1..</double>',
461
            '<double>..1</double>',
462
            '<double>1.0.1</double>',
463
            '<int>x</int>',
464
            '<int>1.0</int>',
465
            '<dateTime.iso8601> 20011126T09:17:52</dateTime.iso8601>',
466
            '<dateTime.iso8601>20011126T09:17:52 </dateTime.iso8601>',
467
            '<base64>!</base64>'
468
        );
469
470
        $i = \PhpXmlRpc\PhpXmlRpc::$xmlrpc_reject_invalid_values;
471
        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_reject_invalid_values = true;
472
473
        foreach($values as $value) {
474
            $f = '<?xml version="1.0"?><methodResponse><params><param><value>' . $value . '</value></param></params></methodResponse> ';
475
            $r = $s->parseResponse($f);
476
            $v = $r->faultCode();
477
            $this->assertEquals(2, $v, "Testing $value");
478
        }
479
480
        /// @todo move to tear_down(), so that we reset this even in case of test failure
481
        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_reject_invalid_values = $i;
482
    }
483
484
    public function testNewlines()
485
    {
486
        $s = $this->newRequest('dummy');
487
        $f = '<?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>hello world. 2 newlines follow
489
490
491
and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
492
';
493
        $r = $s->parseResponse($f);
494
        $v = $r->value();
495
        $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

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

600
        /** @scrutinizer ignore-call */ 
601
        $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

600
        /** @scrutinizer ignore-call */ 
601
        $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...
601
        $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

601
        $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...
602
        $this->assertEquals($string, $v);
603
    }
604
605
    public function testLatin1Response()
606
    {
607
        $string = chr(224) . chr(252) . chr(232);
608
609
        $s = $this->newRequest('dummy');
610
        $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>
611
<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>
612
';
613
        $r = $s->parseResponse($f, false, 'phpvals');
614
        $v = $r->value();
615
        $v = $v['content'];
616
        $this->assertEquals($string, $v);
617
618
        $f = '<?xml version="1.0" encoding="ISO-8859-1"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
619
<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>
620
';
621
        $r = $s->parseResponse($f, false, 'phpvals');
622
        $v = $r->value();
623
        $v = $v['content'];
624
        $this->assertEquals($string, $v);
625
626
        /// @todo move to EncoderTest
627
        $r = php_xmlrpc_decode_xml($f);
628
        $v = $r->value();
629
        $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

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

695
        /** @scrutinizer ignore-deprecated */ \PhpXmlRpc\PhpXmlRpc::importGlobals();
Loading history...
696
        $r = $m->parseresponse($s);
697
        $v = $r->value();
698
        $this->assertequals('null', $v->scalartyp());
699
        // test with the apache version: EX:NIL
700
        $GLOBALS['xmlrpc_null_apache_encoding'] = true;
701
        \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

701
        /** @scrutinizer ignore-deprecated */ \PhpXmlRpc\PhpXmlRpc::importGlobals();
Loading history...
702
        // serialization
703
        $v = new xmlrpcval('hello', 'null');
704
        $s = $v->serialize();
705
        $this->assertequals(1, preg_match('#<value><ex:nil/></value>#', $s));
706
        // deserialization
707
        $r = new xmlrpcresp($v);
708
        $s = $r->serialize();
709
        $r = $m->parseresponse($s);
710
        $v = $r->value();
711
        $this->assertequals('null', $v->scalartyp());
712
        $GLOBALS['xmlrpc_null_extension'] = false;
713
        \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

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