You are here

public function TestHttpClientWrapper::retrieveResponse in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 5.0.x src/Tests/TestHttpClientWrapper.php \Drupal\salesforce\Tests\TestHttpClientWrapper::retrieveResponse()

File

src/Tests/TestHttpClientWrapper.php, line 34

Class

TestHttpClientWrapper
Wraps Guzzle HTTP client for an OAuth ClientInterface.

Namespace

Drupal\salesforce\Tests

Code

public function retrieveResponse(UriInterface $endpoint, $requestBody, array $extraHeaders = [], $method = 'POST') {

  // This method is only used to Salesforce OAuth. Based on the given args,
  // return a hard-coded version of the expected response.
  $dir = drupal_get_path('module', 'salesforce') . '/src/Tests/';
  if ($endpoint
    ->getPath() == '/services/oauth2/token') {
    switch ($requestBody['grant_type']) {
      case 'authorization_code':
        $content = file_get_contents($dir . '/oauthResponse.json');
      case 'urn:ietf:params:oauth:grant-type:jwt-bearer':
        $content = file_get_contents($dir . '/jwtAuthResponse.json');
    }
  }
  elseif ($endpoint
    ->getPath() == '/id/XXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXX') {
    $content = file_get_contents($dir . '/identityResponse.json');
  }
  return $content ?: '';
}