protected function UserLoginHttpTest::logoutRequest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/user/tests/src/Functional/UserLoginHttpTest.php \Drupal\Tests\user\Functional\UserLoginHttpTest::logoutRequest()
- 9 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.
File
- core/
modules/ user/ tests/ src/ Functional/ UserLoginHttpTest.php, line 441
Class
- UserLoginHttpTest
- Tests login and password reset via direct HTTP.
Namespace
Drupal\Tests\user\FunctionalCode
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;
}