/**
  * @param string $name
  * @param array $configuration
  * @return WorkflowDefinition
  */
 public function buildOneFromConfiguration($name, array $configuration)
 {
     $this->assertConfigurationOptions($configuration, array('label', 'entity'));
     $system = $this->getConfigurationOption($configuration, 'is_system', false);
     $startStepName = $this->getConfigurationOption($configuration, 'start_step', null);
     $entityAttributeName = $this->getConfigurationOption($configuration, 'entity_attribute', WorkflowConfiguration::DEFAULT_ENTITY_ATTRIBUTE);
     $stepsDisplayOrdered = $this->getConfigurationOption($configuration, 'steps_display_ordered', false);
     $workflowDefinition = new WorkflowDefinition();
     $workflowDefinition->setName($name)->setLabel($configuration['label'])->setRelatedEntity($configuration['entity'])->setStepsDisplayOrdered($stepsDisplayOrdered)->setSystem($system)->setEntityAttributeName($entityAttributeName)->setConfiguration($this->filterConfiguration($configuration));
     $workflow = $this->workflowAssembler->assemble($workflowDefinition, false);
     $this->setSteps($workflowDefinition, $workflow);
     $workflowDefinition->setStartStep($workflowDefinition->getStepByName($startStepName));
     $this->setEntityAcls($workflowDefinition, $workflow);
     $this->fieldGenerator->generateWorkflowFields($workflowDefinition->getRelatedEntity());
     return $workflowDefinition;
 }
Esempio n. 2
0
 public function testGenerateWorkflowFields()
 {
     $entityClass = 'TestEntity';
     $this->entityConnector->expects($this->once())->method('isWorkflowAware')->with($entityClass)->will($this->returnValue(false));
     $extendConfigProvider = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProviderInterface');
     $entityConfigProvider = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProviderInterface');
     $formConfigProvider = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProviderInterface');
     $viewConfigProvider = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProviderInterface');
     $importExportConfigProvider = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProviderInterface');
     $providerMap = array(array('extend', $extendConfigProvider), array('entity', $entityConfigProvider), array('form', $formConfigProvider), array('view', $viewConfigProvider), array('importexport', $importExportConfigProvider));
     $this->configManager->expects($this->any())->method('getProvider')->will($this->returnValueMap($providerMap));
     $entityConfig = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
     $entityConfig->expects($this->at(0))->method('is')->with('is_extend')->will($this->returnValue(true));
     $extendConfigProvider->expects($this->at(0))->method('getConfig')->with($entityClass)->will($this->returnValue($entityConfig));
     $workflowItemClass = 'Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowItem';
     $workflowStepClass = 'Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowStep';
     $this->addFieldAssertions($entityConfigProvider, $extendConfigProvider, $formConfigProvider, $viewConfigProvider, $importExportConfigProvider, $entityClass, FieldGenerator::PROPERTY_WORKFLOW_ITEM, ConfigHelper::getTranslationKey('entity', 'label', $workflowItemClass, 'related_entity'), ConfigHelper::getTranslationKey('entity', 'description', $workflowItemClass, 'related_entity'), 'Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowItem', 'id', 0);
     $this->addFieldAssertions($entityConfigProvider, $extendConfigProvider, $formConfigProvider, $viewConfigProvider, $importExportConfigProvider, $entityClass, FieldGenerator::PROPERTY_WORKFLOW_STEP, ConfigHelper::getTranslationKey('entity', 'label', $workflowStepClass, 'related_entity'), ConfigHelper::getTranslationKey('entity', 'description', $workflowStepClass, 'related_entity'), 'Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowStep', 'label', 1);
     $entityConfig->expects($this->at(1))->method('set')->with('state', ExtendScope::STATE_UPDATE);
     $entityConfig->expects($this->at(2))->method('set')->with('upgradeable', true);
     $this->configManager->expects($this->at(15))->method('persist')->with($entityConfig);
     $this->configManager->expects($this->at(16))->method('flush');
     $this->entityProcessor->expects($this->once())->method('updateDatabase');
     /*
     $this->addHideAssertions($entityClass, FieldGenerator::PROPERTY_WORKFLOW_ITEM, 0);
     $this->addHideAssertions($entityClass, FieldGenerator::PROPERTY_WORKFLOW_STEP, 1);
     $this->configManager->expects($this->at(17))->method('flush');
     */
     // run test
     $this->generator->generateWorkflowFields($entityClass);
 }