class ClientsConnectionDrupalRESTTestNodeRetrieve in Web Service Clients 7.3
Test node load from a Drupal Services REST connection.
Hierarchy
- class \ClientsConnectionDrupalRESTTestNodeRetrieve implements ClientsConnectionTestingInterface
Expanded class hierarchy of ClientsConnectionDrupalRESTTestNodeRetrieve
1 string reference to 'ClientsConnectionDrupalRESTTestNodeRetrieve'
- clients_drupal_rest_clients_connection_type_info in connections/
clients_drupal_rest/ clients_drupal_rest.module - Implements hook_clients_connection_type_info().
File
- connections/
clients_drupal_rest/ clients_drupal_rest.testing.inc, line 73 - Contains classes for Client connection testing.
View source
class ClientsConnectionDrupalRESTTestNodeRetrieve implements ClientsConnectionTestingInterface {
/**
* The labels for the test.
*/
function testLabels() {
return array(
'label' => t('Test node retrieval'),
'description' => t('Load a node from the connection.'),
'button' => t('Load node'),
);
}
/**
* Creates the form element for the test.
*
* This gets a form element with the basics in place. If your test needs input
* parameters, add form elements here.
*
* @param $element
* A form element for the test's settings and button.
*
* @return
* The form element with the test's additions.
*/
function testForm($element) {
$element['params']['nid'] = array(
'#type' => 'textfield',
'#title' => t('Node ID'),
'#size' => 6,
'#required' => TRUE,
);
return $element;
}
/**
* Validate test form input.
*/
function formValidate(&$button_form_values) {
if (!is_numeric($button_form_values['params']['nid'])) {
form_set_error('buttons][node_load][nid', t('Node id must be numeric.'));
}
}
/**
* Execute the test.
*
* Connection test handlers should return the raw data they got back from the
* connection for display to the user.
*
* @param $connection
* The connection handler.
* @param $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
* Data from the remote connection. This is output to the form as raw data.
*/
function test($connection, &$button_form_values) {
// Must be cast to integer for faffiness of XMLRPC and Services.
$nid = (int) $button_form_values['params']['nid'];
try {
$node = $connection
->makeRequest('node/' . $nid, 'GET');
} catch (Exception $e) {
drupal_set_message(t('Could not retrieve a node from the remote site, got error message "@message".', array(
'@message' => $e
->getMessage(),
)), 'warning');
//dsm($e);
return;
}
if (is_object($node) && isset($node->nid)) {
drupal_set_message(t('Sucessfully retrieved node %title (nid @nid).', array(
'%title' => $node->title,
'@nid' => $node->nid,
)));
}
return $node;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ClientsConnectionDrupalRESTTestNodeRetrieve:: |
function | Validate test form input. | ||
ClientsConnectionDrupalRESTTestNodeRetrieve:: |
function |
Execute the test. Overrides ClientsConnectionTestingInterface:: |
||
ClientsConnectionDrupalRESTTestNodeRetrieve:: |
function | Creates the form element for the test. | ||
ClientsConnectionDrupalRESTTestNodeRetrieve:: |
function |
The labels for the test. Overrides ClientsConnectionTestingInterface:: |