You are here

public function XmlRpcExampleTest::testXmlrpcExampleAlter in xmlrpc 8

Perform several XML-RPC requests.

Alter the server behaviour with hook_xmlrpc_alter API.

See also

hook_xmlrpc_alter()

File

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

Class

XmlRpcExampleTest
Test case for testing the xmlrpc_example module.

Namespace

Drupal\xmlrpc_example\Tests

Code

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

  // Enable XML-RPC service altering functionality.
  $options = [
    'alter_enabled' => TRUE,
  ];
  $this
    ->drupalPostForm('xmlrpc_example/alter', $options, t('Save configuration'));
  $this
    ->assertText(t('The configuration options have been saved'), 'Results are not limited due to methods alteration');

  // After altering the functionality, the add and subtract methods have no
  // limits and should not return any error.
  $edit = [
    'num1' => 80,
    'num2' => 3,
  ];
  $this
    ->drupalPostForm('xmlrpc_example/client', $edit, t('Subtract the integers'));
  $this
    ->assertText(t('The XML-RPC server returned this response: @num', [
    '@num' => 77,
  ]));
  $result = xmlrpc($this->xmlRpcUrl, [
    'xmlrpc_example.add' => [
      30,
      4,
    ],
  ]);
  $this
    ->assertEqual($result, 34, 'Successfully added 30+4 = 34');
  $result = xmlrpc($this->xmlRpcUrl, [
    'xmlrpc_example.subtract' => [
      4,
      30,
    ],
  ]);
  $this
    ->assertEqual($result, -26, 'Successfully subtracted 4-30 = -26');
}