You are here

public function XmlrpcExampleTestCase::testXmlrpcExampleServer in Examples for Developers 7

Same name and namespace in other branches
  1. 6 xmlrpc_example/xmlrpc_example.test \XmlrpcExampleTestCase::testXmlrpcExampleServer()

Perform several XML-RPC requests with different server settings.

File

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

Class

XmlrpcExampleTestCase
Functional tests for the XMLRPC Example module.

Code

public function testXmlrpcExampleServer() {

  // Set different minimum and maxmimum valuesI.
  $options = array(
    'xmlrpc_example_server_min' => 3,
    'xmlrpc_example_server_max' => 7,
  );
  $this
    ->drupalPost('examples/xmlrpc/server', $options, t('Save configuration'));
  $this
    ->assertText(t('The configuration options have been saved'), 'Results limited to >= 3 and <= 7');
  $edit = array(
    'num1' => 8,
    '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' => 5,
  )));
  $result = xmlrpc($this->xmlRpcUrl, array(
    'xmlrpc_example.add' => array(
      3,
      4,
    ),
  ));
  $this
    ->assertEqual($result, 7, 'Successfully added 3+4 = 7');
  $result = xmlrpc($this->xmlRpcUrl, array(
    'xmlrpc_example.subtract' => array(
      4,
      3,
    ),
  ));
  $this
    ->assertEqual(xmlrpc_errno(), 10002, 'subtracting 4-3 = 1 returns custom error: 10002');
  $result = xmlrpc($this->xmlRpcUrl, array(
    'xmlrpc_example.add' => array(
      7,
      4,
    ),
  ));
  $this
    ->assertEqual(xmlrpc_errno(), 10001, 'Adding 7 + 4 = 11 returns custom error: 10001');
}