function UserAuthTest::testAuthenticateWithZeroPassword

Same name and namespace in other branches
  1. 9 core/modules/user/tests/src/Unit/UserAuthTest.php \Drupal\Tests\user\Unit\UserAuthTest::testAuthenticateWithZeroPassword()
  2. 10 core/modules/user/tests/src/Unit/UserAuthTest.php \Drupal\Tests\user\Unit\UserAuthTest::testAuthenticateWithZeroPassword()
  3. 11.x core/modules/user/tests/src/Unit/UserAuthTest.php \Drupal\Tests\user\Unit\UserAuthTest::testAuthenticateWithZeroPassword()

Tests the authenticate method with a correct password.

We discovered in https://www.drupal.org/node/2563751 that logging in with a password that is literally "0" was not possible. This test ensures that this regression can't happen again.

@covers ::authenticate

File

core/modules/user/tests/src/Unit/UserAuthTest.php, line 173

Class

UserAuthTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21user%21src%21UserAuth.php/class/UserAuth/8.9.x" title="Validates user authentication credentials." class="local">\Drupal\user\UserAuth</a> @group user

Namespace

Drupal\Tests\user\Unit

Code

public function testAuthenticateWithZeroPassword() {
    $this->testUser
        ->expects($this->once())
        ->method('id')
        ->will($this->returnValue(2));
    $this->userStorage
        ->expects($this->once())
        ->method('loadByProperties')
        ->with([
        'name' => $this->username,
    ])
        ->will($this->returnValue([
        $this->testUser,
    ]));
    $this->passwordService
        ->expects($this->once())
        ->method('check')
        ->with(0, 0)
        ->will($this->returnValue(TRUE));
    $this->assertsame(2, $this->userAuth
        ->authenticate($this->username, 0));
}

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