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