function UserAuthenticationTest::testAuthenticateWithCorrectPassword

Tests the authenticate method with a correct password.

File

core/modules/user/tests/src/Unit/UserAuthenticationTest.php, line 130

Class

UserAuthenticationTest
Tests Drupal\user\UserAuthentication.

Namespace

Drupal\Tests\user\Unit

Code

public function testAuthenticateWithCorrectPassword() : void {
  $testUser = $this->createPartialMock(User::class, [
    'id',
    'getPassword',
  ]);
  $this->userStorage
    ->expects($this->once())
    ->method('loadByProperties')
    ->with([
    'name' => $this->username,
  ])
    ->willReturn([
    $testUser,
  ]);
  $this->passwordService
    ->method('check')
    ->willReturn(TRUE);
  $user = $this->userAuth
    ->lookupAccount($this->username);
  $this->assertTrue($this->userAuth
    ->authenticateAccount($user, $this->password));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.