You are here

protected function UserLoginHttpTest::logoutRequest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Functional/UserLoginHttpTest.php \Drupal\Tests\user\Functional\UserLoginHttpTest::logoutRequest()
  2. 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\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;
}