function UserLoginHttpTest::loginRequest

Same name and namespace in other branches
  1. 9 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. 11.x core/modules/user/tests/src/Functional/UserLoginHttpTest.php \Drupal\Tests\user\Functional\UserLoginHttpTest::loginRequest()

Executes a login HTTP request.

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::doTestLogin in core/modules/user/tests/src/Functional/UserLoginHttpTest.php
Do login testing for a given serialization format.
UserLoginHttpTest::testGlobalLoginFloodControl in core/modules/user/tests/src/Functional/UserLoginHttpTest.php
Tests the global login flood control.
UserLoginHttpTest::testLogoutCsrfProtection in core/modules/user/tests/src/Functional/UserLoginHttpTest.php
Test csrf protection of User Logout route.
UserLoginHttpTest::testPerUserLoginFloodControl in core/modules/user/tests/src/Functional/UserLoginHttpTest.php
Test the per-user login flood control.

File

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

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.