/**
  * @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;
 }
Example #3
0
 public function testEntityAclAllowed()
 {
     $attribute = new Attribute();
     $this->assertTrue($attribute->isEntityUpdateAllowed());
     $this->assertTrue($attribute->isEntityDeleteAllowed());
     $attribute->setEntityAcl(array('update' => false, 'delete' => false));
     $this->assertFalse($attribute->isEntityUpdateAllowed());
     $this->assertFalse($attribute->isEntityDeleteAllowed());
     $attribute->setEntityAcl(array('update' => true, 'delete' => true));
     $this->assertTrue($attribute->isEntityUpdateAllowed());
     $this->assertTrue($attribute->isEntityDeleteAllowed());
 }
Example #4
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 testGetSetOption()
 {
     $obj = new Attribute();
     $obj->setOptions(array('key' => 'test'));
     $this->assertEquals('test', $obj->getOption('key'));
     $obj->setOption('key2', 'test2');
     $this->assertEquals(array('key' => 'test', 'key2' => 'test2'), $obj->getOptions());
     $obj->setOption('key', 'test_changed');
     $this->assertEquals('test_changed', $obj->getOption('key'));
 }
 /**
  * @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;
 }
Example #7
0
 /**
  * @param Attribute $attribute
  * @param string|array $optionNames
  * @throws AssemblerException If attribute is invalid
  */
 protected function assertAttributeHasNoOptions(Attribute $attribute, $optionNames)
 {
     $optionNames = (array) $optionNames;
     foreach ($optionNames as $optionName) {
         if ($attribute->hasOption($optionName)) {
             throw new AssemblerException(sprintf('Option "%s" cannot be used in attribute "%s"', $optionName, $attribute->getName()));
         }
     }
 }
Example #8
0
 /**
  * @param string $rootClass
  * @param Attribute $attribute
  * @return null|TypeGuess
  */
 public function guessClassAttributeForm($rootClass, Attribute $attribute)
 {
     $propertyPath = $attribute->getPropertyPath();
     if (!$propertyPath) {
         return $this->guessAttributeForm($attribute);
     }
     $attributeParameters = $this->guessMetadataAndField($rootClass, $propertyPath);
     if (!$attributeParameters) {
         return $this->guessAttributeForm($attribute);
     }
     /** @var ClassMetadata $metadata */
     $metadata = $attributeParameters['metadata'];
     $class = $metadata->getName();
     $field = $attributeParameters['field'];
     return $this->getFormTypeGuesser()->guessType($class, $field);
 }
 /**
  * Prepares options of attribute need to add corresponding form type
  *
  * @param Attribute $attribute
  * @param array $attributeOptions
  * @param array $options
  * @return array
  * @throws InvalidConfigurationException
  */
 protected function prepareAttributeOptions(Attribute $attribute, array $attributeOptions, array $options)
 {
     /** @var Workflow $workflow */
     $workflow = $options['workflow'];
     // ensure has form_type
     if (empty($attributeOptions['form_type'])) {
         throw new InvalidConfigurationException(sprintf('Parameter "form_type" must be defined for attribute "%s" in workflow "%s".', $attribute->getName(), $workflow->getName()));
     }
     // updates form options
     if (!isset($attributeOptions['options'])) {
         $attributeOptions['options'] = array();
     }
     // updates form options label
     if (!isset($attributeOptions['options']['label'])) {
         $attributeOptions['options']['label'] = isset($attributeOptions['label']) ? $attributeOptions['label'] : $attribute->getLabel();
     }
     if ($options['disable_attribute_fields']) {
         $attributeOptions['options']['disabled'] = true;
     }
     return $attributeOptions;
 }
 /**
  * @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;
 }
Example #11
0
 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));
 }
Example #12
0
 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));
 }
Example #13
0
 /**
  * @param string $type
  * @param string $propertyPath
  * @param array $options
  * @return Attribute
  */
 protected function createAttribute($type, $propertyPath = null, array $options = array())
 {
     $attribute = new Attribute();
     $attribute->setType($type)->setPropertyPath($propertyPath)->setOptions($options);
     return $attribute;
 }
 /**
  * Returns EntityManager for entity.
  *
  * @param Workflow $workflow
  * @param Attribute $attribute
  * @return EntityManager
  * @throws SerializerException
  */
 protected function getEntityManager(Workflow $workflow, Attribute $attribute)
 {
     $entityClass = $attribute->getOption('class');
     $result = $this->registry->getManagerForClass($entityClass);
     if (!$result) {
         throw new SerializerException(sprintf('Attribute "%s" of workflow "%s" contains object of "%s", but it\'s not managed entity class', $attribute->getName(), $workflow->getName(), $entityClass));
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function supportsDenormalization(Workflow $workflow, Attribute $attribute, $attributeValue)
 {
     return $attribute->getType() == 'entity';
 }
 /**
  * {@inheritdoc}
  */
 public function supportsDenormalization(Workflow $workflow, Attribute $attribute, $attributeValue)
 {
     return !empty($this->normalTypes[$attribute->getType()]);
 }
Example #17
0
 /**
  * @param string $name
  * @return Attribute
  */
 protected function createAttribute($name)
 {
     $attribute = new Attribute();
     $attribute->setName($name);
     return $attribute;
 }
 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));
 }