function RestLoginHttpTest::logoutRequest
Same name and namespace in other branches
- 11.x core/modules/rest/tests/src/Functional/RestLoginHttpTest.php \Drupal\Tests\rest\Functional\RestLoginHttpTest::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/ rest/ tests/ src/ Functional/ RestLoginHttpTest.php, line 444
Class
- RestLoginHttpTest
- Tests login and password reset via direct HTTP.
Namespace
Drupal\Tests\rest\FunctionalCode
protected function logoutRequest(string $format = 'json', string $logout_token = '') : ResponseInterface {
/** @var \GuzzleHttp\Client $client */
$client = $this->container
->get('http_client');
$user_logout_url = Url::fromRoute('rest.logout')->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.