1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
include_once __DIR__ . '/ServerAwareTestCase.php'; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Tests involving the Client class (and mostly no server). |
7
|
|
|
*/ |
8
|
|
|
class ClientTest extends PhpXmlRpc_ServerAwareTestCase |
9
|
|
|
{ |
10
|
|
|
/** @var xmlrpc_client $client */ |
11
|
|
|
public $client = null; |
12
|
|
|
|
13
|
|
|
public function set_up() |
14
|
|
|
{ |
15
|
|
|
parent::set_up(); |
16
|
|
|
|
17
|
|
|
$this->client = $this->getClient(); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function test404() |
21
|
|
|
{ |
22
|
|
|
$this->client->path = '/NOTEXIST.php'; |
23
|
|
|
|
24
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
25
|
|
|
new xmlrpcval('hello', 'string'), |
26
|
|
|
)); |
27
|
|
|
$r = $this->client->send($m, 5); |
28
|
|
|
$this->assertEquals(5, $r->faultCode()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function test404Interop() |
32
|
|
|
{ |
33
|
|
|
$this->client->path = '/NOTEXIST.php'; |
34
|
|
|
|
35
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
36
|
|
|
new xmlrpcval('hello', 'string'), |
37
|
|
|
)); |
38
|
|
|
$orig = \PhpXmlRpc\PhpXmlRpc::$xmlrpcerr; |
39
|
|
|
\PhpXmlRpc\PhpXmlRpc::useInteropFaults(); |
40
|
|
|
$r = $this->client->send($m, 5); |
41
|
|
|
$this->assertEquals(-32300, $r->faultCode()); |
42
|
|
|
\PhpXmlRpc\PhpXmlRpc::$xmlrpcerr = $orig; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testUnsupportedAuth() |
46
|
|
|
{ |
47
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
48
|
|
|
new xmlrpcval('hello', 'string'), |
49
|
|
|
)); |
50
|
|
|
$this->client->setOption(\PhpXmlRpc\Client::OPT_USERNAME, 'user'); |
51
|
|
|
$this->client->setOption(\PhpXmlRpc\Client::OPT_AUTH_TYPE, 2); |
52
|
|
|
$this->client->setOption(\PhpXmlRpc\Client::OPT_USE_CURL, \PhpXmlRpc\Client::USE_CURL_NEVER); |
53
|
|
|
$r = $this->client->send($m); |
54
|
|
|
$this->assertEquals(\PhpXmlRpc\PhpXmlRpc::$xmlrpcerr['unsupported_option'], $r->faultCode()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testSrvNotFound() |
58
|
|
|
{ |
59
|
|
|
$this->client->server .= 'XXX'; |
60
|
|
|
$dnsinfo = @dns_get_record($this->client->server); |
61
|
|
|
if ($dnsinfo) { |
62
|
|
|
$this->markTestSkipped('Seems like there is a catchall DNS in effect: host ' . $this->client->server . ' found'); |
63
|
|
|
} else { |
64
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
65
|
|
|
new xmlrpcval('hello', 'string'), |
66
|
|
|
)); |
67
|
|
|
$r = $this->client->send($m, 5); |
68
|
|
|
// make sure there's no freaking catchall DNS in effect |
69
|
|
|
$this->assertEquals(5, $r->faultCode()); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testCurlKAErr() |
74
|
|
|
{ |
75
|
|
|
if (!function_exists('curl_init')) { |
76
|
|
|
$this->markTestSkipped('CURL missing: cannot test curl keepalive errors'); |
77
|
|
|
|
78
|
|
|
return; |
79
|
|
|
} |
80
|
|
|
$m = new xmlrpcmsg('examples.stringecho', array( |
81
|
|
|
new xmlrpcval('hello', 'string'), |
82
|
|
|
)); |
83
|
|
|
// test 2 calls w. keepalive: 1st time connection ko, second time ok |
84
|
|
|
$this->client->server .= 'XXX'; |
85
|
|
|
$this->client->keepalive = true; |
|
|
|
|
86
|
|
|
$r = $this->client->send($m, 5, 'http11'); |
87
|
|
|
// in case we have a "universal dns resolver" getting in the way, we might get a 302 instead of a 404 |
88
|
|
|
$this->assertTrue($r->faultCode() === 8 || $r->faultCode() == 5); |
89
|
|
|
|
90
|
|
|
// now test a successful connection |
91
|
|
|
$server = explode(':', $this->args['HTTPSERVER']); |
92
|
|
|
if (count($server) > 1) { |
93
|
|
|
$this->client->port = $server[1]; |
|
|
|
|
94
|
|
|
} |
95
|
|
|
$this->client->server = $server[0]; |
96
|
|
|
//$this->client->path = $this->args['HTTPURI']; |
97
|
|
|
//$this->client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId); |
98
|
|
|
$r = $this->client->send($m, 5, 'http11'); |
99
|
|
|
$this->assertEquals(0, $r->faultCode()); |
100
|
|
|
$ro = $r->value(); |
101
|
|
|
is_object($ro) && $this->assertEquals('hello', $ro->scalarVal()); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @dataProvider getAvailableUseCurlOptions |
106
|
|
|
*/ |
107
|
|
|
public function testCustomHeaders($curlOpt) |
108
|
|
|
{ |
109
|
|
|
$this->client->setOption(\PhpXmlRpc\Client::OPT_USE_CURL, $curlOpt); |
110
|
|
|
$this->client->setOption(\PhpXmlRpc\Client::OPT_EXTRA_HEADERS, array('X-PXR-Test: yes')); |
111
|
|
|
$r = new \PhpXmlRpc\Request('tests.getallheaders'); |
112
|
|
|
$r = $this->client->send($r); |
113
|
|
|
$this->assertEquals(0, $r->faultCode()); |
114
|
|
|
$ro = $r->value(); |
115
|
|
|
$this->assertArrayHasKey('X-Pxr-Test', $ro->scalarVal(), "Testing with curl mode: $curlOpt"); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function getAvailableUseCurlOptions() |
119
|
|
|
{ |
120
|
|
|
$opts = array(\PhpXmlRpc\Client::USE_CURL_NEVER); |
121
|
|
|
if (function_exists('curl_init')) |
122
|
|
|
{ |
123
|
|
|
$opts[] = \PhpXmlRpc\Client::USE_CURL_ALWAYS; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return array($opts); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function testgetUrl() |
130
|
|
|
{ |
131
|
|
|
$m = $this->client->getUrl(PHP_URL_SCHEME); |
132
|
|
|
$this->assertEquals($m, $this->client->method); |
133
|
|
|
$h = $this->client->getUrl(PHP_URL_HOST); |
134
|
|
|
$this->assertEquals($h, $this->client->server); |
135
|
|
|
$p = $this->client->getUrl(PHP_URL_PORT); |
136
|
|
|
$this->assertEquals($p, $this->client->port); |
137
|
|
|
$p = $this->client->getUrl(PHP_URL_PATH); |
138
|
|
|
$this->assertEquals($p, $this->client->path); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.