You are here

protected function JsonRpcTestBase::getRpc in JSON-RPC 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/JsonRpcTestBase.php \Drupal\Tests\jsonrpc\Functional\JsonRpcTestBase::getRpc()

JSON RPC request using the GET method.

Parameters

array $rpc_request: The request structure that will be sent as JSON.

\Drupal\Core\Session\AccountInterface $account: The user to be used for Basic Auth authentication.

Return value

\Psr\Http\Message\ResponseInterface The response.

Throws

\GuzzleHttp\Exception\GuzzleException

1 call to JsonRpcTestBase::getRpc()
PluginsTest::testPlugins in modules/jsonrpc_core/tests/src/Functional/PluginsTest.php
Tests the plugin list.

File

tests/src/Functional/JsonRpcTestBase.php, line 64

Class

JsonRpcTestBase
Class JsonRpcTestBase.

Namespace

Drupal\Tests\jsonrpc\Functional

Code

protected function getRpc(array $rpc_request, AccountInterface $account = NULL) {
  $url = $this
    ->buildUrl(Url::fromRoute('jsonrpc.handler'));
  $request_options = [
    RequestOptions::HTTP_ERRORS => FALSE,
    RequestOptions::ALLOW_REDIRECTS => FALSE,
    RequestOptions::QUERY => [
      'query' => Json::encode($rpc_request),
    ],
  ];
  if ($account !== NULL) {
    $request_options[RequestOptions::AUTH] = [
      $account
        ->getAccountName(),
      $account->passRaw,
    ];
  }
  $client = $this
    ->getHttpClient();
  return $client
    ->request('GET', $url, $request_options);
}