You are here

protected function UserLoginHttpTest::passwordRequest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Functional/UserLoginHttpTest.php \Drupal\Tests\user\Functional\UserLoginHttpTest::passwordRequest()
  2. 9 core/modules/user/tests/src/Functional/UserLoginHttpTest.php \Drupal\Tests\user\Functional\UserLoginHttpTest::passwordRequest()

Executes a password HTTP request for a given serialization format.

Parameters

array $request_body: The request body.

string $format: The format to use to make the request.

Return value

\Psr\Http\Message\ResponseInterface The HTTP response.

File

core/modules/user/tests/src/Functional/UserLoginHttpTest.php, line 217

Class

UserLoginHttpTest
Tests login and password reset via direct HTTP.

Namespace

Drupal\Tests\user\Functional

Code

protected function passwordRequest(array $request_body, $format = 'json') {
  $password_reset_url = Url::fromRoute('user.pass.http')
    ->setRouteParameter('_format', $format)
    ->setAbsolute();
  $result = \Drupal::httpClient()
    ->post($password_reset_url
    ->toString(), [
    'body' => $this->serializer
      ->encode($request_body, $format),
    'headers' => [
      'Accept' => "application/{$format}",
    ],
    'http_errors' => FALSE,
    'cookies' => $this->cookies,
  ]);
  return $result;
}