mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX #5337: Allow decoration of DataObject
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@102081 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
6db693a09e
commit
20a61098c6
@ -640,7 +640,7 @@ abstract class Object {
|
||||
$this->class = get_class($this);
|
||||
|
||||
// Don't bother checking some classes that should never be extended
|
||||
static $notExtendable = array('Object', 'ViewableData', 'DataObject', 'RequestHandler');
|
||||
static $notExtendable = array('Object', 'ViewableData', 'RequestHandler');
|
||||
|
||||
if($extensionClasses = ClassInfo::ancestry($this->class)) foreach($extensionClasses as $class) {
|
||||
if(in_array($class, $notExtendable)) continue;
|
||||
|
@ -455,8 +455,6 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
* Called by Object::__construct() once per class.
|
||||
*/
|
||||
function defineMethods() {
|
||||
if($this->class == 'DataObject') return;
|
||||
|
||||
parent::defineMethods();
|
||||
|
||||
// Define the extra db fields - this is only necessary for extensions added in the
|
||||
@ -470,6 +468,8 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
}
|
||||
}
|
||||
|
||||
if($this->class == 'DataObject') return;
|
||||
|
||||
// Set up accessors for joined items
|
||||
if($manyMany = $this->many_many()) {
|
||||
foreach($manyMany as $relationship => $class) {
|
||||
|
@ -10,6 +10,10 @@ class DataObjectDecoratorTest extends SapphireTest {
|
||||
'DataObjectDecoratorTest_MyObject',
|
||||
);
|
||||
|
||||
protected $requiredExtensions = array(
|
||||
'DataObject' => array( 'DataObjectDecoratorTest_AppliedToDO' ),
|
||||
);
|
||||
|
||||
function testOneToManyAssociationWithDecorator() {
|
||||
// Fails in RestfulServerTest
|
||||
// Error: Object::__call() Method 'RelatedObjects' not found in class 'RestfulServerTest_Comment'
|
||||
@ -141,6 +145,17 @@ class DataObjectDecoratorTest extends SapphireTest {
|
||||
$this->assertNotNull($member->dbObject('Website'));
|
||||
$this->assertType('Varchar', $member->dbObject('Website'));
|
||||
}
|
||||
|
||||
function testDecoratorCanBeAppliedToDataObject() {
|
||||
$do = new DataObject();
|
||||
$mo = new DataObjectDecoratorTest_MyObject();
|
||||
|
||||
$this->assertTrue($do->hasMethod('testMethodApplied'));
|
||||
$this->assertTrue($mo->hasMethod('testMethodApplied'));
|
||||
|
||||
$this->assertEquals("hello world", $mo->testMethodApplied());
|
||||
$this->assertEquals("hello world", $do->testMethodApplied());
|
||||
}
|
||||
}
|
||||
|
||||
class DataObjectDecoratorTest_Member extends DataObject implements TestOnly {
|
||||
@ -287,6 +302,12 @@ class DataObjectDecoratorTest_Faves extends DataObjectDecorator implements TestO
|
||||
}
|
||||
}
|
||||
|
||||
class DataObjectDecoratorTest_AppliedToDO extends DataObjectDecorator implements TestOnly {
|
||||
public function testMethodApplied() {
|
||||
return "hello world";
|
||||
}
|
||||
}
|
||||
|
||||
DataObject::add_extension('DataObjectDecoratorTest_MyObject', 'DataObjectDecoratorTest_Ext1');
|
||||
DataObject::add_extension('DataObjectDecoratorTest_MyObject', 'DataObjectDecoratorTest_Ext2');
|
||||
DataObject::add_extension('DataObjectDecoratorTest_MyObject', 'DataObjectDecoratorTest_Faves');
|
||||
|
Loading…
x
Reference in New Issue
Block a user