You are here

protected function UserTest::assertRpcLogin in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Functional/UserTest.php \Drupal\Tests\jsonapi\Functional\UserTest::assertRpcLogin()
  2. 9 core/modules/jsonapi/tests/src/Functional/UserTest.php \Drupal\Tests\jsonapi\Functional\UserTest::assertRpcLogin()

Verifies that logging in with the given username and password works.

@internal

Parameters

string $username: The username to log in with.

string $password: The password to log in with.

File

core/modules/jsonapi/tests/src/Functional/UserTest.php, line 321

Class

UserTest
JSON:API integration test for the "User" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function assertRpcLogin(string $username, string $password) : void {
  $request_body = [
    'name' => $username,
    'pass' => $password,
  ];
  $request_options = [
    RequestOptions::HEADERS => [],
    RequestOptions::BODY => Json::encode($request_body),
  ];
  $response = $this
    ->request('POST', Url::fromRoute('user.login.http')
    ->setRouteParameter('_format', 'json'), $request_options);
  $this
    ->assertSame(200, $response
    ->getStatusCode());
}