/**
  * @param array $data
  * @return WorkflowData
  */
 protected function createWorkflowData(array $data = array())
 {
     $result = new WorkflowData();
     foreach ($data as $name => $value) {
         $result->set($name, $value);
     }
     return $result;
 }
 /**
  * Copy submitted data to existing workflow data
  *
  * @param FormEvent $event
  */
 public function onSubmit(FormEvent $event)
 {
     /** @var WorkflowData $formData */
     $formData = $event->getData();
     if ($this->workflowData && $formData instanceof WorkflowData) {
         $this->workflowData->add($formData->getValues());
         $event->setData($this->workflowData);
     }
 }
 public function testGetDataWithSerialization()
 {
     /** @var WorkflowItem $workflowItem */
     $workflowItem = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowItem')->disableOriginalConstructor()->setMethods(null)->getMock();
     $serializedData = 'serialized_data';
     $data = new WorkflowData();
     $data->set('foo', 'bar');
     $serializer = $this->getMock('Oro\\Bundle\\WorkflowBundle\\Serializer\\WorkflowAwareSerializer');
     $serializer->expects($this->once())->method('deserialize')->with($serializedData, 'Oro\\Bundle\\WorkflowBundle\\Model\\WorkflowData', 'json')->will($this->returnValue($data));
     $workflowItem->setSerializer($serializer, 'json');
     $workflowItem->setSerializedData($serializedData);
     $this->assertSame($data, $workflowItem->getData());
     $this->assertSame($data, $workflowItem->getData());
 }
 public function testGetProxyValue()
 {
     $name = 'entity';
     $existingEntity = $this->getMock('Doctrine\\Common\\Persistence\\Proxy');
     $existingEntity->expects($this->once())->method('__isInitialized')->will($this->returnValue(false));
     $existingEntity->expects($this->once())->method('__load');
     $this->data->set($name, $existingEntity);
     $this->assertEquals($existingEntity, $this->data->get($name));
     $removedEntity = $this->getMock('Doctrine\\Common\\Persistence\\Proxy');
     $removedEntity->expects($this->once())->method('__isInitialized')->will($this->returnValue(false));
     $removedEntity->expects($this->once())->method('__load')->will($this->throwException(new EntityNotFoundException()));
     $this->data->set($name, $removedEntity);
     $this->assertNull($this->data->get($name));
 }
Beispiel #5
0
 public function testMappedField()
 {
     $data = new \stdClass();
     $data->value = 'one';
     $this->data->setFieldsMapping(array('test2' => 'test.value'));
     $this->assertFalse($this->data->has('test'), 'no test');
     $this->assertFalse($this->data->has('test2'), 'no test2');
     $this->data->set('test', $data);
     $this->assertSame($data, $this->data->get('test'));
     $this->assertEquals('one', $this->data->get('test2'));
     $this->assertTrue($this->data->has('test'), 'has test');
     $this->assertTrue($this->data->has('test2'), 'has test2');
     $this->data->set('test2', 'two');
     $this->assertEquals('two', $this->data->get('test2'));
     $actualTest = $this->data->get('test');
     $this->assertEquals('two', $actualTest->value);
     $propertyPath = new PropertyPath('[test].value');
     $this->assertEquals('two', $this->data->get($propertyPath));
 }
Beispiel #6
0
 /**
  * Get data
  *
  * @return WorkflowData
  * @throws WorkflowException If data cannot be deserialized
  */
 public function getData()
 {
     if (!$this->data) {
         if (!$this->serializedData) {
             $this->data = new WorkflowData();
         } elseif (!$this->serializer) {
             throw new WorkflowException('Cannot deserialize data of workflow item. Serializer is not available.');
         } else {
             $this->serializer->setWorkflowName($this->workflowName);
             $this->data = $this->serializer->deserialize($this->serializedData, 'Oro\\Bundle\\WorkflowBundle\\Model\\WorkflowData', $this->serializeFormat);
             $this->data->set($this->getDefinition()->getEntityAttributeName(), $this->getEntity(), false);
         }
     }
     return $this->data;
 }
 public function testDenormalize()
 {
     $attributeName = 'test_attribute';
     $data = array($attributeName => 'normalized_value');
     $expectedData = new WorkflowData(array($attributeName => 'denormalized_value'));
     $this->normalizer->addAttributeNormalizer($this->attributeNormalizer);
     $this->normalizer->setSerializer($this->serializer);
     $this->serializer->expects($this->once())->method('getWorkflow')->will($this->returnValue($this->workflow));
     $this->attributeManager->expects($this->once())->method('getAttribute')->with($attributeName)->will($this->returnValue($this->attribute));
     $this->attributeNormalizer->expects($this->once())->method('supportsDenormalization')->with($this->workflow, $this->attribute, $data[$attributeName])->will($this->returnValue(true));
     $this->attributeNormalizer->expects($this->once())->method('denormalize')->with($this->workflow, $this->attribute, $data[$attributeName])->will($this->returnValue($expectedData->get($attributeName)));
     $this->assertEquals($expectedData, $this->normalizer->denormalize($data, 'Oro\\Bundle\\WorkflowBundle\\Model\\WorkflowData'));
 }