/**
  * @param string $name
  * @param array $options
  * @return Step
  * @throws InvalidParameterException
  * @throws UnknownAttributeException
  */
 protected function assembleStep($name, array $options)
 {
     $this->assertOptions($options, array('label'));
     $step = new Step();
     $step->setName($name)->setLabel($options['label'])->setTemplate($this->getOption($options, 'template', null))->setOrder($this->getOption($options, 'order', 0))->setIsFinal($this->getOption($options, 'is_final', false))->setAllowedTransitions($this->getOption($options, 'allowed_transitions', array()))->setFormType($this->getOption($options, 'form_type', WorkflowStepType::NAME))->setFormOptions($this->assembleFormOptions($options, $name))->setViewAttributes($this->assembleViewAttributes($options, $name));
     return $step;
 }
示例#2
0
 /**
  * @param string $stepName
  * @param array $options
  * @return Step
  * @throws InvalidParameterException
  * @throws UnknownAttributeException
  */
 protected function assembleStep($stepName, array $options)
 {
     $this->assertOptions($options, array('label'));
     $step = new Step();
     $step->setName($stepName)->setLabel($options['label'])->setOrder($this->getOption($options, 'order', 0))->setFinal($this->getOption($options, 'is_final', false))->setAllowedTransitions($this->getOption($options, 'allowed_transitions', array()))->setEntityAcls($this->getOption($options, 'entity_acl', array()));
     return $step;
 }
 /**
  * @param array $inputData
  * @param array $expectedData
  * @param array $expectedAcls
  * @dataProvider buildFromConfigurationDataProvider
  */
 public function testBuildFromConfiguration(array $inputData, array $expectedData, array $expectedAcls = array())
 {
     $workflowConfiguration = current($inputData);
     $steps = array();
     if (!empty($workflowConfiguration[WorkflowConfiguration::NODE_STEPS])) {
         foreach ($workflowConfiguration[WorkflowConfiguration::NODE_STEPS] as $stepData) {
             $step = new Step();
             $step->setName($stepData['name']);
             if (!empty($stepData['entity_acl'])) {
                 $step->setEntityAcls($stepData['entity_acl']);
             }
             if (array_key_exists('is_final', $stepData)) {
                 $step->setFinal($stepData['is_final']);
             }
             $steps[] = $step;
         }
     }
     if (!empty($workflowConfiguration['start_step'])) {
         $step = new Step();
         $step->setName($workflowConfiguration['start_step']);
         $steps[] = $step;
     }
     $stepManager = new StepManager($steps);
     $attributes = array();
     if (!empty($workflowConfiguration[WorkflowConfiguration::NODE_ATTRIBUTES])) {
         foreach ($workflowConfiguration[WorkflowConfiguration::NODE_ATTRIBUTES] as $attributeData) {
             $attribute = new Attribute();
             $attribute->setName($attributeData['name']);
             $attribute->setType($attributeData['type']);
             if (!empty($attributeData['entity_acl'])) {
                 $attribute->setEntityAcl($attributeData['entity_acl']);
             }
             $attributes[] = $attribute;
         }
     }
     $attributeManager = new AttributeManager($attributes);
     $workflow = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\Workflow')->disableOriginalConstructor()->setMethods(array('getStepManager', 'getAttributeManager'))->getMock();
     $workflow->expects($this->any())->method('getStepManager')->will($this->returnValue($stepManager));
     $workflow->expects($this->any())->method('getAttributeManager')->will($this->returnValue($attributeManager));
     $workflowAssembler = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\WorkflowAssembler')->disableOriginalConstructor()->setMethods(array('assemble'))->getMock();
     $workflowAssembler->expects($this->once())->method('assemble')->with($this->isInstanceOf('Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowDefinition'), false)->will($this->returnValue($workflow));
     $fieldGenerator = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Field\\FieldGenerator')->disableOriginalConstructor()->setMethods(array('generateWorkflowFields'))->getMock();
     $fieldGenerator->expects($this->once())->method('generateWorkflowFields')->with($expectedData['entity']);
     $builder = new WorkflowDefinitionConfigurationBuilder($workflowAssembler, $fieldGenerator);
     $workflowDefinitions = $builder->buildFromConfiguration($inputData);
     $this->assertCount(1, $workflowDefinitions);
     /** @var WorkflowDefinition $workflowDefinition */
     $workflowDefinition = current($workflowDefinitions);
     $this->assertEquals($expectedData, $this->getDataAsArray($workflowDefinition));
     $actualAcls = $workflowDefinition->getEntityAcls()->toArray();
     $this->assertSameSize($expectedAcls, $actualAcls);
     foreach ($expectedAcls as $expectedAcl) {
         /** @var WorkflowEntityAcl $actualAcl */
         $actualAcl = array_shift($actualAcls);
         $this->assertEquals($expectedAcl['step'], $actualAcl->getStep()->getName());
         $this->assertEquals($expectedAcl['attribute'], $actualAcl->getAttribute());
         $this->assertEquals($expectedAcl['permissions']['update'], $actualAcl->isUpdatable());
         $this->assertEquals($expectedAcl['permissions']['delete'], $actualAcl->isDeletable());
     }
 }
