You are here

class ClientsConnectionDrupalRESTTestLogin in Web Service Clients 7.3

Test basic connection to a Drupal Services connection.

Hierarchy

Expanded class hierarchy of ClientsConnectionDrupalRESTTestLogin

1 string reference to 'ClientsConnectionDrupalRESTTestLogin'
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 10
Contains classes for Client connection testing.

View source
class ClientsConnectionDrupalRESTTestLogin implements ClientsConnectionTestingInterface {

  /**
   * The labels for the test.
   *
   * (This is because it would seem you can't define class variables using
   * expressions.)
   */
  function testLabels() {
    return array(
      'label' => t('Test login'),
      'description' => t('Test the basic connection to the site by logging in the user.'),
      'button' => t('Connect'),
    );
  }

  /**
   * 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) {
    try {

      // Call the login method.
      $login = $connection
        ->userLogin();
    } catch (Exception $e) {
      drupal_set_message(t('Could not log in to the remote site, got error message "@message".', array(
        '@message' => $e
          ->getMessage(),
      )), 'warning');

      //dsm($e);
      return;
    }
    if (is_object($login) && isset($login->user)) {
      drupal_set_message(t('Sucessfully logged in to the remote site; got back details for user %user (uid @uid).', array(
        '%user' => $login->user->name,
        '@uid' => $login->user->uid,
      )));
    }
    else {
      drupal_set_message(t('Could not log in to the remote site.'), 'warning');
    }
    return $login;
  }

}

Members