You are here

protected function JsonApiRequestTestTrait::request in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/JsonApiRequestTestTrait.php \Drupal\Tests\jsonapi\Functional\JsonApiRequestTestTrait::request()
  2. 10 core/modules/jsonapi/tests/src/Functional/JsonApiRequestTestTrait.php \Drupal\Tests\jsonapi\Functional\JsonApiRequestTestTrait::request()

Performs a HTTP request. Wraps the Guzzle HTTP client.

Why wrap the Guzzle HTTP client? Because we want to keep the actual test code as simple as possible, and hence not require them to specify the 'http_errors = FALSE' request option, nor do we want them to have to convert Drupal Url objects to strings.

We also don't want to follow redirects automatically, to ensure these tests are able to detect when redirects are added or removed.

Parameters

string $method: HTTP method.

\Drupal\Core\Url $url: URL to request.

array $request_options: Request options to apply.

Return value

\Psr\Http\Message\ResponseInterface The response.

See also

\GuzzleHttp\ClientInterface::request()

36 calls to JsonApiRequestTestTrait::request()
CommentTest::testCollectionFilterAccess in core/modules/jsonapi/tests/src/Functional/CommentTest.php
CommentTest::testPostIndividualDxWithoutCriticalBaseFields in core/modules/jsonapi/tests/src/Functional/CommentTest.php
Tests POSTing a comment without critical base fields.
CommentTest::testPostIndividualSkipCommentApproval in core/modules/jsonapi/tests/src/Functional/CommentTest.php
Tests POSTing a comment with and without 'skip comment approval'.
ConfigurableLanguageTest::testGetIndividualDefaultConfig in core/modules/jsonapi/tests/src/Functional/ConfigurableLanguageTest.php
Test a GET request for a default config entity, which has a _core key.
EntryPointTest::testEntryPoint in core/modules/jsonapi/tests/src/Functional/EntryPointTest.php
Test GETing the entry point.

... See full list

File

core/modules/jsonapi/tests/src/Functional/JsonApiRequestTestTrait.php, line 39

Class

JsonApiRequestTestTrait
Boilerplate for JSON:API Functional tests' HTTP requests.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function request($method, Url $url, array $request_options) {
  $this
    ->refreshVariables();
  $request_options[RequestOptions::HTTP_ERRORS] = FALSE;
  $request_options[RequestOptions::ALLOW_REDIRECTS] = FALSE;
  $request_options = $this
    ->decorateWithXdebugCookie($request_options);
  $client = $this
    ->getSession()
    ->getDriver()
    ->getClient()
    ->getClient();
  return $client
    ->request($method, $url
    ->setAbsolute(TRUE)
    ->toString(), $request_options);
}