[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/active_record/tests/cases/ -> lmbARRelationsDefinitionMethodsTest.class.php (source)

   1  <?php
   2  /*

   3   * Limb PHP Framework

   4   *

   5   * @link http://limb-project.com

   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)

   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html

   8   */
   9  lmb_require('limb/active_record/src/lmbActiveRecord.class.php');
  10  lmb_require('limb/dbal/src/lmbSimpleDb.class.php');
  11  
  12  class TestOneTableObjectWithRelationsByMethods extends lmbActiveRecord
  13  {
  14    protected $_db_table_name = 'test_one_table_object';
  15  
  16    public $relations = array();
  17  
  18    function _defineRelations()
  19    {
  20      parent :: _defineRelations();
  21  
  22      $this->_hasOne('has_one_relation', $has_one = array('field' => 'child_id',
  23                                                          'class' => 'ChildClass'));
  24      $this->relations['has_one_relation'] = $has_one;
  25  
  26  
  27      $this->_hasOne('other_has_one_relation', $other_has_one = array('field' => 'other_child_id',
  28                                                                      'class' => 'OtherChildClass'));
  29      $this->relations['other_has_one_relation'] = $other_has_one;
  30  
  31  
  32      $this->_hasMany('has_many_relation', $has_many = array('field' => 'parent_id',
  33                                                             'class' => 'ManyChildClass'));
  34      $this->relations['has_many_relation'] = $has_many;
  35  
  36  
  37      $this->_hasMany('other_has_many_relation', $other_has_many = array('field' => 'other_parent_id',
  38                                                                         'class' => 'OtherManyChildClass'));
  39      $this->relations['other_has_many_relation'] = $other_has_many;
  40  
  41  
  42      $this->_hasManyToMany('has_many_to_many_relation',  $many_to_many = array('field' => 'my_id',
  43                                                                                'foreign_field' => 'important_id',
  44                                                                                'class' => 'ImportantClass',
  45                                                                                'table_name' => 'me2importand_class'));
  46      $this->relations['has_many_to_many_relation'] = $many_to_many;
  47  
  48  
  49      $this->_hasManyToMany('other_has_many_to_many_relation',  $other_many_to_many = array('field' => 'my_id',
  50                                                                                            'foreign_field' => 'other_important_id',
  51                                                                                            'class' => 'OtherImportantClass',
  52                                                                                            'table_name' => 'me2other_importand_class'));
  53      $this->relations['other_has_many_to_many_relation'] = $other_many_to_many;
  54  
  55  
  56      $this->_belongsTo('belongs_to_relation', $belongs_to = array('field' => 'my_id',
  57                                                                   'class' => 'ParentClass'));
  58      $this->relations['belongs_to_relation'] = $belongs_to;
  59  
  60  
  61      $this->_belongsTo('other_belongs_to_relation', $other_belongs_to = array('field' => 'my_id',
  62                                                                               'class' => 'OtherParentClass'));
  63      $this->relations['other_belongs_to_relation'] = $other_belongs_to;
  64  
  65  
  66      $this->_manyBelongsTo('many_belongs_to_relation', $many_belongs_to = array('field' => 'parent_id',
  67                                                                                 'class' => 'ParentClass'));
  68      $this->relations['many_belongs_to_relation'] = $many_belongs_to;
  69  
  70  
  71      $this->_manyBelongsTo('other_many_belongs_to_relation', $other_many_belongs_to =  array('field' => 'parent_id',
  72                                                                                              'class' => 'OtherParentClass'));
  73      $this->relations['other_many_belongs_to_relation'] = $other_many_belongs_to;
  74  
  75      $this->_composedOf('value_object', $value_object = array('field' => 'date_start',
  76                                                               'class' => 'lmbDate',
  77                                                               'getter' => 'getStamp'));
  78  
  79      $this->relations['value_object'] = $value_object;
  80  
  81  
  82      $this->_composedOf('other_value_object', $other_value_object = array('field' => 'date_end',
  83                                                                           'class' => 'lmbDate',
  84                                                                           'getter' => 'getStamp'));
  85      $this->relations['other_value_object'] = $other_value_object;
  86    }
  87  }
  88  
  89  class lmbARRelationsDefinitionMethodsTest extends UnitTestCase
  90  {
  91    protected $object;
  92  
  93    function setUp()
  94    {
  95      $this->object = new TestOneTableObjectWithRelationsByMethods();
  96      $this->relations = $this->object->relations;
  97    }
  98  
  99    function testHasOne()
 100    {
 101      $this->assertEqual($this->object->getRelationInfo('has_one_relation'), $this->relations['has_one_relation']);
 102      $this->assertEqual($this->object->getRelationInfo('other_has_one_relation'), $this->relations['other_has_one_relation']);
 103    }
 104  
 105    function testHasMany()
 106    {
 107      $this->assertEqual($this->object->getRelationInfo('has_many_relation'), $this->relations['has_many_relation']);
 108      $this->assertEqual($this->object->getRelationInfo('other_has_many_relation'), $this->relations['other_has_many_relation']);
 109    }
 110  
 111    function testHasManyToMany()
 112    {
 113      $this->assertEqual($this->object->getRelationInfo('has_many_to_many_relation'), $this->relations['has_many_to_many_relation']);
 114      $this->assertEqual($this->object->getRelationInfo('other_has_many_to_many_relation'), $this->relations['other_has_many_to_many_relation']);
 115    }
 116  
 117    function testBelongsTo()
 118    {
 119      $this->assertEqual($this->object->getRelationInfo('belongs_to_relation'), $this->relations['belongs_to_relation']);
 120      $this->assertEqual($this->object->getRelationInfo('other_belongs_to_relation'), $this->relations['other_belongs_to_relation']);
 121    }
 122  
 123    function testManyBelongsTo()
 124    {
 125      $this->assertEqual($this->object->getRelationInfo('many_belongs_to_relation'), $this->relations['many_belongs_to_relation']);
 126      $this->assertEqual($this->object->getRelationInfo('other_many_belongs_to_relation'), $this->relations['other_many_belongs_to_relation']);
 127    }
 128  
 129    function testComposedOf()
 130    {
 131      $this->assertEqual($this->object->getRelationInfo('value_object'), $this->relations['value_object']);
 132      $this->assertEqual($this->object->getRelationInfo('other_value_object'), $this->relations['other_value_object']);
 133    }
 134  }
 135  
 136  ?>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7