You are here

protected function LayoutRestTestBase::request in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/tests/src/Functional/Rest/LayoutRestTestBase.php \Drupal\Tests\layout_builder\Functional\Rest\LayoutRestTestBase::request()
  2. 9 core/modules/layout_builder/tests/src/Functional/Rest/LayoutRestTestBase.php \Drupal\Tests\layout_builder\Functional\Rest\LayoutRestTestBase::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

Overrides ResourceTestBase::request

See also

\GuzzleHttp\ClientInterface::request()

1 call to LayoutRestTestBase::request()
OverrideSectionsTest::testOverrideField in core/modules/layout_builder/tests/src/Functional/Rest/OverrideSectionsTest.php
Tests that the layout override field is not normalized.

File

core/modules/layout_builder/tests/src/Functional/Rest/LayoutRestTestBase.php, line 93

Class

LayoutRestTestBase
Base class for Layout Builder REST tests.

Namespace

Drupal\Tests\layout_builder\Functional\Rest

Code

protected function request($method, Url $url, array $request_options = []) {
  $request_options[RequestOptions::HEADERS] = [
    'Content-Type' => static::$mimeType,
  ];
  $request_options = NestedArray::mergeDeep($request_options, $this
    ->getAuthenticationRequestOptions($method));
  $request_options[RequestOptions::QUERY] = [
    '_format' => static::$format,
  ];
  return parent::request($method, $url, $request_options);
}