/**
  * @param string $workflowName
  * @param array $attributes
  * @param array $steps
  * @param string|null $relatedEntity
  * @return Workflow
  */
 protected function createWorkflow($workflowName, array $attributes = array(), array $steps = array(), $relatedEntity = null)
 {
     $entityConnector = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\EntityConnector')->disableOriginalConstructor()->getMock();
     $aclManager = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Acl\\AclManager')->disableOriginalConstructor()->getMock();
     $workflow = new Workflow($entityConnector, $aclManager);
     $workflow->setName($workflowName);
     foreach ($attributes as $name => $attribute) {
         $workflow->getAttributeManager()->getAttributes()->set($name, $attribute);
     }
     $workflow->getStepManager()->setSteps($steps);
     $definition = new WorkflowDefinition();
     $definition->setRelatedEntity($relatedEntity);
     $workflow->setDefinition($definition);
     return $workflow;
 }
Пример #2
0
 /**
  * @param mixed $workflowIdentifier
  * @dataProvider activateWorkflowDataProvider
  */
 public function testActivateWorkflow($workflowIdentifier)
 {
     if ($workflowIdentifier instanceof WorkflowDefinition) {
         $workflowName = $workflowIdentifier->getName();
         $entityClass = $workflowIdentifier->getRelatedEntity();
     } else {
         $workflowName = $workflowIdentifier;
         $entityClass = '\\DateTime';
         $workflowDefinition = new WorkflowDefinition();
         $workflowDefinition->setRelatedEntity($entityClass);
         /** @var Workflow $workflow */
         $workflow = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\Workflow')->disableOriginalConstructor()->setMethods(null)->getMock();
         $workflow->setName($workflowName);
         $workflow->setDefinition($workflowDefinition);
         $this->workflowRegistry->expects($this->once())->method('getWorkflow')->with($workflowIdentifier)->will($this->returnValue($workflow));
     }
     $entityConfig = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
     $entityConfig->expects($this->once())->method('set')->with('active_workflow', $workflowName);
     $workflowConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $workflowConfigProvider->expects($this->once())->method('hasConfig')->with($entityClass)->will($this->returnValue(true));
     $workflowConfigProvider->expects($this->once())->method('getConfig')->with($entityClass)->will($this->returnValue($entityConfig));
     $this->configManager->expects($this->once())->method('getProvider')->with('workflow')->will($this->returnValue($workflowConfigProvider));
     $this->configManager->expects($this->once())->method('persist')->with($entityConfig);
     $this->configManager->expects($this->once())->method('flush');
     $this->workflowManager->activateWorkflow($workflowIdentifier);
 }