function RestLoginHttpTest::loginRequest

Same name and namespace in other branches
  1. main core/modules/rest/tests/src/Functional/RestLoginHttpTest.php \Drupal\Tests\rest\Functional\RestLoginHttpTest::loginRequest()

Executes a login HTTP request for a given serialization format.

Parameters

string|null $name: The username.

string|null $pass: The user password.

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

Return value

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

4 calls to RestLoginHttpTest::loginRequest()
RestLoginHttpTest::doTestGlobalLoginFloodControl in core/modules/rest/tests/src/Functional/RestLoginHttpTest.php
Tests the global login flood control for a given serialization format.
RestLoginHttpTest::doTestLogin in core/modules/rest/tests/src/Functional/RestLoginHttpTest.php
Do login testing for a given serialization format.
RestLoginHttpTest::doTestLogoutCsrfProtection in core/modules/rest/tests/src/Functional/RestLoginHttpTest.php
Tests csrf protection of User Logout route for given serialization format.
RestLoginHttpTest::doTestPerUserLoginFloodControl in core/modules/rest/tests/src/Functional/RestLoginHttpTest.php
Tests the per-user login flood control for a given serialization format.

File

core/modules/rest/tests/src/Functional/RestLoginHttpTest.php, line 80

Class

RestLoginHttpTest
Tests login and password reset via direct HTTP.

Namespace

Drupal\Tests\rest\Functional

Code

protected function loginRequest($name, $pass, $format = 'json') : ResponseInterface {
  $user_login_url = Url::fromRoute('rest.login')->setRouteParameter('_format', $format)
    ->setAbsolute();
  $request_body = [];
  if (isset($name)) {
    $request_body['name'] = $name;
  }
  if (isset($pass)) {
    $request_body['pass'] = $pass;
  }
  $result = \Drupal::httpClient()->post($user_login_url->toString(), [
    'body' => $this->serializer
      ->encode($request_body, $format),
    'headers' => [
      'Accept' => "application/{$format}",
    ],
    'http_errors' => FALSE,
    'cookies' => $this->cookies,
  ]);
  return $result;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.