You are here

public function XmlRpcExampleTest::testXmlrpcExampleServer in xmlrpc 8

Perform several XML-RPC requests with different server settings.

File

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

Class

XmlRpcExampleTest
Test case for testing the xmlrpc_example module.

Namespace

Drupal\xmlrpc_example\Tests

Code

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

  // Set different minimum and maximum values.
  $options = [
    'min' => 3,
    'max' => 7,
  ];
  $this
    ->drupalPostForm('xmlrpc_example/server', $options, t('Save configuration'));
  $this
    ->assertText(t('The configuration options have been saved'), 'Results limited to >= 3 and <= 7');
  $edit = [
    'num1' => 8,
    'num2' => 3,
  ];
  $this
    ->drupalPostForm('xmlrpc_example/client', $edit, t('Subtract the integers'));
  $this
    ->assertText(t('The XML-RPC server returned this response: @num', [
    '@num' => 5,
  ]));
  $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(xmlrpc_errno(), 10002, 'subtracting 4-3 = 1 returns custom error: 10002');
  $result = xmlrpc($this->xmlRpcUrl, [
    'xmlrpc_example.add' => [
      7,
      4,
    ],
  ]);
  $this
    ->assertEqual(xmlrpc_errno(), 10001, 'Adding 7 + 4 = 11 returns custom error: 10001');
}