You are here

public function OwnOrAdminConstraintValidatorTest::testValidate in Simple OAuth (OAuth2) & OpenID Connect 8

@covers ::validate @dataProvider validateProvider

File

tests/src/Unit/Plugin/Validation/Constraint/OwnOrAdminConstraintValidatorTest.php, line 26

Class

OwnOrAdminConstraintValidatorTest
Class OwnOrAdminConstraintValidatorTest.

Namespace

Drupal\Tests\simple_oauth\Unit\Plugin\Validation\Constraint

Code

public function testValidate($uid, $has_permission, $success) {
  $constraint = $this
    ->prophesize(OwnOrAdminConstraint::class);
  $account = $this
    ->prophesize(AccountInterface::class);
  $account
    ->id()
    ->willReturn(6);
  $account
    ->hasPermission('lorem ipsum dolor')
    ->willReturn($has_permission);
  $constraint
    ->getAccount()
    ->willReturn($account
    ->reveal());
  $constraint
    ->getPermission()
    ->willReturn('lorem ipsum dolor');
  $context = $this
    ->prophesize(ExecutionContext::class);
  $constraint_validator = new OwnOrAdminConstraintValidator();
  $constraint_validator
    ->initialize($context
    ->reveal());
  $revealed_constraint = $constraint
    ->reveal();
  $revealed_constraint->message = 'Foo';
  $constraint_validator
    ->validate($uid, $revealed_constraint);
  $method = $success ? 'shouldNotHaveBeenCalled' : 'shouldHaveBeenCalled';
  $context
    ->addViolation(Argument::type('string'), Argument::type('array'))
    ->{$method}();
}