class TestRestClient in Salesforce Suite 5.0.x
Same name and namespace in other branches
- 8.4 src/Tests/TestRestClient.php \Drupal\salesforce\Tests\TestRestClient
- 8.3 src/Tests/TestRestClient.php \Drupal\salesforce\Tests\TestRestClient
Test Salesforce REST client.
Hierarchy
- class \Drupal\salesforce\Rest\RestClient implements RestClientInterface uses StringTranslationTrait
- class \Drupal\salesforce\Tests\TestRestClient
Expanded class hierarchy of TestRestClient
See also
tests/modules/salesforce_test_rest_client
2 files declare their use of TestRestClient
- PullQueueTest.php in modules/
salesforce_pull/ tests/ src/ Functional/ PullQueueTest.php - SalesforceTestRestClientServiceProvider.php in tests/
modules/ salesforce_test_rest_client/ src/ SalesforceTestRestClientServiceProvider.php
File
- src/
Tests/ TestRestClient.php, line 19
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';
/**
* {@inheritdoc}
*/
public function isInit() {
return TRUE;
}
/**
* Wrapper for test results.
*/
public static function getContactQueryResults() {
return json_decode(file_get_contents(__DIR__ . '/contactQuery.json'), JSON_OBJECT_AS_ARRAY);
}
/**
* Mock a query result for test_mapping.
*
* @see modules/salesforce_mapping/tests/modules/salesforce_mapping_test/config/install/salesforce_mapping.salesforce_mapping.test_mapping.yml
*/
public function query(SelectQueryInterface $query) {
return new SelectQueryResult(self::getContactQueryResults());
}
/**
* 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 | Active auth provider config. | |
RestClient:: |
protected | property | Auth provider manager. | |
RestClient:: |
protected | property | Active auth provider. | |
RestClient:: |
protected | property | Active auth token. | |
RestClient:: |
protected | property | The cache service. | |
RestClient:: |
protected | property | Config factory service. | |
RestClient:: |
protected | property | GuzzleHttp client. | |
RestClient:: |
protected | property | HTTP client options. | |
RestClient:: |
protected | property | Salesforce immutable config object. Useful for gets. | |
RestClient:: |
protected | property | The JSON serializer service. | |
RestClient:: |
public | property | Response object. | |
RestClient:: |
protected | property | The state service. | |
RestClient:: |
protected | property | Salesforce API URL. | |
RestClient:: |
protected | function | Private helper to issue an SF API request. | |
RestClient:: |
constant | |||
RestClient:: |
public | function |
Get the api usage, as returned in the most recent API request header. Overrides RestClientInterface:: |
|
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 |
Getter for long term cache lifetime. 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:: |
protected | function | Returns REQUEST_TIME. | |
RestClient:: |
public | function |
Getter for short term cache lifetime. Overrides RestClientInterface:: |
|
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:: |
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 |
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 |
Set a single Guzzle HTTP client option. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Set options for Guzzle HTTP client. Overrides RestClientInterface:: |
|
RestClient:: |
protected | function | Helper to extract API Usage info from response header and write to state. | |
RestClient:: |
public | function | Constructor which initializes the consumer. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TestRestClient:: |
public | function |
Short-circuit api calls. Overrides RestClient:: |
|
TestRestClient:: |
constant | |||
TestRestClient:: |
constant | |||
TestRestClient:: |
public | function | Get the fake OAuth endpoint. | |
TestRestClient:: |
public | function | Get the fake Auth token endpoint. | |
TestRestClient:: |
public static | function | Wrapper for test results. | |
TestRestClient:: |
public | function |
Hard-code record types for testing. Overrides RestClient:: |
|
TestRestClient:: |
public | function | Helper callback for OAuth handshake, and refreshToken() | |
TestRestClient:: |
public | function |
Check if the client is ready to perform API calls. Overrides RestClient:: |
|
TestRestClient:: |
public | function |
Prevent an API call out here. Overrides RestClient:: |
|
TestRestClient:: |
public | function |
Create a new object of the given type. Overrides RestClient:: |
|
TestRestClient:: |
public | function |
Delete a Salesforce object. 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 |
Update an existing object. Overrides RestClient:: |
|
TestRestClient:: |
public | function |
Create new records or update existing records. Overrides RestClient:: |
|
TestRestClient:: |
public | function |
Mock a query result for test_mapping. Overrides RestClient:: |