/**
  * @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));
 }
예제 #2
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));
 }