You are here

class TestRestClient in Salesforce Suite 8.3

Same name and namespace in other branches
  1. 8.4 src/Tests/TestRestClient.php \Drupal\salesforce\Tests\TestRestClient
  2. 5.0.x src/Tests/TestRestClient.php \Drupal\salesforce\Tests\TestRestClient

Test Salesforce REST client.

Hierarchy

Expanded class hierarchy of TestRestClient

See also

tests/modules/salesforce_test_rest_client

1 file declares its use of TestRestClient
SalesforceTestRestClientServiceProvider.php in tests/modules/salesforce_test_rest_client/src/SalesforceTestRestClientServiceProvider.php

File

src/Tests/TestRestClient.php, line 18

Namespace

Drupal\salesforce\Tests
View source
class TestRestClient extends RestClient {
  const AUTH_ENDPOINT_URL = 'https://example.com/fake/auth/endpoint/for/testing';
  const AUTH_TOKEN_URL = 'https://example.com/fake/token/url/for/testing';

  /**
   * Always return TRUE for test client.
   */
  public function isAuthorized() {
    return TRUE;
  }

  /**
   * Short-circuit api calls.
   */
  public function apiCall($path, array $params = [], $method = 'GET', $returnObject = FALSE) {
  }

  /**
   * Hard-code a short list of objects for testing.
   */
  public function objects(array $conditions = [
    'updateable' => TRUE,
  ], $reset = FALSE) {
    return json_decode(file_get_contents(__DIR__ . '/objects.json'), JSON_OBJECT_AS_ARRAY);
  }

  /**
   * Hard-code the object descriptions for testing.
   */
  public function objectDescribe($name, $reset = FALSE) {
    $contents = file_get_contents(__DIR__ . '/objectDescribe.json');
    return new RestResponseDescribe(new RestResponse(new Response(200, [
      'Content-Type' => 'application/json;charset=UTF-8',
    ], $contents)));
  }

  /**
   * Hard-code record types for testing.
   */
  public function getRecordTypes($name = NULL, $reset = FALSE) {
    $json = json_decode(file_get_contents(__DIR__ . '/recordTypes.json'), JSON_OBJECT_AS_ARRAY);
    $result = new SelectQueryResult($json);
    $record_types = [];
    foreach ($result
      ->records() as $rt) {
      $record_types[$rt
        ->field('SobjectType')][$rt
        ->field('DeveloperName')] = $rt;
    }
    if ($name != NULL) {
      if (!isset($record_types[$name])) {
        throw new \Exception("No record types for {$name}");
      }
      return $record_types[$name];
    }
    return $record_types;
  }

  /**
   * Helper callback for OAuth handshake, and refreshToken()
   *
   * @param \GuzzleHttp\Psr7\Response $response
   *   Response object from refreshToken or authToken endpoints.
   *
   * @see SalesforceController::oauthCallback()
   * @see self::refreshToken()
   */
  public function handleAuthResponse(Response $response) {
  }

  /**
   * Get the fake OAuth endpoint.
   *
   * @return string
   *   REST OAuth Login URL.
   */
  public function getAuthEndpointUrl() {
    return self::AUTH_ENDPOINT_URL;
  }

  /**
   * Get the fake Auth token endpoint.
   *
   * @return string
   *   REST OAuth Token URL.
   */
  public function getAuthTokenUrl() {
    return self::AUTH_TOKEN_URL;
  }

  /**
   * Prevent an API call out here.
   */
  public function listResources() {
    return (object) [
      'resources' => [],
    ];
  }

  /**
   * @inheritDoc
   */
  public function objectCreate($name, array $params) {
    $random = new Random();
    return new SFID(strtoupper($random
      ->string(SFID::MAX_LENGTH)));
  }

  /**
   * @inheritDoc
   */
  public function objectUpsert($name, $key, $value, array $params) {
    $random = new Random();
    return new SFID(strtoupper($random
      ->string(SFID::MAX_LENGTH)));
  }

  /**
   * @inheritDoc
   */
  public function objectUpdate($name, $id, array $params) {

    // Object update does... NOTHING!
    return NULL;
  }

