function UserLoginHttpTest::logoutRequest

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

Executes a logout HTTP request for a given serialization format.

Parameters

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

string $logout_token: The csrf token for user logout.

Return value

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

3 calls to UserLoginHttpTest::logoutRequest()
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 445

Class

UserLoginHttpTest
Tests login and password reset via direct HTTP.

Namespace

Drupal\Tests\user\Functional

Code

protected function logoutRequest($format = 'json', $logout_token = '') {
    
    /** @var \GuzzleHttp\Client $client */
    $client = $this->container
        ->get('http_client');
    $user_logout_url = Url::fromRoute('user.logout.http')->setRouteParameter('_format', $format)
        ->setAbsolute();
    if ($logout_token) {
        $user_logout_url->setOption('query', [
            'token' => $logout_token,
        ]);
    }
    $post_options = [
        'headers' => [
            'Accept' => "application/{$format}",
        ],
        'http_errors' => FALSE,
        'cookies' => $this->cookies,
    ];
    $response = $client->post($user_logout_url->toString(), $post_options);
    return $response;
}

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