示例#4
0
 public function testStartStep()
 {
     $testStartStep = 'start_step';
     $startStep = new Step();
     $startStep->setName($testStartStep);
     $stepManager = new StepManager(array($startStep));
     $this->assertNull($stepManager->getStartStep());
     $this->assertFalse($stepManager->hasStartStep());
     $stepManager->setStartStepName($testStartStep);
     $this->assertEquals($startStep, $stepManager->getStartStep());
     $this->assertTrue($stepManager->hasStartStep());
 }
示例#5
0
 public function testEntityAclAllowed()
 {
     $this->assertTrue($this->step->isEntityUpdateAllowed('not_existing_attribute'));
     $this->assertTrue($this->step->isEntityDeleteAllowed('not_existing_attribute'));
     $this->step->setEntityAcls(array('existing_attribute' => array('update' => false, 'delete' => false)));
     $this->assertFalse($this->step->isEntityUpdateAllowed('existing_attribute'));
     $this->assertFalse($this->step->isEntityDeleteAllowed('existing_attribute'));
     $this->step->setEntityAcls(array('existing_attribute' => array('update' => true, 'delete' => true)));
     $this->assertTrue($this->step->isEntityUpdateAllowed('existing_attribute'));
     $this->assertTrue($this->step->isEntityDeleteAllowed('existing_attribute'));
 }
示例#6
0
 /**
  * @param string $name
  * @return Step
  */
 protected function createStep($name)
 {
     $step = new Step();
     $step->setName($name);
     return $step;
 }
 public function testGetAllowedTransitions()
 {
     $firstTransition = new Transition();
     $firstTransition->setName('first_transition');
     $secondTransition = new Transition();
     $secondTransition->setName('second_transition');
     $step = new Step();
     $step->setName('test_step');
     $step->setAllowedTransitions(array($secondTransition->getName()));
     $workflow = $this->createWorkflow();
     $workflow->getStepManager()->setSteps(array($step));
     $workflow->getTransitionManager()->setTransitions(array($firstTransition, $secondTransition));
     $workflowItem = new WorkflowItem();
     $workflowItem->setCurrentStepName($step->getName());
     $actualTransitions = $workflow->getTransitionsByWorkflowItem($workflowItem);
     $this->assertEquals(array($secondTransition), $actualTransitions->getValues());
 }
 /**
  * @param string|null $name
  * @return Step
  */
 protected function createStep($name = null)
 {
     $result = new Step();
     $result->setName($name);
     return $result;
 }
 public function testSetGetViewAttributes()
 {
     $viewAttributes = array(array('attribute' => 'foo'), array('attribute' => 'bar'));
     $this->step->setViewAttributes($viewAttributes);
     $this->assertEquals($viewAttributes, $this->step->getViewAttributes());
 }