/**
  * @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;
 }
Exemplo n.º 2
0
 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 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;
 }
Exemplo n.º 4
0
 /**
  * @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;
 }
Exemplo n.º 5
0
 /**
  * @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;
 }
Exemplo n.º 6
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));
 }
 /**
  * @dataProvider workflowNameDataProvider
  * @param string|null $requiredWorkflowName
  */
 public function testGetApplicableWorkflows($requiredWorkflowName)
 {
     // mocks for entity metadata
     $entity = new \DateTime('now');
     $entityClass = get_class($entity);
     $entityId = 1;
     $this->doctrineHelper->expects($this->any())->method('getEntityIdentifier')->with($entity)->will($this->returnValue($entityId));
     // mocks for workflows:
     // - without workflow items
     // - single managed entity with workflow items
     // - multiple managed entity with workflow items
     $singleEntityAttribute = new Attribute();
     $singleEntityAttribute->setOptions(array('class' => $entityClass));
     $multipleEntityAttribute = new Attribute();
     $multipleEntityAttribute->setOptions(array('class' => $entityClass, 'multiple' => true));
     $newWorkflow = $this->createWorkflow('new_workflow', array($singleEntityAttribute));
     $usedSingleWorkflow = $this->createWorkflow('used_single_workflow', array($singleEntityAttribute));
     $usedMultipleWorkflow = $this->createWorkflow('used_multiple_workflow', array($multipleEntityAttribute));
     $allowedWorkflows = array($newWorkflow, $usedSingleWorkflow, $usedMultipleWorkflow);
     if ($requiredWorkflowName) {
         $this->workflowRegistry->expects($this->exactly(2))->method('getWorkflow')->with($requiredWorkflowName)->will($this->returnValue($newWorkflow));
         // expected workflows (single managed entity with existing workflow items is not allowed)
         $expectedWorkflows = array($newWorkflow->getName() => $newWorkflow);
     } else {
         // expected workflows (single managed entity with existing workflow items is not allowed)
         $expectedWorkflows = array($newWorkflow->getName() => $newWorkflow, $usedMultipleWorkflow->getName() => $usedMultipleWorkflow);
         $this->workflowRegistry->expects($this->any())->method('getWorkflowsByEntityClass')->with($entityClass)->will($this->returnValue($allowedWorkflows));
     }
     // mocks for workflow items
     $workflowItems = array($this->createWorkflowItem($usedSingleWorkflow->getName()), $this->createWorkflowItem($usedMultipleWorkflow->getName()));
     $workflowItemsRepository = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Entity\\Repository\\WorkflowItemRepository')->disableOriginalConstructor()->setMethods(array('findByEntityMetadata'))->getMock();
     $workflowItemsRepository->expects($this->any())->method('findByEntityMetadata')->with($entityClass, $entityId, $requiredWorkflowName)->will($this->returnValue($workflowItems));
     $this->registry->expects($this->any())->method('getRepository')->with('OroWorkflowBundle:WorkflowItem')->will($this->returnValue($workflowItemsRepository));
     // with automatic workflow item extraction
     $this->assertEquals($expectedWorkflows, $this->workflowManager->getApplicableWorkflows($entity, null, $requiredWorkflowName));
     // with manual workflow item setting
     $this->assertEquals($expectedWorkflows, $this->workflowManager->getApplicableWorkflows($entity, $workflowItems, $requiredWorkflowName));
 }