protected function setUp()
 {
     $this->tree = new OwnerTree();
     $this->metadataProvider = new OwnershipMetadataProviderStub($this);
     $this->metadataProvider->setMetadata($this->metadataProvider->getOrganizationClass(), new OwnershipMetadata());
     $this->metadataProvider->setMetadata($this->metadataProvider->getBusinessUnitClass(), new OwnershipMetadata('BUSINESS_UNIT', 'owner', 'owner_id', 'organization'));
     $this->metadataProvider->setMetadata($this->metadataProvider->getUserClass(), new OwnershipMetadata('BUSINESS_UNIT', 'owner', 'owner_id', 'organization'));
     $treeProvider = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Owner\\OwnerTreeProvider')->disableOriginalConstructor()->getMock();
     $treeProvider->expects($this->any())->method('getTree')->will($this->returnValue($this->tree));
     $this->decisionMaker = new EntityOwnershipDecisionMaker($treeProvider, new ObjectIdAccessor(), new EntityOwnerAccessor($this->metadataProvider), $this->metadataProvider);
 }
 protected function setUp()
 {
     $this->tree = new OwnerTree();
     $treeProvider = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Owner\\OwnerTreeProvider')->disableOriginalConstructor()->getMock();
     $treeProvider->expects($this->any())->method('getTree')->will($this->returnValue($this->tree));
     $entityMetadataProvider = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Metadata\\EntitySecurityMetadataProvider')->disableOriginalConstructor()->getMock();
     $entityMetadataProvider->expects($this->any())->method('isProtectedEntity')->will($this->returnValue(true));
     $this->metadataProvider = new OwnershipMetadataProviderStub($this);
     $this->metadataProvider->setMetadata($this->metadataProvider->getOrganizationClass(), new OwnershipMetadata());
     $this->metadataProvider->setMetadata($this->metadataProvider->getBusinessUnitClass(), new OwnershipMetadata('BUSINESS_UNIT', 'owner', 'owner_id'));
     $this->metadataProvider->setMetadata($this->metadataProvider->getUserClass(), new OwnershipMetadata('BUSINESS_UNIT', 'owner', 'owner_id'));
     $this->securityContext = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $securityContextLink = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->disableOriginalConstructor()->getMock();
     $securityContextLink->expects($this->any())->method('getService')->will($this->returnValue($this->securityContext));
     $this->aclVoter = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Acl\\Voter\\AclVoter')->disableOriginalConstructor()->getMock();
     $this->builder = new OwnershipConditionDataBuilder($securityContextLink, new ObjectIdAccessor(), $entityMetadataProvider, $this->metadataProvider, $treeProvider, $this->aclVoter);
 }
 /**
  * @dataProvider decideIsGrantingProvider
  */
 public function testDecideIsGranting($triggeredMask, $user, $object, $expectedResult)
 {
     $this->buildTestTree();
     if ($object instanceof TestEntity && $object->getOwner() !== null) {
         $owner = $object->getOwner();
         if (is_a($owner, $this->metadataProvider->getOrganizationClass())) {
             $this->metadataProvider->setMetadata(get_class($object), new OwnershipMetadata('ORGANIZATION', 'owner', 'owner_id'));
         } elseif (is_a($owner, $this->metadataProvider->getBusinessUnitClass())) {
             $this->metadataProvider->setMetadata(get_class($object), new OwnershipMetadata('BUSINESS_UNIT', 'owner', 'owner_id'));
         } elseif (is_a($owner, $this->metadataProvider->getUserClass())) {
             $this->metadataProvider->setMetadata(get_class($object), new OwnershipMetadata('USER', 'owner', 'owner_id'));
         }
     }
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $token->expects($this->any())->method('getUser')->will($this->returnValue($user));
     $this->assertEquals($expectedResult, $this->extension->decideIsGranting($triggeredMask, $object, $token));
 }
Пример #4
0
 /**
  * @dataProvider decideIsGrantingProvider
  */
 public function testDecideIsGranting($triggeredMask, $user, $organization, $object, $expectedResult)
 {
     $this->buildTestTree();
     if ($object instanceof TestEntity && $object->getOwner() !== null) {
         $owner = $object->getOwner();
         if (is_a($owner, $this->metadataProvider->getOrganizationClass())) {
             $this->metadataProvider->setMetadata(get_class($object), new OwnershipMetadata('ORGANIZATION', 'owner', 'owner_id', 'organization'));
         } elseif (is_a($owner, $this->metadataProvider->getBusinessUnitClass())) {
             $this->metadataProvider->setMetadata(get_class($object), new OwnershipMetadata('BUSINESS_UNIT', 'owner', 'owner_id', 'organization'));
         } elseif (is_a($owner, $this->metadataProvider->getUserClass())) {
             $this->metadataProvider->setMetadata(get_class($object), new OwnershipMetadata('USER', 'owner', 'owner_id', 'organization'));
         }
     }
     $token = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Authentication\\Token\\UsernamePasswordOrganizationToken')->disableOriginalConstructor()->getMock();
     $token->expects($this->any())->method('getOrganizationContext')->will($this->returnValue($organization));
     $token->expects($this->any())->method('getUser')->will($this->returnValue($user));
     $this->assertEquals($expectedResult, $this->extension->decideIsGranting($triggeredMask, $object, $token));
 }