Extends
lithium\test\Unit
Tests introspecting the relationship settings for the model as a whole, various relationship
types, and individual relationships.
Returns
voidSource
public function testRelationshipIntrospection() {
$result = array_keys(MockPost::relations());
$expected = array('MockComment');
$this->assertEqual($expected, $result);
$result = MockPost::relations('hasMany');
$this->assertEqual($expected, $result);
$result = array_keys(MockComment::relations());
$expected = array('MockPost');
$this->assertEqual($expected, $result);
$result = MockComment::relations('belongsTo');
$this->assertEqual($expected, $result);
$this->assertFalse(MockComment::relations('hasMany'));
$this->assertFalse(MockPost::relations('belongsTo'));
$expected = array(
'name' => 'MockPost',
'type' => 'belongsTo',
'key' => array('mock_post_id' => 'id'),
'from' => 'lithium\tests\mocks\data\MockComment',
'to' => 'lithium\tests\mocks\data\MockPost',
'link' => 'key',
'fields' => true,
'fieldName' => 'mock_post',
'constraint' => array(),
'init' => true
);
$this->assertEqual($expected, MockComment::relations('MockPost')->data());
$expected = array('MockComment.mock_post_id' => 'MockPost.id');
$this->assertEqual($expected, MockComment::relations('MockPost')->constraints());
$expected = array(
'name' => 'MockComment',
'type' => 'hasMany',
'from' => 'lithium\tests\mocks\data\MockPost',
'to' => 'lithium\tests\mocks\data\MockComment',
'fields' => true,
'key' => array('id' => 'mock_post_id'),
'link' => 'key',
'fieldName' => 'mock_comments',
'constraint' => array(),
'init' => true
);
$this->assertEqual($expected, MockPost::relations('MockComment')->data());
$expected = array('MockPost.id' => 'MockComment.mock_post_id');
$this->assertEqual($expected, MockPost::relations('MockComment')->constraints());
}