BUGFIX #3919: Fix DataObject::dbObject() for decorated fields

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@75150 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-04-27 00:44:10 +00:00
parent 8fcdcfa2eb
commit b165bde578
4 changed files with 27 additions and 4 deletions

View File

@ -211,19 +211,19 @@ class ViewableData extends Object implements IteratorAggregate {
public function buildCastingHelperCache(&$cache) {
$class = $this->class ? $this->class : get_class($this);
$classes = ClassInfo::ancestry($class);
foreach($classes as $componentClass) {
if($componentClass == "ViewableData") $isViewableData = true;
if($componentClass == "DataObject") $isDataObject = true;
if(isset($isDataObject) && $isDataObject) {
$fields = eval("return {$componentClass}::\$db;");
$fields = Object::uninherited_static($componentClass, 'db');
if($fields) foreach($fields as $fieldName => $fieldSchema) {
$cache[$fieldName] = ViewableData::castingObjectCreatorPair($fieldSchema);
}
}
if(isset($isViewableData) && $isViewableData) {
$fields = eval("return {$componentClass}::\$casting;");
$fields = Object::uninherited_static($componentClass, 'casting');
if($fields) foreach($fields as $fieldName => $fieldSchema) {
$cache[$fieldName] = ViewableData::castingObjectCreatorPair($fieldSchema);
}

View File

@ -64,7 +64,15 @@ class DataObjectDecoratorTest extends SapphireTest {
'Defaults can be populated through decorator'
);
}
/**
* Test that DataObject::dbObject() works for fields applied by a decorator
*/
function testDbObjectOnDecoratedFields() {
$member = $this->objFromFixture('DataObjectDecoratorTest_Member', 'member1');
$this->assertNotNull($member->dbObject('Website'));
$this->assertType('Text', $member->dbObject('Website'));
}
}
class DataObjectDecoratorTest_Member extends DataObject implements TestOnly {

View File

@ -33,6 +33,10 @@ Member:
Groups: =>Group.admingroup
websiteuser:
Email: websiteuser@test.com
DataObjectDecoratorTest_Member:
member1:
Name: Sam
Website: http://www.example.org
DataObjectDecoratorTest_MyObject:
object1:
Title: Object 1

View File

@ -69,6 +69,17 @@ class ObjectStaticTest extends SapphireTest {
);
}
/**
* Check that calls to Object::add_static() will update the data returned by Object::uninherited_static()
*/
public function testAddStaticFollowedByUnheritedCall() {
Object::add_static_var('ObjectStaticTest_First', 'first', array('test_1b'));
Object::add_static_var('ObjectStaticTest_Second', 'first', array('test_2b'));
$this->assertContains('test_1b', Object::uninherited_static('ObjectStaticTest_First', 'first'));
$this->assertContains('test_2b', Object::uninherited_static('ObjectStaticTest_Second', 'first'));
}
}
/**#@+