View source
<?php
namespace Drupal\Tests\password_policy_consecutive\Unit;
use Drupal\Tests\UnitTestCase;
class ConsecutiveCharactersTest extends UnitTestCase {
public function testConsecutiveCharacters($count, $password, $result) {
$characters = $this
->getMockBuilder('Drupal\\password_policy_consecutive\\Plugin\\PasswordConstraint\\ConsecutiveCharacters')
->disableOriginalConstructor()
->setMethods([
'getConfiguration',
't',
])
->getMock();
$characters
->method('getConfiguration')
->willReturn([
'max_consecutive_characters' => $count,
]);
$user = $this
->getMockBuilder('Drupal\\user\\Entity\\User')
->disableOriginalConstructor()
->getMock();
$this
->assertEquals($characters
->validate($password, $user)
->isValid(), $result);
}
public function passwordsDataProvider() {
return [
[
2,
'PasSword',
TRUE,
],
[
3,
'Password',
TRUE,
],
[
4,
'PasSword',
TRUE,
],
[
5,
'PasSsSworD',
TRUE,
],
[
2,
'Password',
FALSE,
],
[
3,
'Passsword',
FALSE,
],
[
4,
'paSSWOOOORD',
FALSE,
],
[
5,
'Password1233333',
FALSE,
],
];
}
}