Esempio n. 1
0
 public function testRelationFromFieldName()
 {
     MockPost::bind('hasMany', 'MockTag');
     $this->assertEqual('MockComment', MockPost::relations('mock_comments')->name());
     $this->assertEqual('MockTag', MockPost::relations('mock_tags')->name());
     $this->assertEqual('MockPost', MockComment::relations('mock_post')->name());
     $this->assertNull(MockPost::relations('undefined'));
 }
Esempio n. 2
0
 /**
  * Tests introspecting the relationship settings for the model as a whole, various relationship
  * types, and individual relationships.
  *
  * @todo Some tests will need to change when full relationship support is built out.
  * @return void
  */
 public function testRelationshipIntrospection()
 {
     $result = MockPost::relations();
     $expected = array('MockComment');
     $this->assertEqual($expected, $result);
     $result = MockPost::relations('hasMany');
     $this->assertEqual($expected, $result);
     $result = 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'));
     $this->assertNull(MockComment::relations('MockPost'));
     $this->assertNull(MockPost::relations('MockComment'));
 }
Esempio n. 3
0
 public function testLazyLoad()
 {
     $object = MockPost::invokeMethod('_object');
     $object->belongsTo = array('Unexisting');
     MockPost::config();
     MockPost::invokeMethod('_initialize', array('lithium\\tests\\mocks\\data\\MockPost'));
     $exception = 'Related model class \'lithium\\tests\\mocks\\data\\Unexisting\' not found.';
     $this->expectException($exception);
     MockPost::relations('Unexisting');
 }
Esempio n. 4
0
 /**
  * Tests introspecting the relationship settings for the model as a whole, various relationship
  * types, and individual relationships.
  *
  * @todo Some tests will need to change when full relationship support is built out.
  * @return void
  */
 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', 'keys' => array('mock_post_id' => 'id'), 'from' => 'lithium\\tests\\mocks\\data\\MockComment', 'to' => 'lithium\\tests\\mocks\\data\\MockPost', 'link' => 'key', 'fields' => true, 'fieldName' => 'mockPost', 'conditions' => null, 'init' => true);
     $this->assertEqual($expected, MockComment::relations('MockPost')->data());
     $expected = array('name' => 'MockComment', 'type' => 'hasMany', 'from' => 'lithium\\tests\\mocks\\data\\MockPost', 'to' => 'lithium\\tests\\mocks\\data\\MockComment', 'fields' => true, 'keys' => array('mock_post_id' => 'id'), 'link' => 'key', 'fieldName' => 'mockComment', 'conditions' => null, 'init' => true);
     $this->assertEqual($expected, MockPost::relations('MockComment')->data());
 }