You are here

protected function ProtectedUserFieldConstraintValidatorTest::createValidator in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/ProtectedUserFieldConstraintValidatorTest.php \Drupal\Tests\user\Unit\Plugin\Validation\Constraint\ProtectedUserFieldConstraintValidatorTest::createValidator()
  2. 9 core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/ProtectedUserFieldConstraintValidatorTest.php \Drupal\Tests\user\Unit\Plugin\Validation\Constraint\ProtectedUserFieldConstraintValidatorTest::createValidator()
1 call to ProtectedUserFieldConstraintValidatorTest::createValidator()
ProtectedUserFieldConstraintValidatorTest::testValidate in core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/ProtectedUserFieldConstraintValidatorTest.php
@covers ::validate

File

core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/ProtectedUserFieldConstraintValidatorTest.php, line 20

Class

ProtectedUserFieldConstraintValidatorTest
@coversDefaultClass \Drupal\user\Plugin\Validation\Constraint\ProtectedUserFieldConstraintValidator @group user

Namespace

Drupal\Tests\user\Unit\Plugin\Validation\Constraint

Code

protected function createValidator() {

  // Setup mocks that don't need to change.
  $unchanged_field = $this
    ->createMock('Drupal\\Core\\Field\\FieldItemListInterface');
  $unchanged_field
    ->expects($this
    ->any())
    ->method('getValue')
    ->willReturn('unchanged-value');
  $unchanged_account = $this
    ->createMock('Drupal\\user\\UserInterface');
  $unchanged_account
    ->expects($this
    ->any())
    ->method('get')
    ->willReturn($unchanged_field);
  $user_storage = $this
    ->createMock('Drupal\\user\\UserStorageInterface');
  $user_storage
    ->expects($this
    ->any())
    ->method('loadUnchanged')
    ->willReturn($unchanged_account);
  $current_user = $this
    ->createMock('Drupal\\Core\\Session\\AccountProxyInterface');
  $current_user
    ->expects($this
    ->any())
    ->method('id')
    ->willReturn('current-user');
  return new ProtectedUserFieldConstraintValidator($user_storage, $current_user);
}