You are here

public function XmlrpcExampleTestCase::testXmlrpcExampleAlter in Examples for Developers 7

Test XML-RPC requests with hook_xmlrpc_alter() functionality.

Perform several XML-RPC requests altering the server behaviour with hook_xmlrpc_alter API.

File

xmlrpc_example/xmlrpc_example.test, line 121
Test case for the XML-RPC example module.

Class

XmlrpcExampleTestCase
Functional tests for the XMLRPC Example module.

Code

public function testXmlrpcExampleAlter() {

  // Enable XML-RPC service altering functionality.
  $options = array(
    'xmlrpc_example_alter_enabled' => TRUE,
  );
  $this
    ->drupalPost('examples/xmlrpc/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 = array(
    'num1' => 80,
    'num2' => 3,
  );
  $this
    ->drupalPost('examples/xmlrpc/client', $edit, t('Subtract the integers'));
  $this
    ->assertText(t('The XML-RPC server returned this response: @num', array(
    '@num' => 77,
  )));
  $result = xmlrpc($this->xmlRpcUrl, array(
    'xmlrpc_example.add' => array(
      30,
      4,
    ),
  ));
  $this
    ->assertEqual($result, 34, 'Successfully added 30+4 = 34');
  $result = xmlrpc($this->xmlRpcUrl, array(
    'xmlrpc_example.subtract' => array(
      4,
      30,
    ),
  ));
  $this
    ->assertEqual($result, -26, 'Successfully subtracted 4-30 = -26');
}