public function testBelongsTo()
 {
     $company = new DataObjectTest_Company();
     $ceo = new DataObjectTest_CEO();
     $company->write();
     $ceo->write();
     $company->CEOID = $ceo->ID;
     $company->write();
     $this->assertEquals($company->ID, $ceo->Company()->ID, 'belongs_to returns the right results.');
     $ceo = new DataObjectTest_CEO();
     $ceo->write();
     $this->assertTrue($ceo->Company() instanceof DataObjectTest_Company, 'DataObjects across belongs_to relations are automatically created.');
     $this->assertEquals($ceo->ID, $ceo->Company()->CEOID, 'Remote IDs are automatically set.');
     $ceo->write(false, false, false, true);
     $this->assertTrue($ceo->Company()->isInDB(), 'write() writes belongs_to components to the database.');
     $newCEO = DataObject::get_by_id('DataObjectTest_CEO', $ceo->ID);
     $this->assertEquals($ceo->Company()->ID, $newCEO->Company()->ID, 'belongs_to can be retrieved from the database.');
 }
 public function testBelongsToPolymorphic()
 {
     $company = new DataObjectTest_Company();
     $ceo = new DataObjectTest_CEO();
     $company->write();
     $ceo->write();
     // Test belongs_to assignment
     $company->OwnerID = $ceo->ID;
     $company->OwnerClass = $ceo->class;
     $company->write();
     $this->assertEquals($company->ID, $ceo->CompanyOwned()->ID, 'belongs_to returns the right results.');
     $this->assertEquals($company->class, $ceo->CompanyOwned()->class, 'belongs_to returns the right results.');
     // Test automatic creation of class where no assigment exists
     $ceo = new DataObjectTest_CEO();
     $ceo->write();
     $this->assertTrue($ceo->CompanyOwned() instanceof DataObjectTest_Company, 'DataObjects across polymorphic belongs_to relations are automatically created.');
     $this->assertEquals($ceo->ID, $ceo->CompanyOwned()->OwnerID, 'Remote IDs are automatically set.');
     $this->assertInstanceOf($ceo->CompanyOwned()->OwnerClass, $ceo, 'Remote class is automatically  set');
     // Write object with components
     $ceo->write(false, false, false, true);
     $this->assertTrue($ceo->CompanyOwned()->isInDB(), 'write() writes belongs_to components to the database.');
     $newCEO = DataObject::get_by_id('DataObjectTest_CEO', $ceo->ID);
     $this->assertEquals($ceo->CompanyOwned()->ID, $newCEO->CompanyOwned()->ID, 'polymorphic belongs_to can be retrieved from the database.');
 }