You are here

protected function JsonRpcTestBase::postRpc in JSON-RPC 2.x

Same name and namespace in other branches
  1. 8 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.

3 calls to JsonRpcTestBase::postRpc()
MaintenanceModeEnabledTest::testEnablingMaintenanceMode in modules/jsonrpc_core/tests/src/Functional/MaintenanceModeEnabledTest.php
Tests enabling the maintenance mode.
ResponseHeadersTest::testInvalidSchema in tests/src/Functional/ResponseHeadersTest.php
Ensures that a response not matching the schema produces invalid results.
ResponseHeadersTest::testResponseHeaders in tests/src/Functional/ResponseHeadersTest.php
Tests enabling the maintenance mode.

File

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

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);
}