TestRestClient.php in Salesforce Suite 8.3
File
src/Tests/TestRestClient.php
View source
<?php
namespace Drupal\salesforce\Tests;
use Drupal\Component\Utility\Random;
use Drupal\salesforce\Rest\RestResponse;
use Drupal\salesforce\Rest\RestResponseDescribe;
use Drupal\salesforce\SelectQueryResult;
use Drupal\salesforce\SFID;
use GuzzleHttp\Psr7\Response;
use Drupal\salesforce\Rest\RestClient;
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';
public function isAuthorized() {
return TRUE;
}
public function apiCall($path, array $params = [], $method = 'GET', $returnObject = FALSE) {
}
public function objects(array $conditions = [
'updateable' => TRUE,
], $reset = FALSE) {
return json_decode(file_get_contents(__DIR__ . '/objects.json'), JSON_OBJECT_AS_ARRAY);
}
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)));
}
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;
}
public function handleAuthResponse(Response $response) {
}
public function getAuthEndpointUrl() {
return self::AUTH_ENDPOINT_URL;
}
public function getAuthTokenUrl() {
return self::AUTH_TOKEN_URL;
}
public function listResources() {
return (object) [
'resources' => [],
];
}
public function objectCreate($name, array $params) {
$random = new Random();
return new SFID(strtoupper($random
->string(SFID::MAX_LENGTH)));
}
public function objectUpsert($name, $key, $value, array $params) {
$random = new Random();
return new SFID(strtoupper($random
->string(SFID::MAX_LENGTH)));
}
public function objectUpdate($name, $id, array $params) {
return NULL;
}
public function objectDelete($name, $id, $throw_exception = FALSE) {
return NULL;
}
}