public function testUpdateAclIdentities() { $entity = new \DateTime(); $entityIdentifier = 42; $workflowName = 'test_workflow'; $firstStep = new WorkflowStep(); $firstStep->setName('first_step'); $secondStep = new WorkflowStep(); $secondStep->setName('second_step'); $firstAttribute = new Attribute(); $firstAttribute->setName('first_attribute')->setOption('class', 'FirstTestEntity'); $secondAttribute = new Attribute(); $secondAttribute->setName('second_attribute')->setOption('class', 'SecondTestEntity'); $firstEntityAcl = new WorkflowEntityAcl(); $firstEntityAcl->setStep($firstStep)->setAttribute($firstAttribute->getName()); $secondEntityAcl = new WorkflowEntityAcl(); $secondEntityAcl->setStep($secondStep)->setAttribute($firstAttribute->getName()); $thirdEntityAcl = new WorkflowEntityAcl(); $thirdEntityAcl->setStep($secondStep)->setAttribute($secondAttribute->getName()); $definition = new WorkflowDefinition(); $definition->setName($workflowName)->setSteps(array($firstStep, $secondStep))->setEntityAcls(array($firstEntityAcl, $secondEntityAcl, $thirdEntityAcl)); $this->setWorkflow($workflowName, array($firstAttribute, $secondAttribute)); $this->doctrineHelper->expects($this->any())->method('getSingleEntityIdentifier')->with($entity)->will($this->returnValue($entityIdentifier)); $workflowItem = new WorkflowItem(); $workflowItem->setWorkflowName($workflowName)->setDefinition($definition)->setCurrentStep($secondStep); $workflowItem->getData()->set($firstAttribute->getName(), $entity); $this->assertEmpty($workflowItem->getAclIdentities()->toArray()); $this->assertEquals($workflowItem, $this->manager->updateAclIdentities($workflowItem)); $this->assertCount(1, $workflowItem->getAclIdentities()); /** @var WorkflowEntityAclIdentity $aclIdentity */ $aclIdentity = $workflowItem->getAclIdentities()->first(); $this->assertEquals($secondEntityAcl, $aclIdentity->getAcl()); $this->assertEquals($firstAttribute->getOption('class'), $aclIdentity->getEntityClass()); $this->assertEquals($entityIdentifier, $aclIdentity->getEntityId()); $this->assertEquals($workflowItem, $aclIdentity->getWorkflowItem()); }
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()); }