/**
  * @param WorkflowDefinition $workflowDefinition
  * @param Workflow $workflow
  */
 protected function setSteps(WorkflowDefinition $workflowDefinition, Workflow $workflow)
 {
     $workflowSteps = array();
     foreach ($workflow->getStepManager()->getSteps() as $step) {
         $workflowStep = new WorkflowStep();
         $workflowStep->setName($step->getName())->setLabel($step->getLabel())->setStepOrder($step->getOrder())->setFinal($step->isFinal());
         $workflowSteps[] = $workflowStep;
     }
     $workflowDefinition->setSteps($workflowSteps);
 }
Esempio n. 2
0
 public function testImport()
 {
     $this->step->setName('test');
     $this->step->setLabel('test');
     $this->step->setStepOrder(1);
     $this->step->setFinal(true);
     $newStep = new WorkflowStep();
     $this->assertEquals($newStep, $newStep->import($this->step));
     $this->assertEquals('test', $newStep->getName());
     $this->assertEquals('test', $newStep->getLabel());
     $this->assertEquals(1, $newStep->getStepOrder());
     $this->assertTrue($newStep->isFinal());
 }
 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());
 }
Esempio n. 4
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);
 }
Esempio n. 5
0
 public function testImport()
 {
     $step = new WorkflowStep();
     $step->setName('step');
     $definition = new WorkflowDefinition();
     $definition->addStep($step);
     $this->entityAcl->setAttribute('attribute');
     $this->entityAcl->setStep($step);
     $this->entityAcl->setEntityClass('TestEntity');
     $this->entityAcl->setUpdatable(false);
     $this->entityAcl->setDeletable(false);
     $newEntityAcl = new WorkflowEntityAcl();
     $newEntityAcl->setDefinition($definition);
     $this->assertEquals($newEntityAcl, $newEntityAcl->import($this->entityAcl));
     $this->assertEquals('attribute', $newEntityAcl->getAttribute());
     $this->assertEquals($step, $newEntityAcl->getStep());
     $this->assertEquals('TestEntity', $newEntityAcl->getEntityClass());
     $this->assertFalse($this->entityAcl->isUpdatable());
     $this->assertFalse($this->entityAcl->isDeletable());
     $this->assertEquals($this->entityAcl->getAttributeStepKey(), $newEntityAcl->getAttributeStepKey());
 }
 /**
  * @dataProvider validateExceptionsDataProvider
  */
 public function testValidateExceptions($workflowException, $expectedViolations)
 {
     $workflowName = 'test_workflow';
     $workflowItem = $this->getMock('Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowItem');
     $workflowItem->expects($this->any())->method('getWorkflowName')->will($this->returnValue($workflowName));
     $currentStep = new WorkflowStep();
     $currentStep->setName('test_step');
     $workflowItem->expects($this->any())->method('getCurrentStep')->will($this->returnValue($currentStep));
     $transitionName = 'test_transition';
     $constraint = new TransitionIsAllowed($workflowItem, $transitionName);
     $workflow = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\Workflow')->disableOriginalConstructor()->getMock();
     $this->registry->expects($this->once())->method('getWorkflow')->with($workflowName)->will($this->returnValue($workflow));
     $workflow->expects($this->once())->method('isTransitionAllowed')->with($workflowItem, $transitionName, $this->isInstanceOf('Doctrine\\Common\\Collections\\Collection'), true)->will($this->throwException($workflowException));
     $value = new WorkflowData();
     $context = $this->getMock('Symfony\\Component\\Validator\\ExecutionContextInterface');
     foreach (array_values($expectedViolations) as $index => $expectedViolation) {
         list($message, $params) = array_pad((array) $expectedViolation, 2, array());
         $context->expects($this->at($index))->method('addViolation')->with($message, $params);
     }
     $this->validator->initialize($context);
     $this->validator->validate($value, $constraint);
 }
Esempio n. 7
0
 /**
  * @param WorkflowStep $workflowStep
  * @return WorkflowStep
  */
 public function import(WorkflowStep $workflowStep)
 {
     $this->setName($workflowStep->getName())->setLabel($workflowStep->getLabel())->setStepOrder($workflowStep->getStepOrder())->setFinal($workflowStep->isFinal());
     return $this;
 }
Esempio n. 8
0
 public function testToString()
 {
     $label = 'Step Label';
     $this->step->setLabel($label);
     $this->assertEquals($label, (string) $this->step);
 }
Esempio n. 9
0
 /**
  * @param WorkflowStep $step
  * @return WorkflowDefinition
  */
 public function removeStep(WorkflowStep $step)
 {
     $stepName = $step->getName();
     if ($this->hasStepByName($stepName)) {
         $step = $this->getStepByName($stepName);
         $this->steps->removeElement($step);
     }
     return $this;
 }
Esempio n. 10
0
 protected function getTransitionRecordMock($stepToName)
 {
     $workflowStep = new WorkflowStep();
     $workflowStep->setName($stepToName);
     $record = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowTransitionRecord')->disableOriginalConstructor()->getMock();
     $record->expects($this->any())->method('getStepTo')->will($this->returnValue($workflowStep));
     return $record;
 }
Esempio n. 11
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());
 }
Esempio n. 12
0
 protected function getStepEntity($name)
 {
     $step = new WorkflowStep();
     $step->setName($name);
     return $step;
 }