You are here

function ClientsConnectionDrupalRESTTestEntityCreate::test in Web Service Clients 7.3

Execute the test.

Connection test handlers should return the raw data they got back from the connection for display to the user.

Parameters

$connection: The connection handler.

$button_form_values: The form values for the test form element. The values for elements added to the form are in $button_form_values['params'].

Return value

Data from the remote connection. This is output to the form as raw data.

Overrides ClientsConnectionTestingInterface::test

File

connections/clients_drupal_rest/clients_drupal_rest.testing.inc, line 242
Contains classes for Client connection testing.

Class

ClientsConnectionDrupalRESTTestEntityCreate
Test entity creation on a Drupal Services connection.

Code

function test($connection, &$button_form_values) {
  $entity_type = $button_form_values['params']['entity_type'];
  $path = $entity_type;
  if ($button_form_values['params']['data_type'] == 'json') {
    $data = drupal_json_decode($button_form_values['params']['data']);
  }
  else {
    eval('$data = ' . $button_form_values['params']['data'] . ';');
  }
  if (module_exists('devel')) {
    dpm($data, 'POST data');
    $json_error = json_last_error();
    if ($json_error != JSON_ERROR_NONE) {
      dpm($json_error, 'JSON error');
    }
  }
  try {
    $result = $connection
      ->makeRequest($path, 'POST', $data);
  } catch (Exception $e) {
    drupal_set_message($e
      ->getMessage(), 'warning');

    //dsm($e);
    return;
  }
  return $result;
}