You are here

public function ServicesXMLRPCTestCase::servicesXMLRPC in Services 7.3

Do XMLRPC call.

Parameters

string $method: Name of method to call.

array $args: Arguments to pass to call.

bool $sessid: Add cookies in order to log in.

bool $assert_no_error: Whether assert that no error returned.

Return value

array array( 'body' -- answer of call 'error_message' -- error message if any )

3 calls to ServicesXMLRPCTestCase::servicesXMLRPC()
ServicesXMLRPCTestCase::testlistMethods in tests/functional/ServicesXMLRPCTests.test
Test list.Methods call.
ServicesXMLRPCTestCase::testPrecedence in tests/functional/ServicesXMLRPCTests.test
Precedence CRUD methods > Actions > Relations > Targeted Actions
ServicesXMLRPCTestCase::testUserLogin in tests/functional/ServicesXMLRPCTests.test
Test user login.

File

tests/functional/ServicesXMLRPCTests.test, line 214

Class

ServicesXMLRPCTestCase

Code

public function servicesXMLRPC($method, $args = array(), $sessid = TRUE, $assert_no_error = TRUE) {
  if (!is_array($args)) {
    $args = array(
      $args,
    );
  }
  $options = array(
    'headers' => array(),
  );

  // Set up cookies.
  if ($sessid && !empty($this->sessid)) {
    $options['headers']['Cookie'] = $this->session_name . '=' . $this->sessid;
  }
  $csrf_token_response = xmlrpc(url($this->endpoint->path, array(
    'absolute' => TRUE,
  )), array(
    'user.token' => array(),
  ), $options);
  $options['headers']['X-CSRF-Token'] = $csrf_token_response['token'];
  $output = xmlrpc(url($this->endpoint->path, array(
    'absolute' => TRUE,
  )), array(
    $method => $args,
  ), $options);
  $error_message = xmlrpc_error_msg();
  if ($assert_no_error) {
    $this
      ->assertTrue(empty($error_message), format_string('XMLRPC call %method run without errors.', array(
      '%method' => $method,
    )), 'XMLRPC call');
  }
  $this
    ->verbose('XMLRPC request to: ' . $method . '<hr />Arguments: ' . highlight_string('<?php ' . var_export($args, TRUE), TRUE) . '<hr />Response: ' . highlight_string('<?php ' . var_export($output, TRUE), TRUE) . '<hr />Error: ' . $error_message);
  if (!empty($error_message)) {
    return array(
      'error_message' => $error_message,
      'body' => '',
    );
  }
  return array(
    'error_message' => '',
    'body' => $output,
  );
}