/** * @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()); } }
/** * @param string|null $name * @param string|null $type * @param string|null $label * @return Attribute */ protected function createAttribute($name = null, $type = null, $label = null) { $result = new Attribute(); $result->setName($name); $result->setType($type); $result->setLabel($label); return $result; }
/** * @param string $name * @param string $label * @param string $type * @param array $options * @return Attribute */ protected function getAttribute($name, $label, $type, array $options = array()) { $attribute = new Attribute(); $attribute->setName($name); $attribute->setLabel($label); $attribute->setType($type); $attribute->setOptions($options); return $attribute; }
/** * @param string $name * @param array $options * @return Attribute */ protected function assembleAttribute($name, array $options) { $options = $this->addDefaultOptions($options); $this->assertOptions($options, array('label', 'type')); $attribute = new Attribute(); $attribute->setName($name); $attribute->setLabel($options['label']); $attribute->setType($options['type']); $attribute->setOptions($this->getOption($options, 'options', array())); $this->validateAttribute($attribute); return $attribute; }
/** * @param WorkflowDefinition $definition * @param string $name * @param array $options * @return Attribute */ protected function assembleAttribute(WorkflowDefinition $definition, $name, array $options) { if (!empty($options['property_path'])) { $options = $this->guessOptions($options, $definition->getRelatedEntity(), $options['property_path']); } $this->assertOptions($options, array('label', 'type')); $this->assertAttributeEntityAcl($options); $attribute = new Attribute(); $attribute->setName($name); $attribute->setLabel($options['label']); $attribute->setType($options['type']); $attribute->setEntityAcl($this->getOption($options, 'entity_acl', array())); $attribute->setPropertyPath($this->getOption($options, 'property_path')); $attribute->setOptions($this->getOption($options, 'options', array())); $this->validateAttribute($attribute); return $attribute; }
/** * @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); }
/** * @param string $name * @return Attribute */ protected function createAttribute($name) { $attribute = new Attribute(); $attribute->setName($name); return $attribute; }
/** * @param string $name * @param string $label * @param string $type * @param array $options * @param string $propertyPath * @param array $entityAcl * @return Attribute */ protected function getAttribute($name, $label, $type, array $options = array(), $propertyPath = null, array $entityAcl = array()) { $attribute = new Attribute(); $attribute->setName($name); $attribute->setLabel($label); $attribute->setType($type); $attribute->setOptions($options); $attribute->setPropertyPath($propertyPath); $attribute->setEntityAcl($entityAcl); return $attribute; }
public function testIsStartTransitionAvailable() { $data = array(); $errors = new ArrayCollection(); $transitionName = 'test_transition'; $workflowDefinition = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowDefinition')->disableOriginalConstructor()->getMock(); $transition = $this->getTransitionMock($transitionName); $transition->expects($this->once())->method('isAvailable')->with($this->isInstanceOf('Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowItem'), $errors)->will($this->returnValue(true)); $transitionManager = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\TransitionManager')->disableOriginalConstructor()->getMock(); $transitionManager->expects($this->once())->method('extractTransition')->with($transition)->will($this->returnValue($transition)); $entity = new \DateTime(); $entityAttribute = new Attribute(); $entityAttribute->setName('entity'); $workflow = $this->createWorkflow(null, null, null, null, $transitionManager); $workflow->setDefinition($workflowDefinition); $workflow->getAttributeManager()->setAttributes(array($entityAttribute)); $workflow->getAttributeManager()->setEntityAttributeName($entityAttribute->getName()); $this->assertTrue($workflow->isStartTransitionAvailable($transition, $entity, $data, $errors)); }
public function testIsStartTransitionAvailable() { $workflowName = 'test_workflow'; $errors = new ArrayCollection(); $entity = new \DateTime('now'); $data = array(); $entityAttribute = new Attribute(); $entityAttribute->setName('entity_attribute'); $entityAttribute->setType('entity'); $entityAttribute->setOptions(array('class' => 'DateTime')); $stringAttribute = new Attribute(); $stringAttribute->setName('other_attribute'); $stringAttribute->setType('string'); $transition = 'test_transition'; $workflow = $this->createWorkflow($workflowName, array($entityAttribute, $stringAttribute)); $workflow->expects($this->once())->method('isStartTransitionAvailable')->with($transition, $entity, $data, $errors)->will($this->returnValue(true)); $this->workflowRegistry->expects($this->once())->method('getWorkflow')->with($workflowName)->will($this->returnValue($workflow)); $this->assertTrue($this->workflowManager->isStartTransitionAvailable($workflowName, $transition, $entity, $data, $errors)); }
public function testIsAllManagedEntitiesSpecified() { $managedAttributeName = 'entity'; $managedAttribute = new Attribute(); $managedAttribute->setName($managedAttributeName); $workflow = $this->createWorkflow(self::TEST_WORKFLOW_NAME, array($managedAttribute)); $this->workflowRegistry->expects($this->any())->method('getWorkflow')->with(self::TEST_WORKFLOW_NAME)->will($this->returnValue($workflow)); $validWorkflowItem = $this->createWorkflowItem(); $validWorkflowItem->getData()->set($managedAttributeName, new \DateTime()); $this->assertTrue($this->workflowManager->isAllManagedEntitiesSpecified($validWorkflowItem)); $invalidWorkflowItem = $this->createWorkflowItem(); $this->assertFalse($this->workflowManager->isAllManagedEntitiesSpecified($invalidWorkflowItem)); }