You are here

public function XmlRpcExampleTest::testXmlrpcExampleClient in xmlrpc 8

Perform several calls using XML-RPC web client.

File

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

Class

XmlRpcExampleTest
Test case for testing the xmlrpc_example module.

Namespace

Drupal\xmlrpc_example\Tests

Code

public function testXmlrpcExampleClient() {

  // Now test the UI.
  // Add the integers.
  $edit = [
    'num1' => 3,
    'num2' => 5,
  ];
  $this
    ->drupalPostForm('xmlrpc_example/client', $edit, t('Add the integers'));
  $this
    ->assertText(t('The XML-RPC server returned this response: @num', [
    '@num' => 8,
  ]));

  // Subtract the integers.
  $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,
  ]));

  // Request available methods.
  $this
    ->drupalPostForm('xmlrpc_example/client', $edit, t('Request methods'));
  $this
    ->assertText('xmlrpc_example.add', 'The XML-RPC Add method was found.');
  $this
    ->assertText('xmlrpc_example.subtract', 'The XML-RPC Subtract method was found.');

  // Before testing multicall, verify that method exists.
  $this
    ->assertText('system.multicall', 'The XML-RPC Multicall method was found.');

  // Verify multicall request.
  $edit = [
    'num1' => 5,
    'num2' => 2,
  ];
  $this
    ->drupalPostForm('xmlrpc_example/client', $edit, t('Add and Subtract'));
  $this
    ->assertText('[0] => 7', 'The XML-RPC server returned the addition result.');
  $this
    ->assertText('[1] => 3', 'The XML-RPC server returned the subtraction result.');
}