protected function setUp()
 {
     if (!class_exists('Doctrine\\DBAL\\DriverManager')) {
         $this->markTestSkipped('The Doctrine2 DBAL is required for this test');
     }
     $this->ownerTree = new OwnerTree();
     $this->metadataProvider = new OwnershipMetadataProviderStub($this);
     $objectIdAccessor = new ObjectIdAccessor();
     /** @var \PHPUnit_Framework_MockObject_MockObject|OwnerTreeProvider $treeProviderMock */
     $treeProviderMock = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Owner\\OwnerTreeProvider')->disableOriginalConstructor()->getMock();
     $treeProviderMock->expects($this->any())->method('getTree')->will($this->returnValue($this->ownerTree));
     $configProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $configProvider->expects($this->any())->method('hasConfig')->willReturn(false);
     $this->container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $this->container->expects($this->any())->method('get')->will($this->returnValueMap([['oro_security.ownership_tree_provider.chain', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $treeProviderMock], ['oro_security.owner.metadata_provider.chain', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->metadataProvider], ['oro_security.acl.object_id_accessor', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $objectIdAccessor], ['oro_security.owner.entity_owner_accessor', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, new EntityOwnerAccessor($this->metadataProvider)], ['oro_entity_config.provider.security', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $configProvider]]));
     $decisionMaker = new EntityOwnershipDecisionMaker($treeProviderMock, $objectIdAccessor, new EntityOwnerAccessor($this->metadataProvider), $this->metadataProvider);
     $decisionMaker->setContainer($this->container);
     $this->strategy = new PermissionGrantingStrategy($decisionMaker, $this->metadataProvider);
     $this->selector = TestHelper::get($this)->createAclExtensionSelector($this->metadataProvider, $this->ownerTree, $decisionMaker);
     $this->context = new PermissionGrantingStrategyContext($this->selector);
     $contextLink = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->disableOriginalConstructor()->getMock();
     $contextLink->expects($this->any())->method('getService')->will($this->returnValue($this->context));
     $this->strategy->setContext($contextLink);
     $user = new User(1);
     $user->setUsername('TestUser');
     $this->sid = new UserSecurityIdentity('TestUser', get_class($user));
     $this->rsid = new RoleSecurityIdentity('TestRole');
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $token->expects($this->any())->method('getUser')->will($this->returnValue($user));
     $this->context->setSecurityToken($token);
     $this->context->setObject(new TestEntity('testId'));
     $this->map = new PermissionMap($this->selector);
 }
 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'));
     $this->metadataProvider->setMetadata($this->metadataProvider->getUserClass(), new OwnershipMetadata('BUSINESS_UNIT', 'owner', 'owner_id'));
     /** @var \PHPUnit_Framework_MockObject_MockObject|OwnerTreeProvider $treeProviderMock */
     $treeProviderMock = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Owner\\OwnerTreeProvider')->disableOriginalConstructor()->getMock();
     $treeProviderMock->expects($this->any())->method('getTree')->will($this->returnValue($this->tree));
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->any())->method('get')->will($this->returnValueMap([['oro_security.ownership_tree_provider.chain', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $treeProviderMock], ['oro_security.owner.metadata_provider.chain', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->metadataProvider], ['oro_security.acl.object_id_accessor', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, new ObjectIdAccessor()], ['oro_security.owner.entity_owner_accessor', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, new EntityOwnerAccessor($this->metadataProvider)]]));
     $this->decisionMaker = new EntityOwnershipDecisionMaker($treeProviderMock, new ObjectIdAccessor(), new EntityOwnerAccessor($this->metadataProvider), $this->metadataProvider);
     $this->decisionMaker->setContainer($container);
     $this->extension = TestHelper::get($this)->createEntityAclExtension($this->metadataProvider, $this->tree, new ObjectIdAccessor(), $this->decisionMaker);
 }
 public function testIsAssociatedWithUserForUserOwnedObject()
 {
     $this->buildTestTree();
     $this->metadataProvider->setMetadata('Oro\\Bundle\\SecurityBundle\\Tests\\Unit\\Acl\\Domain\\Fixtures\\Entity\\TestEntity', new OwnershipMetadata('USER', 'owner', 'owner_id'));
     $obj = new TestEntity(1);
     $obj1 = new TestEntity(1, $this->user1);
     $obj2 = new TestEntity(1, $this->user2);
     $obj3 = new TestEntity(1, $this->user3);
     $obj31 = new TestEntity(1, $this->user31);
     $obj4 = new TestEntity(1, $this->user4);
     $obj411 = new TestEntity(1, $this->user411);
     $this->assertFalse($this->decisionMaker->isAssociatedWithUser($this->user1, $obj));
     $this->assertTrue($this->decisionMaker->isAssociatedWithUser($this->user1, $obj1));
     $this->assertFalse($this->decisionMaker->isAssociatedWithUser($this->user2, $obj));
     $this->assertTrue($this->decisionMaker->isAssociatedWithUser($this->user2, $obj2));
     $this->assertFalse($this->decisionMaker->isAssociatedWithUser($this->user3, $obj));
     $this->assertTrue($this->decisionMaker->isAssociatedWithUser($this->user3, $obj3));
     $this->assertFalse($this->decisionMaker->isAssociatedWithUser($this->user3, $obj31));
     $this->assertFalse($this->decisionMaker->isAssociatedWithUser($this->user4, $obj));
     $this->assertFalse($this->decisionMaker->isAssociatedWithUser($this->user4, $obj3));
     $this->assertFalse($this->decisionMaker->isAssociatedWithUser($this->user4, $obj31));
     $this->assertTrue($this->decisionMaker->isAssociatedWithUser($this->user4, $obj4));
     $this->assertFalse($this->decisionMaker->isAssociatedWithUser($this->user4, $obj411));
 }
 /**
  * @dataProvider supportsDataProvider
  *
  * @param mixed $user
  * @param bool $expectedResult
  */
 public function testSupports($user, $expectedResult)
 {
     $this->securityFacade->expects($this->once())->method('getLoggedUser')->willReturn($user);
     $this->assertEquals($expectedResult, $this->decisionMaker->supports());
 }