function testTwoSubclassesWithTheSameFieldNameWork() { // Create two objects of different subclasses, setting the values of fields that are // defined separately in each subclass $obj1 = new DataObjectTest_SubTeam(); $obj1->SubclassDatabaseField = "obj1"; $obj2 = new OtherSubclassWithSameField(); $obj2->SubclassDatabaseField = "obj2"; // Write them to the database $obj1->write(); $obj2->write(); // Check that the values of those fields are properly read from the database $values = DataObject::get("DataObjectTest_Team", "\"DataObjectTest_Team\".\"ID\" IN \n\t\t\t({$obj1->ID}, {$obj2->ID})")->column("SubclassDatabaseField"); $this->assertEquals(array('obj1', 'obj2'), $values); }
public function testForceInsert() { /* If you set an ID on an object and pass forceInsert = true, then the object should be correctly created */ $obj = new DataObjectTest_SubTeam(); $obj->ID = 1001; $obj->Title = 'asdfasdf'; $obj->SubclassDatabaseField = 'asdfasdf'; $obj->write(false, true); $this->assertEquals("DataObjectTest_SubTeam", DB::query("SELECT ClassName FROM DataObjectTest_Team WHERE ID = $obj->ID")->value()); /* Check that it actually saves to the database with the correct ID */ $this->assertEquals("1001", DB::query("SELECT ID FROM DataObjectTest_SubTeam WHERE SubclassDatabaseField = 'asdfasdf'")->value()); $this->assertEquals("1001", DB::query("SELECT ID FROM DataObjectTest_Team WHERE Title = 'asdfasdf'")->value()); }