You are here

protected function UserLoginHttpTest::passwordRequest in Drupal 9

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

Executes a password HTTP request.

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.

1 call to UserLoginHttpTest::passwordRequest()
UserLoginHttpTest::doTestPasswordReset in core/modules/user/tests/src/Functional/UserLoginHttpTest.php
Do password reset testing for given format and account.

File

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

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