Permalink
Browse files

MINOR Added test for has one relation getters in DataObjectTest

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@77313 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent b57f60b commit 5a277c7a2cc8f26b024ae2fd1226468cf02224a0 @halkyon halkyon committed with sminnee May 20, 2009
Showing with 16 additions and 1 deletion.
  1. +16 −1 tests/DataObjectTest.php
View
@@ -154,6 +154,21 @@ function testHasManyRelationships() {
$this->assertTrue($comment->ParentID == $page->ID);
}
}
+
+ function testHasOneRelationship() {
+ $team1 = $this->fixture->objFromFixture('DataObjectTest_Team', 'team1');
+ $player1 = $this->fixture->objFromFixture('DataObjectTest_Player', 'player1');
+
+ // Add a captain to team 1
+ $team1->setField('CaptainID', $player1->ID);
+ $team1->write();
+
+ $this->assertEquals($player1->ID, $team1->Captain()->ID, 'The captain exists for team 1');
+ $this->assertEquals($player1->ID, $team1->getComponent('Captain')->ID, 'The captain exists through the component getter');
+
+ $this->assertEquals($team1->Captain()->FirstName, 'Player 1', 'Player 1 is the captain');
+ $this->assertEquals($team1->getComponent('Captain')->FirstName, 'Player 1', 'Player 1 is the captain');
+ }
/**
* @todo Test removeMany() and addMany() on $many_many relationships
@@ -577,7 +592,7 @@ class DataObjectTest_Player extends Member implements TestOnly {
static $has_one = array(
'FavouriteTeam' => 'DataObjectTest_Team',
);
-
+
static $belongs_many_many = array(
'Teams' => 'DataObjectTest_Team'
);

0 comments on commit 5a277c7

Please sign in to comment.