/** * @dataProvider buildFilterConstraintProvider */ public function testGetAclConditionData($userId, $organizationId, $isGranted, $accessLevel, $ownerType, $targetEntityClassName, $expectedConstraint, $expectedGroup = '') { $this->buildTestTree(); if ($ownerType !== null) { $this->metadataProvider->setMetadata(self::TEST_ENTITY, new OwnershipMetadata($ownerType, 'owner', 'owner_id', 'organization', 'organization_id')); } /** @var OneShotIsGrantedObserver $aclObserver */ $aclObserver = null; $this->aclVoter->expects($this->any())->method('addOneShotIsGrantedObserver')->will($this->returnCallback(function ($observer) use(&$aclObserver, &$accessLevel) { $aclObserver = $observer; /** @var OneShotIsGrantedObserver $aclObserver */ $aclObserver->setAccessLevel($accessLevel); })); $user = new User($userId); $organization = new Organization($organizationId); $user->addOrganization($organization); $token = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Authentication\\Token\\UsernamePasswordOrganizationToken')->disableOriginalConstructor()->getMock(); $token->expects($this->any())->method('getUser')->will($this->returnValue($user)); $token->expects($this->any())->method('getOrganizationContext')->will($this->returnValue($organization)); /** @var \PHPUnit_Framework_MockObject_MockObject|AclGroupProviderInterface $aclGroupProvider */ $aclGroupProvider = $this->getMock('Oro\\Bundle\\SecurityBundle\\Acl\\Group\\AclGroupProviderInterface'); $aclGroupProvider->expects($this->any())->method('getGroup')->willReturn($expectedGroup); $this->builder->setAclGroupProvider($aclGroupProvider); $this->securityContext->expects($this->any())->method('isGranted')->with($this->equalTo('VIEW'), $this->callback(function (ObjectIdentity $identity) use($targetEntityClassName, $expectedGroup) { $this->assertEquals('entity', $identity->getIdentifier()); $this->assertStringEndsWith($targetEntityClassName, $identity->getType()); if ($expectedGroup) { $this->assertStringStartsWith($expectedGroup, $identity->getType()); } return true; }))->will($this->returnValue($isGranted)); $this->securityContext->expects($this->any())->method('getToken')->will($this->returnValue($userId ? $token : null)); $result = $this->builder->getAclConditionData($targetEntityClassName); $this->assertEquals($expectedConstraint, $result); }