public function testImport() { $step = new WorkflowStep(); $step->setName('step'); $entityAcl = new WorkflowEntityAcl(); $entityAcl->setStep($step)->setAttribute('attribute'); $this->aclIdentity->setEntityId(123); $this->aclIdentity->setAcl($entityAcl); $newAclIdentity = new WorkflowEntityAclIdentity(); $newAclIdentity->setAcl($entityAcl); $this->assertEquals($newAclIdentity, $newAclIdentity->import($this->aclIdentity)); $this->assertEquals(123, $newAclIdentity->getEntityId()); $this->assertEquals($this->aclIdentity->getAclAttributeStepKey(), $newAclIdentity->getAclAttributeStepKey()); }
/** * @param WorkflowItem $workflowItem * @return WorkflowItem * @throws WorkflowException */ public function updateAclIdentities(WorkflowItem $workflowItem) { $workflow = $this->workflowRegistry->getWorkflow($workflowItem->getWorkflowName()); $definition = $workflowItem->getDefinition(); $currentStepName = $workflowItem->getCurrentStep()->getName(); $aclIdentities = array(); foreach ($definition->getEntityAcls() as $entityAcl) { if ($entityAcl->getStep()->getName() == $currentStepName) { $attributeName = $entityAcl->getAttribute(); $attribute = $workflow->getAttributeManager()->getAttribute($attributeName); $entity = $workflowItem->getData()->get($attributeName); if (!$entity) { continue; } if (!is_object($entity)) { throw new WorkflowException(sprintf('Value of attribute "%s" must be an object', $attributeName)); } $aclIdentity = new WorkflowEntityAclIdentity(); $aclIdentity->setAcl($entityAcl)->setEntityClass($attribute->getOption('class'))->setEntityId($this->doctrineHelper->getSingleEntityIdentifier($entity)); $aclIdentities[] = $aclIdentity; } } $workflowItem->setAclIdentities($aclIdentities); return $workflowItem; }
/** * @param int $expected * @param object $object * @param array $attributes * @param bool $updatable * @param bool $deletable * @dataProvider voteDataProvider */ public function testVote($expected, $object, array $attributes = [], $updatable = true, $deletable = true) { $entityAcl = new WorkflowEntityAcl(); $entityAcl->setEntityClass('WorkflowEntity')->setUpdatable($updatable)->setDeletable($deletable); $aclIdentity = new WorkflowEntityAclIdentity(); $aclIdentity->setAcl($entityAcl); $identifier = null; if ($object instanceof WorkflowEntity) { $identifier = $object->getId(); $this->setDoctrineHelper('WorkflowEntity', $identifier); } elseif ($object instanceof ObjectIdentity && filter_var($object->getIdentifier(), FILTER_VALIDATE_INT)) { $identifier = $object->getIdentifier(); } $this->setRegistryRepositories([$entityAcl], 'WorkflowEntity', $identifier, [$aclIdentity]); $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'); $this->assertEquals($expected, $this->voter->vote($token, $object, $attributes)); }
public function testSetGetAclIdentities() { $firstStep = new WorkflowStep(); $firstStep->setName('first_step'); $secondStep = new WorkflowStep(); $secondStep->setName('second_step'); $firstEntityAcl = new WorkflowEntityAcl(); $firstEntityAcl->setStep($firstStep)->setAttribute('first_attribute'); $secondEntityAcl = new WorkflowEntityAcl(); $secondEntityAcl->setStep($secondStep)->setAttribute('second_attribute'); $firstAclIdentity = new WorkflowEntityAclIdentity(); $firstAclIdentity->setAcl($firstEntityAcl); $alternativeFirstAclIdentity = new WorkflowEntityAclIdentity(); $alternativeFirstAclIdentity->setAcl($firstEntityAcl); $secondAclIdentity = new WorkflowEntityAclIdentity(); $secondAclIdentity->setAcl($secondEntityAcl); // default $this->assertEmpty($this->workflowItem->getAclIdentities()->toArray()); // adding $this->workflowItem->setAclIdentities(array($firstAclIdentity)); $this->assertCount(1, $this->workflowItem->getAclIdentities()); $this->assertEquals($firstAclIdentity, $this->workflowItem->getAclIdentities()->first()); // merging $this->workflowItem->setAclIdentities(array($alternativeFirstAclIdentity, $secondAclIdentity)); $this->assertCount(2, $this->workflowItem->getAclIdentities()); $aclIdentities = array_values($this->workflowItem->getAclIdentities()->toArray()); $this->assertEquals($firstAclIdentity, $aclIdentities[0]); $this->assertEquals($secondAclIdentity, $aclIdentities[1]); // removing $this->workflowItem->setAclIdentities(array($secondAclIdentity)); $this->assertCount(1, $this->workflowItem->getAclIdentities()); $this->assertEquals($secondAclIdentity, $this->workflowItem->getAclIdentities()->first()); // resetting $this->workflowItem->setAclIdentities(array()); $this->assertEmpty($this->workflowItem->getAclIdentities()->toArray()); }