Exemplo n.º 1
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'));
 }
 /**
  * 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;
 }
Exemplo n.º 3
0
 public function testUpdateAclIdentities()
 {
     $entity = new \DateTime();
     $entityIdentifier = 42;
     $workflowName = 'test_workflow';
     $firstStep = new WorkflowStep();
     $firstStep->setName('first_step');
     $secondStep = new WorkflowStep();
     $secondStep->setName('second_step');
     $firstAttribute = new Attribute();
     $firstAttribute->setName('first_attribute')->setOption('class', 'FirstTestEntity');
     $secondAttribute = new Attribute();
     $secondAttribute->setName('second_attribute')->setOption('class', 'SecondTestEntity');
     $firstEntityAcl = new WorkflowEntityAcl();
     $firstEntityAcl->setStep($firstStep)->setAttribute($firstAttribute->getName());
     $secondEntityAcl = new WorkflowEntityAcl();
     $secondEntityAcl->setStep($secondStep)->setAttribute($firstAttribute->getName());
     $thirdEntityAcl = new WorkflowEntityAcl();
     $thirdEntityAcl->setStep($secondStep)->setAttribute($secondAttribute->getName());
     $definition = new WorkflowDefinition();
     $definition->setName($workflowName)->setSteps(array($firstStep, $secondStep))->setEntityAcls(array($firstEntityAcl, $secondEntityAcl, $thirdEntityAcl));
     $this->setWorkflow($workflowName, array($firstAttribute, $secondAttribute));
     $this->doctrineHelper->expects($this->any())->method('getSingleEntityIdentifier')->with($entity)->will($this->returnValue($entityIdentifier));
     $workflowItem = new WorkflowItem();
     $workflowItem->setWorkflowName($workflowName)->setDefinition($definition)->setCurrentStep($secondStep);
     $workflowItem->getData()->set($firstAttribute->getName(), $entity);
     $this->assertEmpty($workflowItem->getAclIdentities()->toArray());
     $this->assertEquals($workflowItem, $this->manager->updateAclIdentities($workflowItem));
     $this->assertCount(1, $workflowItem->getAclIdentities());
     /** @var WorkflowEntityAclIdentity $aclIdentity */
     $aclIdentity = $workflowItem->getAclIdentities()->first();
     $this->assertEquals($secondEntityAcl, $aclIdentity->getAcl());
     $this->assertEquals($firstAttribute->getOption('class'), $aclIdentity->getEntityClass());
     $this->assertEquals($entityIdentifier, $aclIdentity->getEntityId());
     $this->assertEquals($workflowItem, $aclIdentity->getWorkflowItem());
 }
Exemplo n.º 4
0
 /**
  * @param Attribute $attribute
  * @return null|TypeGuess
  */
 public function guessAttributeForm(Attribute $attribute)
 {
     $attributeType = $attribute->getType();
     if ($attributeType === 'entity') {
         list($formType, $formOptions) = $this->getEntityForm($attribute->getOption('class'));
     } elseif (isset($this->formTypeMapping[$attributeType])) {
         $formType = $this->formTypeMapping[$attributeType]['type'];
         $formOptions = $this->formTypeMapping[$attributeType]['options'];
     } else {
         return null;
     }
     return new TypeGuess($formType, $formOptions, TypeGuess::VERY_HIGH_CONFIDENCE);
 }
 /**
  * @param mixed $value
  * @param Attribute $attribute
  * @return object|null
  */
 protected function denormalizeObject($value, Attribute $attribute)
 {
     $value = $this->unserialize($value);
     $class = $attribute->getOption('class');
     if (!is_object($value) || !$value instanceof $class) {
         $value = null;
     }
     return $value;
 }
 /**
  * {@inheritdoc}
  */
 public function supportsDenormalization(Workflow $workflow, Attribute $attribute, $attributeValue)
 {
     return $attribute->getType() == 'entity' && !$attribute->getOption('multiple');
 }