/**
  * @dataProvider configurationDataProvider
  * @param array $configuration
  * @param Attribute $expectedAttribute
  */
 public function testAssemble($configuration, $expectedAttribute)
 {
     $assembler = new AttributeAssembler();
     $attributes = $assembler->assemble($configuration);
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $attributes);
     $this->assertCount(1, $attributes);
     $this->assertTrue($attributes->containsKey($expectedAttribute->getName()));
     $this->assertEquals($expectedAttribute, $attributes->get($expectedAttribute->getName()));
 }
 /**
  * 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;
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
 /**
  * @dataProvider configurationDataProvider
  * @param array $configuration
  * @param Attribute $expectedAttribute
  * @param array $guessedParameters
  */
 public function testAssemble($configuration, $expectedAttribute, array $guessedParameters = array())
 {
     $relatedEntity = '\\stdClass';
     $attributeGuesser = $this->getAttributeGuesser();
     $attributeGuesser->expects($this->any())->method('fixPropertyPath')->will($this->returnArgument(0));
     $attributeConfiguration = current($configuration);
     if ($guessedParameters && array_key_exists('property_path', $attributeConfiguration)) {
         $attributeGuesser->expects($this->any())->method('guessAttributeParameters')->with($relatedEntity, $attributeConfiguration['property_path'])->will($this->returnValue($guessedParameters));
     }
     $assembler = new AttributeAssembler($attributeGuesser);
     $definition = $this->getWorkflowDefinition();
     $definition->expects($this->once())->method('getEntityAttributeName')->will($this->returnValue('entity_attribute'));
     $definition->expects($this->any())->method('getRelatedEntity')->will($this->returnValue($relatedEntity));
     $expectedAttributesCount = 1;
     if (!array_key_exists('entity_attribute', $configuration)) {
         $expectedAttributesCount++;
     }
     $attributes = $assembler->assemble($definition, $configuration);
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $attributes);
     $this->assertCount($expectedAttributesCount, $attributes);
     $this->assertTrue($attributes->containsKey($expectedAttribute->getName()));
     $this->assertEquals($expectedAttribute, $attributes->get($expectedAttribute->getName()));
 }
Ejemplo n.º 5
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()));
         }
     }
 }
Ejemplo n.º 6
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));
 }
 /**
  * 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;
 }