  /**
   * @inheritDoc
   */
  public function objectDelete($name, $id, $throw_exception = FALSE) {

    // Object delete does... NOTHING!
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RestClient::$cache protected property The cache service.
RestClient::$configFactory protected property Config factory service.
RestClient::$httpClient protected property GuzzleHttp client.
RestClient::$httpClientOptions protected property
RestClient::$immutableConfig protected property Salesforce immutable config object. Useful for gets.
RestClient::$json protected property The JSON serializer service.
RestClient::$mutableConfig protected property Salesforce mutable config object. Useful for sets.
RestClient::$response public property Response object.
RestClient::$state protected property The state service.
RestClient::$storage Deprecated private property Token storage.
RestClient::$url protected property Salesforce API URL.
RestClient::apiHttpRequest protected function Private helper to issue an SF API request.
RestClient::CACHE_LIFETIME constant
RestClient::getAccessToken public function Get the access token. Overrides RestClientInterface::getAccessToken 1
RestClient::getApiEndPoint public function Get the API end point for a given type of the API. Overrides RestClientInterface::getApiEndPoint
RestClient::getApiUsage public function Get the api usage, as returned in the most recent API request header. Overrides RestClientInterface::getApiUsage
RestClient::getApiVersion public function Wrapper for config rest_api_version.version. Overrides RestClientInterface::getApiVersion
RestClient::getAuthCallbackUrl public function Helper to build the redirect URL for OAUTH workflow. Overrides RestClientInterface::getAuthCallbackUrl
RestClient::getConsumerKey public function Consumer key getter. Overrides RestClientInterface::getConsumerKey 1
RestClient::getConsumerSecret public function Comsumer secret getter. Overrides RestClientInterface::getConsumerSecret 1
RestClient::getDeleted public function Retrieves objects deleted within the given timeframe. Overrides RestClientInterface::getDeleted
RestClient::getErrorData protected function Extract normalized error information from a RequestException.
RestClient::getHttpClientOption public function Getter for a single, named HTTP client option. Overrides RestClientInterface::getHttpClientOption
RestClient::getHttpClientOptions public function Getter for HTTP client options. Overrides RestClientInterface::getHttpClientOptions
RestClient::getIdentity public function Return the Salesforce identity, which is stored in a variable. Overrides RestClientInterface::getIdentity 1
RestClient::getInstanceUrl public function Get the SF instance URL. Useful for linking to objects. Overrides RestClientInterface::getInstanceUrl
RestClient::getLoginUrl public function Login url getter. Overrides RestClientInterface::getLoginUrl
RestClient::getObjectTypeName public function Utility function to determine object type for given SFID. Overrides RestClientInterface::getObjectTypeName
RestClient::getRecordTypeIdByDeveloperName public function Given a DeveloperName and SObject Name, return SFID of the RecordType. Overrides RestClientInterface::getRecordTypeIdByDeveloperName
RestClient::getRefreshToken public function Get refresh token. 1
RestClient::getRequestTime protected function Returns REQUEST_TIME.
RestClient::getUpdated public function Return a list of SFIDs for the given object for the given timeframe. Overrides RestClientInterface::getUpdated
RestClient::getVersions public function Wrapper for "Versions" resource to list information about API releases. Overrides RestClientInterface::getVersions
RestClient::httpRequest protected function Make the HTTP request. Wrapper around drupal_http_request().
RestClient::httpRequestRaw public function Return raw response content from given URL. Overrides RestClientInterface::httpRequestRaw
RestClient::initializeIdentity public function Retrieve and store the Salesforce identity given an ID url. Overrides RestClientInterface::initializeIdentity
RestClient::LONGTERM_CACHE_LIFETIME constant
RestClient::objectRead public function Return a fullly loaded Salesforce object. Overrides RestClientInterface::objectRead
RestClient::objectReadbyExternalId public function Return a full loaded Salesforce object from External ID. Overrides RestClientInterface::objectReadbyExternalId
RestClient::query public function Use SOQL to get objects based on query string. Overrides RestClientInterface::query
RestClient::queryAll public function Same as ::query(), but also returns deleted or archived records. Overrides RestClientInterface::queryAll
RestClient::queryMore public function Given a select query result, fetch the next results set, if it exists. Overrides RestClientInterface::queryMore
RestClient::refreshToken public function Refresh access token based on the refresh token. Overrides RestClientInterface::refreshToken
RestClient::setAccessToken public function Set the access token. Overrides RestClientInterface::setAccessToken 1
RestClient::setApiVersion public function Setter for config salesforce.settings rest_api_version and use_latest. Overrides RestClientInterface::setApiVersion
RestClient::setConsumerKey public function Consumer key setter. Overrides RestClientInterface::setConsumerKey 1
RestClient::setConsumerSecret public function Consumer key setter. Overrides RestClientInterface::setConsumerSecret 1
RestClient::setHttpClientOption public function Set a single Guzzle HTTP client option. Overrides RestClientInterface::setHttpClientOption
RestClient::setHttpClientOptions public function Set options for Guzzle HTTP client. Overrides RestClientInterface::setHttpClientOptions
RestClient::setIdentity public function Set the Salesforce identity, which is stored in a variable. Overrides RestClientInterface::setIdentity 1
RestClient::setInstanceUrl public function Set the SF instance URL. Overrides RestClientInterface::setInstanceUrl
RestClient::setLoginUrl public function Login url setter. Overrides RestClientInterface::setLoginUrl
RestClient::setRefreshToken public function Set the refresh token. Overrides RestClientInterface::setRefreshToken 1
RestClient::storage Deprecated private function Storage helper.
RestClient::updateApiUsage protected function Helper to extract API Usage info from response header and write to state.
RestClient::__construct public function Constructor which initializes the consumer. 1
TestRestClient::apiCall public function Short-circuit api calls. Overrides RestClient::apiCall
TestRestClient::AUTH_ENDPOINT_URL constant
TestRestClient::AUTH_TOKEN_URL constant
TestRestClient::getAuthEndpointUrl public function Get the fake OAuth endpoint. Overrides RestClient::getAuthEndpointUrl
TestRestClient::getAuthTokenUrl public function Get the fake Auth token endpoint. Overrides RestClient::getAuthTokenUrl
TestRestClient::getRecordTypes public function Hard-code record types for testing. Overrides RestClient::getRecordTypes
TestRestClient::handleAuthResponse public function Helper callback for OAuth handshake, and refreshToken() Overrides RestClient::handleAuthResponse
TestRestClient::isAuthorized public function Always return TRUE for test client. Overrides RestClient::isAuthorized
TestRestClient::listResources public function Prevent an API call out here. Overrides RestClient::listResources
TestRestClient::objectCreate public function @inheritDoc Overrides RestClient::objectCreate
TestRestClient::objectDelete public function @inheritDoc Overrides RestClient::objectDelete
TestRestClient::objectDescribe public function Hard-code the object descriptions for testing. Overrides RestClient::objectDescribe
TestRestClient::objects public function Hard-code a short list of objects for testing. Overrides RestClient::objects
TestRestClient::objectUpdate public function @inheritDoc Overrides RestClient::objectUpdate
TestRestClient::objectUpsert public function @inheritDoc Overrides RestClient::objectUpsert