You are here

protected function ProtectedUserFieldConstraintValidatorTest::createValidator in Lightweight Directory Access Protocol (LDAP) 8.4

Creates a validator.

Return value

\Drupal\ldap_user\Plugin\Validation\Constraint\LdapProtectedUserFieldConstraintValidator Validator.

2 calls to ProtectedUserFieldConstraintValidatorTest::createValidator()
ProtectedUserFieldConstraintValidatorTest::testSuccess in ldap_user/tests/src/Unit/ProtectedUserFieldConstraintValidatorTest.php
Test validation.
ProtectedUserFieldConstraintValidatorTest::testValidate in ldap_user/tests/src/Unit/ProtectedUserFieldConstraintValidatorTest.php
Test validation.

File

ldap_user/tests/src/Unit/ProtectedUserFieldConstraintValidatorTest.php, line 32

Class

ProtectedUserFieldConstraintValidatorTest
Extended from core tests.

Namespace

Drupal\Tests\ldap_user\Unit

Code

protected function createValidator() : LdapProtectedUserFieldConstraintValidator {

  // Setup mocks that don't need to change.
  $unchanged_field = $this
    ->createMock(FieldItemListInterface::class);
  $unchanged_field
    ->expects($this
    ->any())
    ->method('getValue')
    ->willReturn('unchanged-value');
  $unchanged_account = $this
    ->createMock(UserInterface::class);
  $unchanged_account
    ->expects($this
    ->any())
    ->method('get')
    ->willReturn($unchanged_field);
  $user_storage = $this
    ->createMock(UserStorageInterface::class);
  $user_storage
    ->expects($this
    ->any())
    ->method('loadUnchanged')
    ->willReturn($unchanged_account);
  $current_user = $this
    ->createMock(AccountProxyInterface::class);
  $current_user
    ->expects($this
    ->any())
    ->method('id')
    ->willReturn('current-user');
  $validator = new LdapProtectedUserFieldConstraintValidator($user_storage, $current_user);
  $login_service = $this
    ->createMock(LoginValidatorLoginForm::class);
  $login_service
    ->expects($this
    ->any())
    ->method('validateCredentialsLoggedIn')
    ->willReturn(LoginValidatorBase::AUTHENTICATION_FAILURE_CREDENTIALS);
  $validator
    ->setLoginValidator($login_service);
  return $validator;
}