public function testGetOrganization() { $metadataProvider = new OwnershipMetadataProviderStub($this); $accessor = new EntityOwnerAccessor($metadataProvider); $org = new \stdClass(); $obj = new TestEntity(1, null, $org); $metadataProvider->setMetadata(get_class($obj), new OwnershipMetadata(null, null, null, 'organization')); $this->assertSame($org, $accessor->getOrganization($obj)); }
/** * @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); }
public function testWarmUpCacheWithClassName() { $this->configProvider->expects($this->once())->method('hasConfig')->with(self::SOME_CLASS)->willReturn(true); $this->configProvider->expects($this->once())->method('getConfig')->with(self::SOME_CLASS)->willReturn($this->config); $this->cache->expects($this->once())->method('fetch')->with(self::SOME_CLASS)->willReturn(false); $this->cache->expects($this->once())->method('save')->with(self::SOME_CLASS); $this->provider->warmUpCache(self::SOME_CLASS); }
public function testObjIsGrantedUsesClassAcesIfNoApplicableObjectAceWasFound() { $obj = new TestEntity(1); $this->context->setObject($obj); $masks = $this->getMasks('VIEW', $obj); $aceMask = $this->getMaskBuilder('VIEW', $obj)->add('VIEW_GLOBAL')->get(); $acl = $this->getAcl(ObjectIdentity::fromDomainObject($obj)); $acl->insertClassAce($this->rsid, $aceMask); $this->assertTrue($this->strategy->isGranted($acl, $masks, array($this->rsid))); $this->metadataProvider->setMetadata(get_class($obj), $this->getOrganizationMetadata()); $this->assertFalse($this->strategy->isGranted($acl, $masks, array($this->rsid))); $this->metadataProvider->setMetadata(get_class($obj), $this->getBusinessUnitMetadata()); $this->metadataProvider->setMetadata(get_class($obj), $this->getUserMetadata()); }
/** * @param OwnershipMetadata $metadata * @param array $expected * * @dataProvider accessLevelProvider */ public function testGetAccessLevelNamesForNonRoot(OwnershipMetadata $metadata, array $expected) { $object = new ObjectIdentity('entity', '\\stdClass'); $this->metadataProvider->setMetadata('\\stdClass', $metadata); $this->assertEquals($expected, $this->extension->getAccessLevelNames($object)); }