public function testGetSetWorkflowDefinition()
 {
     $this->assertNull($this->workflowDefinitionEntity->getWorkflowDefinition());
     $value = new WorkflowDefinition();
     $value->setName('test_workflow');
     $this->workflowDefinitionEntity->setWorkflowDefinition($value);
     $this->assertEquals($value, $this->workflowDefinitionEntity->getWorkflowDefinition());
 }
 /**
  * @expectedException \Oro\Bundle\WorkflowBundle\Exception\WorkflowException
  * @expectedExceptionMessage Cannot find workflow definition "test_workflow"
  */
 public function testPrePersistFails()
 {
     $entity = new WorkflowItem();
     $entity->setWorkflowName('test_workflow');
     $workflowDefinition = new WorkflowDefinition();
     $workflowDefinition->setName('test_workflow');
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->setMethods(array('find'))->disableOriginalConstructor()->getMock();
     $em->expects($this->once())->method('find')->with('OroWorkflowBundle:WorkflowDefinition', 'test_workflow')->will($this->returnValue(null));
     $this->subscriber->prePersist(new LifecycleEventArgs($entity, $em));
 }
 public function testImport()
 {
     $expectedData = array('name' => 'test_name', 'label' => 'test_label', 'enabled' => false, 'start_step' => 'test_step', 'configuration' => array('test', 'configuration'), 'entities' => array(array('class' => 'TestClass')));
     $this->assertNotEquals($expectedData, $this->getDefinitionAsArray($this->workflowDefinition));
     $definitionEntity = new WorkflowDefinitionEntity();
     $definitionEntity->setClassName($expectedData['entities'][0]['class']);
     $newDefinition = new WorkflowDefinition();
     $newDefinition->setName($expectedData['name'])->setLabel($expectedData['label'])->setEnabled($expectedData['enabled'])->setStartStep($expectedData['start_step'])->setConfiguration($expectedData['configuration'])->setWorkflowDefinitionEntities(array($definitionEntity));
     $this->workflowDefinition->import($newDefinition);
     $this->assertEquals($expectedData, $this->getDefinitionAsArray($this->workflowDefinition));
 }
 public function testImport()
 {
     $startStep = new WorkflowStep();
     $startStep->setName('start');
     $expectedData = array('name' => 'test_name', 'label' => 'test_label', 'steps' => new ArrayCollection(array($startStep)), 'start_step' => $startStep, 'configuration' => array('test', 'configuration'));
     $this->assertNotEquals($expectedData, $this->getDefinitionAsArray($this->workflowDefinition));
     $newDefinition = new WorkflowDefinition();
     $newDefinition->setName($expectedData['name'])->setSteps($expectedData['steps'])->setLabel($expectedData['label'])->setStartStep($expectedData['start_step'])->setConfiguration($expectedData['configuration']);
     $this->assertEquals($this->workflowDefinition, $this->workflowDefinition->import($newDefinition));
     $this->assertEquals($expectedData, $this->getDefinitionAsArray($this->workflowDefinition));
 }
 /**
  * @param array $inputOptions
  * @param array $expectedOptions
  * @dataProvider setDefaultOptionsDataProvider
  */
 public function testSetDefaultOptions(array $inputOptions, array $expectedOptions)
 {
     $testWorkflowDefinition = new WorkflowDefinition();
     $testWorkflowDefinition->setName(self::TEST_WORKFLOW_NAME)->setLabel(self::TEST_WORKFLOW_LABEL);
     $repository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $repository->expects($this->any())->method('findBy')->with(array('relatedEntity' => self::TEST_ENTITY_CLASS))->will($this->returnValue(array($testWorkflowDefinition)));
     $this->registry->expects($this->any())->method('getRepository')->with('OroWorkflowBundle:WorkflowDefinition')->will($this->returnValue($repository));
     $form = $this->factory->create($this->type, null, $inputOptions);
     $actualOptions = $form->getConfig()->getOptions();
     foreach ($expectedOptions as $name => $expectedValue) {
         $this->assertArrayHasKey($name, $actualOptions);
         $this->assertEquals($expectedValue, $actualOptions[$name]);
     }
 }
 /**
  * @param array $configurationData
  * @return WorkflowDefinition[]
  */
 public function buildFromConfiguration($configurationData)
 {
     $workflowDefinitions = array();
     foreach ($configurationData as $workflowName => $workflowConfiguration) {
         $this->assertConfigurationOptions($workflowConfiguration, array('label', 'type'));
         $type = $this->getConfigurationOption($workflowConfiguration, 'type', Workflow::TYPE_ENTITY);
         $enabled = $this->getConfigurationOption($workflowConfiguration, 'enabled', true);
         $startStep = $this->getConfigurationOption($workflowConfiguration, 'start_step', null);
         $managedEntityClasses = $this->getManagedEntityClasses($workflowConfiguration);
         $definitionEntities = $this->buildDefinitionEntities($managedEntityClasses);
         $workflowDefinition = new WorkflowDefinition();
         $workflowDefinition->setName($workflowName)->setLabel($workflowConfiguration['label'])->setType($type)->setEnabled($enabled)->setStartStep($startStep)->setConfiguration($workflowConfiguration)->setWorkflowDefinitionEntities($definitionEntities);
         $workflowDefinitions[] = $workflowDefinition;
     }
     return $workflowDefinitions;
 }
 /**
  * @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;
 }
 public function testBuildFromRawConfiguration()
 {
     $rawConfiguration = array('name' => 'test_workflow');
     $handledConfiguration = array('name' => 'test_workflow', 'label' => 'Test Workflow');
     $processedConfiguration = array('name' => 'test_workflow', 'label' => 'Test Workflow', 'is_system' => false);
     $workflowDefinition = new WorkflowDefinition();
     $workflowDefinition->setName($processedConfiguration['name']);
     $handler = $this->getMock('Oro\\Bundle\\WorkflowBundle\\Configuration\\Handler\\ConfigurationHandlerInterface');
     $handler->expects($this->once())->method('handle')->with($rawConfiguration)->will($this->returnValue($handledConfiguration));
     $configuration = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Configuration\\WorkflowConfiguration')->disableOriginalConstructor()->getMock();
     $configuration->expects($this->once())->method('processConfiguration')->with($handledConfiguration)->will($this->returnValue($processedConfiguration));
     $configurationBuilder = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Configuration\\WorkflowDefinitionConfigurationBuilder')->disableOriginalConstructor()->getMock();
     $configurationBuilder->expects($this->once())->method('buildOneFromConfiguration')->with($processedConfiguration['name'], $processedConfiguration)->will($this->returnValue($workflowDefinition));
     $handleBuilder = new WorkflowDefinitionHandleBuilder($handler, $configuration, $configurationBuilder);
     $this->assertEquals($workflowDefinition, $handleBuilder->buildFromRawConfiguration($rawConfiguration));
 }
Example #9
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);
 }
 public function testGetWorkflowsByEntityClass()
 {
     $entityClass = '\\stdClass';
     $workflowName = 'test_workflow';
     $workflowDefinition = new WorkflowDefinition();
     $workflowDefinition->setName($workflowName);
     /** @var Workflow $workflow */
     $workflow = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\Workflow')->disableOriginalConstructor()->getMock();
     $workflowDefinitionRepository = $this->createWorkflowDefinitionRepositoryMock();
     $workflowDefinitionRepository->expects($this->once())->method('findByEntityClass')->with($entityClass)->will($this->returnValue(array($workflowDefinition)));
     $managerRegistry = $this->createManagerRegistryMock($workflowDefinitionRepository);
     $workflowAssembler = $this->createWorkflowAssemblerMock($workflowDefinition, $workflow);
     $workflowRegistry = new WorkflowRegistry($managerRegistry, $workflowAssembler);
     $expectedWorkflows = array($workflowName => $workflow);
     $actualWorkflows = $workflowRegistry->getWorkflowsByEntityClass($entityClass);
     $this->assertEquals($expectedWorkflows, $actualWorkflows);
 }
 /**
  * @param array $configuration
  * @return WorkflowDefinition
  */
 protected function createWorkflowDefinition(array $configuration)
 {
     $workflowDefinition = new WorkflowDefinition();
     $workflowDefinition->setName($this->workflowParameters['name'])->setLabel($this->workflowParameters['label'])->setEnabled($this->workflowParameters['enabled'])->setType($this->workflowParameters['type'])->setConfiguration($configuration);
     return $workflowDefinition;
 }
