You are here

protected function UserTest::assertRpcLogin in JSON:API 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/UserTest.php \Drupal\Tests\jsonapi\Functional\UserTest::assertRpcLogin()

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

Parameters

string $username: The username to log in with.

string $password: The password to log in with.

1 call to UserTest::assertRpcLogin()
UserTest::testPatchDxForSecuritySensitiveBaseFields in tests/src/Functional/UserTest.php
Tests PATCHing security-sensitive base fields of the logged in account.

File

tests/src/Functional/UserTest.php, line 337

Class

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

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function assertRpcLogin($username, $password) {
  $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());
}