class TestRestClient in Salesforce Suite 8.3
Same name and namespace in other branches
- 8.4 src/Tests/TestRestClient.php \Drupal\salesforce\Tests\TestRestClient
- 5.0.x src/Tests/TestRestClient.php \Drupal\salesforce\Tests\TestRestClient
Test Salesforce REST client.
Hierarchy
- class \Drupal\salesforce\Rest\RestClient implements RestClientInterface
- class \Drupal\salesforce\Tests\TestRestClient
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\TestsView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RestClient:: |
protected | property | The cache service. | |
RestClient:: |
protected | property | Config factory service. | |
RestClient:: |
protected | property | GuzzleHttp client. | |
RestClient:: |
protected | property | ||
RestClient:: |
protected | property | Salesforce immutable config object. Useful for gets. | |
RestClient:: |
protected | property | The JSON serializer service. | |
RestClient:: |
protected | property | Salesforce mutable config object. Useful for sets. | |
RestClient:: |
public | property | Response object. | |
RestClient:: |
protected | property | The state service. | |
RestClient:: |
private | property | Token storage. | |
RestClient:: |
protected | property | Salesforce API URL. | |
RestClient:: |
protected | function | Private helper to issue an SF API request. | |
RestClient:: |
constant | |||
RestClient:: |
public | function |
Get the access token. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Get the API end point for a given type of the API. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Get the api usage, as returned in the most recent API request header. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Wrapper for config rest_api_version.version. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Helper to build the redirect URL for OAUTH workflow. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Consumer key getter. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Comsumer secret getter. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Retrieves objects deleted within the given timeframe. Overrides RestClientInterface:: |
|
RestClient:: |
protected | function | Extract normalized error information from a RequestException. | |
RestClient:: |
public | function |
Getter for a single, named HTTP client option. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Getter for HTTP client options. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Return the Salesforce identity, which is stored in a variable. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Get the SF instance URL. Useful for linking to objects. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Login url getter. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Utility function to determine object type for given SFID. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Given a DeveloperName and SObject Name, return SFID of the RecordType. Overrides RestClientInterface:: |
|
RestClient:: |
public | function | Get refresh token. | 1 |
RestClient:: |
protected | function | Returns REQUEST_TIME. | |
RestClient:: |
public | function |
Return a list of SFIDs for the given object for the given timeframe. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Wrapper for "Versions" resource to list information about API releases. Overrides RestClientInterface:: |
|
RestClient:: |
protected | function | Make the HTTP request. Wrapper around drupal_http_request(). | |
RestClient:: |
public | function |
Return raw response content from given URL. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Retrieve and store the Salesforce identity given an ID url. Overrides RestClientInterface:: |
|
RestClient:: |
constant | |||
RestClient:: |
public | function |
Return a fullly loaded Salesforce object. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Return a full loaded Salesforce object from External ID. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Use SOQL to get objects based on query string. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Same as ::query(), but also returns deleted or archived records. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Given a select query result, fetch the next results set, if it exists. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Refresh access token based on the refresh token. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Set the access token. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Setter for config salesforce.settings rest_api_version and use_latest. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Consumer key setter. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Consumer key setter. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Set a single Guzzle HTTP client option. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Set options for Guzzle HTTP client. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Set the Salesforce identity, which is stored in a variable. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Set the SF instance URL. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Login url setter. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Set the refresh token. Overrides RestClientInterface:: |
1 |
RestClient:: |
private | function | Storage helper. | |
RestClient:: |
protected | function | Helper to extract API Usage info from response header and write to state. | |
RestClient:: |
public | function | Constructor which initializes the consumer. | 1 |
TestRestClient:: |
public | function |
Short-circuit api calls. Overrides RestClient:: |
|
TestRestClient:: |
constant | |||
TestRestClient:: |
constant | |||
TestRestClient:: |
public | function |
Get the fake OAuth endpoint. Overrides RestClient:: |
|
TestRestClient:: |
public | function |
Get the fake Auth token endpoint. Overrides RestClient:: |
|
TestRestClient:: |
public | function |
Hard-code record types for testing. Overrides RestClient:: |
|
TestRestClient:: |
public | function |
Helper callback for OAuth handshake, and refreshToken() Overrides RestClient:: |
|
TestRestClient:: |
public | function |
Always return TRUE for test client. Overrides RestClient:: |
|
TestRestClient:: |
public | function |
Prevent an API call out here. Overrides RestClient:: |
|
TestRestClient:: |
public | function |
@inheritDoc Overrides RestClient:: |
|
TestRestClient:: |
public | function |
@inheritDoc Overrides RestClient:: |
|
TestRestClient:: |
public | function |
Hard-code the object descriptions for testing. Overrides RestClient:: |
|
TestRestClient:: |
public | function |
Hard-code a short list of objects for testing. Overrides RestClient:: |
|
TestRestClient:: |
public | function |
@inheritDoc Overrides RestClient:: |
|
TestRestClient:: |
public | function |
@inheritDoc Overrides RestClient:: |