function UserLoginHttpTest::loginRequest

Same name and namespace in other branches
  1. 11.x core/modules/user/tests/src/Functional/UserLoginHttpTest.php \Drupal\Tests\user\Functional\UserLoginHttpTest::loginRequest()
  2. 10 core/modules/user/tests/src/Functional/UserLoginHttpTest.php \Drupal\Tests\user\Functional\UserLoginHttpTest::loginRequest()
  3. 8.9.x core/modules/user/tests/src/Functional/UserLoginHttpTest.php \Drupal\Tests\user\Functional\UserLoginHttpTest::loginRequest()

Executes a login HTTP request for a given serialization format.

Parameters

string $name: The username.

string $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 UserLoginHttpTest::loginRequest()
UserLoginHttpTest::doTestGlobalLoginFloodControl in core/modules/user/tests/src/Functional/UserLoginHttpTest.php
Tests the global login flood control for a given serialization format.
UserLoginHttpTest::doTestLogin in core/modules/user/tests/src/Functional/UserLoginHttpTest.php
Do login testing for a given serialization format.
UserLoginHttpTest::doTestLogoutCsrfProtection in core/modules/user/tests/src/Functional/UserLoginHttpTest.php
Tests csrf protection of User Logout route for given serialization format.
UserLoginHttpTest::doTestPerUserLoginFloodControl in core/modules/user/tests/src/Functional/UserLoginHttpTest.php
Tests the per-user login flood control for a given serialization format.

File

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

Class

UserLoginHttpTest
Tests login and password reset via direct HTTP.

Namespace

Drupal\Tests\user\Functional

Code

protected function loginRequest($name, $pass, $format = 'json') {
  $user_login_url = Url::fromRoute('user.login.http')->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.