Example #12
0
 public function testGetActiveWorkflowByEntityClassNoWorkflow()
 {
     $entityClass = '\\stdClass';
     $workflowName = 'test_workflow';
     $workflowDefinition = new WorkflowDefinition();
     $workflowDefinition->setName($workflowName);
     $workflowDefinitionRepository = $this->createWorkflowDefinitionRepositoryMock();
     $workflowDefinitionRepository->expects($this->once())->method('find')->with($workflowName)->will($this->returnValue(null));
     $managerRegistry = $this->createManagerRegistryMock($workflowDefinitionRepository);
     $workflowAssembler = $this->createWorkflowAssemblerMock();
     $configProvider = $this->createConfigurationProviderMock();
     $configProvider->expects($this->any())->method('hasConfig')->with($entityClass)->will($this->returnValue(true));
     $config = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface')->getMock();
     $config->expects($this->any())->method('get')->with('active_workflow')->will($this->returnValue($workflowName));
     $configProvider->expects($this->any())->method('getConfig')->with($entityClass)->will($this->returnValue($config));
     $workflowRegistry = new WorkflowRegistry($managerRegistry, $workflowAssembler, $configProvider);
     $this->assertNull($workflowRegistry->getActiveWorkflowByEntityClass($entityClass));
 }
Example #13
0
 public function testResetWorkflowData()
 {
     $name = 'testWorkflow';
     $entityClass = 'Test:Entity';
     $workflowDefinition = new WorkflowDefinition();
     $workflowDefinition->setName($name)->setRelatedEntity($entityClass);
     $workflowItemsRepository = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Entity\\Repository\\WorkflowItemRepository')->disableOriginalConstructor()->setMethods(array('resetWorkflowData'))->getMock();
     $workflowItemsRepository->expects($this->once())->method('resetWorkflowData')->with($entityClass, array($name));
     $this->registry->expects($this->once())->method('getRepository')->with('OroWorkflowBundle:WorkflowItem')->will($this->returnValue($workflowItemsRepository));
     $this->workflowManager->resetWorkflowData($workflowDefinition);
 }