You are here

protected function JsonRpcTestBase::postRpc in JSON-RPC 8

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

Post a request in JSON format.

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 Exceptions from the Guzzle client.

1 call to JsonRpcTestBase::postRpc()
MaintenanceModeEnabledTest::testEnablingMaintenanceMode in modules/jsonrpc_core/tests/src/Functional/MaintenanceModeEnabledTest.php
Tests enabling the maintenance mode.

File

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

Class

JsonRpcTestBase
Class JsonRpcTestBase.

Namespace

Drupal\Tests\jsonrpc\Functional

Code

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