View source
<?php
namespace Drupal\xmlrpc\Tests;
use GuzzleHttp\Exception\ClientException;
class XmlRpcBasicTest extends XmlRpcTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'xmlrpc',
];
public function testListMethods() {
$minimum = [
'system.multicall',
'system.methodSignature',
'system.getCapabilities',
'system.listMethods',
'system.methodHelp',
];
$methods = $this
->xmlRpcGet([
'system.listMethods' => [],
]);
$count = 0;
foreach ((array) $methods as $method) {
if (in_array($method, $minimum)) {
$count++;
}
}
$this
->assertEqual($count, count($minimum), 'system.listMethods returned at least the minimum listing');
}
public function testMethodSignature() {
$signature = $this
->xmlRpcGet([
'system.methodSignature' => [
'system.listMethods',
],
]);
$this
->assert(is_array($signature) && !empty($signature) && is_array($signature[0]), 'system.methodSignature returns an array of signature arrays.');
}
public function testInvalidMessageParsing() {
module_load_include('inc', 'xmlrpc');
$invalid_messages = [
[
'message' => xmlrpc_message(''),
'assertion' => 'Empty message correctly rejected during parsing.',
],
[
'message' => xmlrpc_message('<?xml version="1.0" encoding="ISO-8859-1"?>'),
'assertion' => 'Empty message with XML declaration correctly rejected during parsing.',
],
[
'message' => xmlrpc_message('<?xml version="1.0"?><params><param><value><string>value</string></value></param></params>'),
'assertion' => 'Non-empty message without a valid message type is rejected during parsing.',
],
[
'message' => xmlrpc_message('<methodResponse><params><param><value><string>value</string></value></param></methodResponse>'),
'assertion' => 'Non-empty malformed message is rejected during parsing.',
],
];
foreach ($invalid_messages as $assertion) {
$this
->assertFalse(xmlrpc_message_parse($assertion['message']), $assertion['assertion']);
}
}
public function testAcceptHeaders() {
$request_header_sets = [
'implicit' => [],
'text/xml' => [
'Accept' => 'text/xml',
],
'application/xml' => [
'Accept' => 'application/xml',
],
];
foreach ($request_header_sets as $accept => $headers) {
try {
$methods = $this
->xmlRpcGet([
'system.listMethods' => [],
], $headers);
$this
->assertTrue(is_array($methods), strtr('@accept accept header is accepted', [
'@accept' => $accept,
]));
} catch (ClientException $e) {
$this
->fail($e);
}
}
}
public function testInvalidServer() {
$invalid_endpoint = 'http://example.invalid/xmlrpc';
$result = xmlrpc($invalid_endpoint, [
'system.listMethods' => [],
]);
$this
->verboseResult($result);
$this
->assertFalse($result, "Calling an unknown host returns an error condition");
$this
->assertEqual(-32300, xmlrpc_errno(), "Calling an unknown host is reported as a transport error.");
$message = xmlrpc_error_msg();
$this
->assertFalse(empty($message), "Calling an unknown host returns a meaningful error message.");
}
}