From 78ceca69346670dbcfb479661074a366fb9a217a Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 5 Nov 2018 16:09:49 +1300 Subject: [PATCH] MINOR: Add test for defaults on subclasses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was raised in https://github.com/silverstripe/silverstripe-framework/issues/8567 and wasn’t covered by a test. --- tests/php/ORM/DataObjectTest.php | 7 +++++++ tests/php/ORM/DataObjectTest/Staff.php | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/tests/php/ORM/DataObjectTest.php b/tests/php/ORM/DataObjectTest.php index c0d81c15f..aee0b8d1c 100644 --- a/tests/php/ORM/DataObjectTest.php +++ b/tests/php/ORM/DataObjectTest.php @@ -1456,6 +1456,13 @@ class DataObjectTest extends SapphireTest 'Default Value', 'Defaults are populated from overloaded populateDefaults() method' ); + + // Test populate defaults on subclasses + $staffObj = new DataObjectTest\Staff(); + $this->assertEquals('Staff', $staffObj->EmploymentType); + + $ceoObj = new DataObjectTest\CEO(); + $this->assertEquals('Staff', $ceoObj->EmploymentType); } /** diff --git a/tests/php/ORM/DataObjectTest/Staff.php b/tests/php/ORM/DataObjectTest/Staff.php index bc66d3fff..fbf7ae130 100644 --- a/tests/php/ORM/DataObjectTest/Staff.php +++ b/tests/php/ORM/DataObjectTest/Staff.php @@ -9,6 +9,7 @@ class Staff extends DataObject implements TestOnly { private static $db = array( 'Salary' => 'BigInt', + 'EmploymentType' => 'Varchar', ); private static $table_name = 'DataObjectTest_Staff'; @@ -17,4 +18,8 @@ class Staff extends DataObject implements TestOnly 'CurrentCompany' => Company::class, 'PreviousCompany' => Company::class ); + + private static $defaults = [ + 'EmploymentType' => 'Staff', + ]; }