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());
 }
예제 #2
0
 /**
  * @expectedException \Oro\Bundle\WorkflowBundle\Exception\WorkflowException
  * @expectedExceptionMessage Value of attribute "attribute" must be an object
  */
 public function testUpdateAclIdentitiesNotAnObjectException()
 {
     $workflowName = 'test_workflow';
     $step = new WorkflowStep();
     $step->setName('step');
     $attribute = new Attribute();
     $attribute->setName('attribute')->setOption('class', 'TestEntity');
     $entityAcl = new WorkflowEntityAcl();
     $entityAcl->setStep($step)->setAttribute($attribute->getName());
     $definition = new WorkflowDefinition();
     $definition->setName($workflowName)->setSteps(array($step))->setEntityAcls(array($entityAcl));
     $this->setWorkflow($workflowName, array($attribute));
     $workflowItem = new WorkflowItem();
     $workflowItem->setWorkflowName($workflowName)->setDefinition($definition)->setCurrentStep($step);
     $workflowItem->getData()->set($attribute->getName(), 'not_an_object');
     $this->manager->updateAclIdentities($workflowItem);
 }
예제 #3
0
 /**
  * @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));
 }
예제 #4
0
 /**
  * @param WorkflowEntityAcl $acl
  * @return WorkflowDefinition
  */
 public function removeEntityAcl(WorkflowEntityAcl $acl)
 {
     $attributeStep = $acl->getAttributeStepKey();
     if ($this->hasEntityAclByAttributeStep($attributeStep)) {
         $acl = $this->getEntityAclByAttributeStep($attributeStep);
         $this->entityAcls->removeElement($acl);
     }
     return $this;
 }
 /**
  * @param WorkflowDefinition $workflowDefinition
  * @param Workflow $workflow
  */
 protected function setEntityAcls(WorkflowDefinition $workflowDefinition, Workflow $workflow)
 {
     $entityAcls = array();
     foreach ($workflow->getAttributeManager()->getEntityAttributes() as $attribute) {
         foreach ($workflow->getStepManager()->getSteps() as $step) {
             $updatable = $attribute->isEntityUpdateAllowed() && $step->isEntityUpdateAllowed($attribute->getName());
             $deletable = $attribute->isEntityDeleteAllowed() && $step->isEntityDeleteAllowed($attribute->getName());
             if (!$updatable || !$deletable) {
                 $entityAcl = new WorkflowEntityAcl();
                 $entityAcl->setAttribute($attribute->getName())->setStep($workflowDefinition->getStepByName($step->getName()))->setEntityClass($attribute->getOption('class'))->setUpdatable($updatable)->setDeletable($deletable);
                 $entityAcls[] = $entityAcl;
             }
         }
     }
     $workflowDefinition->setEntityAcls($entityAcls);
 }
예제 #6
0
 /**
  * @expectedException \Oro\Bundle\WorkflowBundle\Exception\WorkflowException
  * @expectedExceptionMessage Workflow entity ACL with ID 1 doesn't have workflow step
  */
 public function testGetAttributeStepKeyNoStepException()
 {
     $this->setEntityId(1);
     $this->entityAcl->getAttributeStepKey();
 }
예제 #7
0
 public function testSetGetAclIdentities()
 {
     $firstStep = new WorkflowStep();
     $firstStep->setName('first_step');
     $secondStep = new WorkflowStep();
     $secondStep->setName('second_step');
     $this->workflowDefinition->setSteps(array($firstStep, $secondStep));
     $firstEntityAcl = new WorkflowEntityAcl();
     $firstEntityAcl->setStep($firstStep)->setAttribute('first_attribute');
     $secondEntityAcl = new WorkflowEntityAcl();
     $secondEntityAcl->setStep($secondStep)->setAttribute('second_attribute');
     // default
     $this->assertEmpty($this->workflowDefinition->getEntityAcls()->toArray());
     // adding
     $this->workflowDefinition->setEntityAcls(array($firstEntityAcl));
     $this->assertCount(1, $this->workflowDefinition->getEntityAcls());
     $this->assertEquals($firstEntityAcl, $this->workflowDefinition->getEntityAcls()->first());
     // merging
     $this->workflowDefinition->setEntityAcls(array($firstEntityAcl, $secondEntityAcl));
     $this->assertCount(2, $this->workflowDefinition->getEntityAcls());
     $entityAcls = array_values($this->workflowDefinition->getEntityAcls()->toArray());
     $this->assertEquals($firstEntityAcl, $entityAcls[0]);
     $this->assertEquals($secondEntityAcl, $entityAcls[1]);
     // removing
     $this->workflowDefinition->setEntityAcls(array($secondEntityAcl));
     $this->assertCount(1, $this->workflowDefinition->getEntityAcls());
     $this->assertEquals($secondEntityAcl, $this->workflowDefinition->getEntityAcls()->first());
     // resetting
     $this->workflowDefinition->setEntityAcls(array());
     $this->assertEmpty($this->workflowDefinition->getEntityAcls()->toArray());
 }
예제 #8
0
 /**
  * @param WorkflowEntityAcl $acl
  * @return WorkflowEntityAcl
  */
 public function import(WorkflowEntityAcl $acl)
 {
     $this->setAttribute($acl->getAttribute())->setStep($this->getDefinition()->getStepByName($acl->getStep()->getName()))->setEntityClass($acl->getEntityClass())->setUpdatable($acl->isUpdatable())->setDeletable($acl->isDeletable());
     return $this;
 }