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 = new xmlrpc_client('/NOTEXIST.php', $this->args['HTTPSERVER'], 80); |
18
|
|
|
$this->client->setDebug($this->args['DEBUG']); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function test404() |
22
|
|
|
{ |
23
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
24
|
|
|
new xmlrpcval('hello', 'string'), |
25
|
|
|
)); |
26
|
|
|
$r = $this->client->send($m, 5); |
27
|
|
|
$this->assertEquals(5, $r->faultCode()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function test404Interop() |
31
|
|
|
{ |
32
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
33
|
|
|
new xmlrpcval('hello', 'string'), |
34
|
|
|
)); |
35
|
|
|
$orig = \PhpXmlRpc\PhpXmlRpc::$xmlrpcerr; |
36
|
|
|
\PhpXmlRpc\PhpXmlRpc::useInteropFaults(); |
37
|
|
|
$r = $this->client->send($m, 5); |
38
|
|
|
$this->assertEquals(-32300, $r->faultCode()); |
39
|
|
|
\PhpXmlRpc\PhpXmlRpc::$xmlrpcerr = $orig; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testUnsupportedAuth() |
43
|
|
|
{ |
44
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
45
|
|
|
new xmlrpcval('hello', 'string'), |
46
|
|
|
)); |
47
|
|
|
$this->client->setOption(\PhpXmlRpc\Client::OPT_USERNAME, 'user'); |
48
|
|
|
$this->client->setOption(\PhpXmlRpc\Client::OPT_AUTH_TYPE, 2); |
49
|
|
|
$this->client->setOption(\PhpXmlRpc\Client::OPT_USE_CURL, \PhpXmlRpc\Client::USE_CURL_NEVER); |
50
|
|
|
$r = $this->client->send($m); |
51
|
|
|
$this->assertEquals(\PhpXmlRpc\PhpXmlRpc::$xmlrpcerr['unsupported_option'], $r->faultCode()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testSrvNotFound() |
55
|
|
|
{ |
56
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
57
|
|
|
new xmlrpcval('hello', 'string'), |
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
|
|
|
$r = $this->client->send($m, 5); |
65
|
|
|
// make sure there's no freaking catchall DNS in effect |
66
|
|
|
$this->assertEquals(5, $r->faultCode()); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testCurlKAErr() |
71
|
|
|
{ |
72
|
|
|
if (!function_exists('curl_init')) { |
73
|
|
|
$this->markTestSkipped('CURL missing: cannot test curl keepalive errors'); |
74
|
|
|
|
75
|
|
|
return; |
76
|
|
|
} |
77
|
|
|
$m = new xmlrpcmsg('examples.stringecho', array( |
78
|
|
|
new xmlrpcval('hello', 'string'), |
79
|
|
|
)); |
80
|
|
|
// test 2 calls w. keepalive: 1st time connection ko, second time ok |
81
|
|
|
$this->client->server .= 'XXX'; |
82
|
|
|
$this->client->keepalive = true; |
|
|
|
|
83
|
|
|
$r = $this->client->send($m, 5, 'http11'); |
84
|
|
|
// in case we have a "universal dns resolver" getting in the way, we might get a 302 instead of a 404 |
85
|
|
|
$this->assertTrue($r->faultCode() === 8 || $r->faultCode() == 5); |
86
|
|
|
|
87
|
|
|
// now test a successful connection |
88
|
|
|
$server = explode(':', $this->args['HTTPSERVER']); |
89
|
|
|
if (count($server) > 1) { |
90
|
|
|
$this->client->port = $server[1]; |
|
|
|
|
91
|
|
|
} |
92
|
|
|
$this->client->server = $server[0]; |
93
|
|
|
$this->client->path = $this->args['HTTPURI']; |
94
|
|
|
$this->client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId); |
95
|
|
|
$r = $this->client->send($m, 5, 'http11'); |
96
|
|
|
$this->assertEquals(0, $r->faultCode()); |
97
|
|
|
$ro = $r->value(); |
98
|
|
|
is_object($ro) && $this->assertEquals('hello', $ro->scalarVal()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testgetUrl() |
102
|
|
|
{ |
103
|
|
|
$m = $this->client->getUrl(PHP_URL_SCHEME); |
104
|
|
|
$this->assertEquals($m, $this->client->method); |
105
|
|
|
$h = $this->client->getUrl(PHP_URL_HOST); |
106
|
|
|
$this->assertEquals($h, $this->client->server); |
107
|
|
|
$p = $this->client->getUrl(PHP_URL_PORT); |
108
|
|
|
$this->assertEquals($p, $this->client->port); |
109
|
|
|
$p = $this->client->getUrl(PHP_URL_PATH); |
110
|
|
|
$this->assertEquals($p, $this->client->path); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|