function ProtectedUserFieldConstraintValidatorTest::createValidator

Same name in other branches
  1. 8.9.x core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/ProtectedUserFieldConstraintValidatorTest.php \Drupal\Tests\user\Unit\Plugin\Validation\Constraint\ProtectedUserFieldConstraintValidatorTest::createValidator()
  2. 10 core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/ProtectedUserFieldConstraintValidatorTest.php \Drupal\Tests\user\Unit\Plugin\Validation\Constraint\ProtectedUserFieldConstraintValidatorTest::createValidator()
  3. 11.x 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);
}

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