You are here

public function XmlRpcExampleTest::testXmlrpcExampleBasic in xmlrpc 8

Perform several calls to the XML-RPC interface to test the services.

File

xmlrpc_example/src/Tests/XmlRpcExampleTest.php, line 43

Class

XmlRpcExampleTest
Test case for testing the xmlrpc_example module.

Namespace

Drupal\xmlrpc_example\Tests

Code

public function testXmlrpcExampleBasic() {
  $this->xmlRpcUrl = $this
    ->getEndpoint();

  // Unit test functionality.
  $result = xmlrpc($this->xmlRpcUrl, [
    'xmlrpc_example.add' => [
      3,
      4,
    ],
  ]);
  $this
    ->assertEqual($result, 7, 'Successfully added 3+4 = 7');
  $result = xmlrpc($this->xmlRpcUrl, [
    'xmlrpc_example.subtract' => [
      4,
      3,
    ],
  ]);
  $this
    ->assertEqual($result, 1, 'Successfully subtracted 4-3 = 1');

  // Make a multicall request.
  $options = [
    'xmlrpc_example.add' => [
      5,
      2,
    ],
    'xmlrpc_example.subtract' => [
      5,
      2,
    ],
  ];
  $expected = [
    7,
    3,
  ];
  $result = xmlrpc($this->xmlRpcUrl, $options);
  $this
    ->assertEqual($result, $expected, 'Successfully called multicall request');

  // Verify default limits.
  $result = xmlrpc($this->xmlRpcUrl, [
    'xmlrpc_example.subtract' => [
      3,
      4,
    ],
  ]);
  $this
    ->assertEqual(xmlrpc_errno(), 10002, 'Results below minimum return custom error: 10002');
  $result = xmlrpc($this->xmlRpcUrl, [
    'xmlrpc_example.add' => [
      7,
      4,
    ],
  ]);
  $this
    ->assertEqual(xmlrpc_errno(), 10001, 'Results beyond maximum return custom error: 10001');
}