Skip to content

Commit

Permalink
Support embedded object for the show mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
claudusd committed Jun 1, 2016
1 parent 6eeb1ad commit 5c99a46
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Admin/FieldDescription.php
Expand Up @@ -98,6 +98,10 @@ public function getValue($object)
$object = $this->getFieldValue($object, $parentAssociationMapping['fieldName']);
}

if (isset($this->getFieldMapping()['declaredField'])) {
$object = $this->getFieldValue($object, $this->getFieldMapping()['declaredField']);
}

return $this->getFieldValue($object, $this->fieldName);
}
}
22 changes: 22 additions & 0 deletions Tests/Admin/FieldDescriptionTest.php
Expand Up @@ -330,4 +330,26 @@ public function testGetFieldMapping()

$this->assertEquals($fieldMapping, $field->getFieldMapping());
}

public function testGetValueForEmbeddedObject()
{
$mockedEmbeddedObject = $this->getMock('MockedTestObject', array('myMethod'));
$mockedEmbeddedObject->expects($this->once())
->method('myMethod')
->will($this->returnValue('myMethodValue'));

$mockedObject = $this->getMock('MockedTestObject', array('getMyEmbeddedObject'));
$mockedObject->expects($this->once())
->method('getMyEmbeddedObject')
->will($this->returnValue($mockedEmbeddedObject));

$field = new FieldDescription();
$field->setFieldMapping(array(
'declaredField' => 'myEmbeddedObject', 'type' => 'string', 'fieldName' => 'myEmbeddedObject.myMethod'
));
$field->setFieldName('myMethod');
$field->setOption('code', 'myMethod');

$this->assertEquals('myMethodValue', $field->getValue($mockedObject));
}
}

0 comments on commit 5c99a46

Please sign in to comment.