[Solar-svn] Revision 2728

pmjones at solarphp.com pmjones at solarphp.com
Tue Aug 21 10:18:59 CDT 2007


Branch: tests: continued updates to Solar_Model tests (including belongs-to and has-one testing)



Modified: branches/orm/tests/Test/Solar/Sql/Model/Catalog.php
===================================================================
--- branches/orm/tests/Test/Solar/Sql/Model/Catalog.php	2007-08-21 15:18:03 UTC (rev 2727)
+++ branches/orm/tests/Test/Solar/Sql/Model/Catalog.php	2007-08-21 15:18:58 UTC (rev 2728)
@@ -113,4 +113,16 @@
         $this->todo('stub');
     }
 
+    
+    /**
+     * 
+     * Test -- Resets (removes) all the catalog data, or resets (removes) just the catalog data for one class.
+     * 
+     */
+    public function testReset()
+    {
+        $this->todo('stub');
+    }
+
+
 }

Modified: branches/orm/tests/Test/Solar/Sql/Model/Collection.php
===================================================================
--- branches/orm/tests/Test/Solar/Sql/Model/Collection.php	2007-08-21 15:18:03 UTC (rev 2727)
+++ branches/orm/tests/Test/Solar/Sql/Model/Collection.php	2007-08-21 15:18:58 UTC (rev 2728)
@@ -393,4 +393,6 @@
         $this->todo('stub');
     }
 
+
+
 }

Modified: branches/orm/tests/Test/Solar/Sql/Model/Filter/ValidateConfirm.php
===================================================================
--- branches/orm/tests/Test/Solar/Sql/Model/Filter/ValidateConfirm.php	2007-08-21 15:18:03 UTC (rev 2727)
+++ branches/orm/tests/Test/Solar/Sql/Model/Filter/ValidateConfirm.php	2007-08-21 15:18:58 UTC (rev 2728)
@@ -93,4 +93,6 @@
         $this->todo('stub');
     }
 
+
+
 }

Modified: branches/orm/tests/Test/Solar/Sql/Model/Filter/ValidateUnique.php
===================================================================
--- branches/orm/tests/Test/Solar/Sql/Model/Filter/ValidateUnique.php	2007-08-21 15:18:03 UTC (rev 2727)
+++ branches/orm/tests/Test/Solar/Sql/Model/Filter/ValidateUnique.php	2007-08-21 15:18:58 UTC (rev 2728)
@@ -93,4 +93,6 @@
         $this->todo('stub');
     }
 
+
+
 }

Modified: branches/orm/tests/Test/Solar/Sql/Model/Filter.php
===================================================================
--- branches/orm/tests/Test/Solar/Sql/Model/Filter.php	2007-08-21 15:18:03 UTC (rev 2727)
+++ branches/orm/tests/Test/Solar/Sql/Model/Filter.php	2007-08-21 15:18:58 UTC (rev 2728)
@@ -263,4 +263,6 @@
         $this->todo('stub');
     }
 
+
+
 }

Modified: branches/orm/tests/Test/Solar/Sql/Model/Record.php
===================================================================
--- branches/orm/tests/Test/Solar/Sql/Model/Record.php	2007-08-21 15:18:03 UTC (rev 2727)
+++ branches/orm/tests/Test/Solar/Sql/Model/Record.php	2007-08-21 15:18:58 UTC (rev 2728)
@@ -393,4 +393,6 @@
         $this->todo('stub');
     }
 
+
+
 }

Modified: branches/orm/tests/Test/Solar/Sql/Model.php
===================================================================
--- branches/orm/tests/Test/Solar/Sql/Model.php	2007-08-21 15:18:03 UTC (rev 2727)
+++ branches/orm/tests/Test/Solar/Sql/Model.php	2007-08-21 15:18:58 UTC (rev 2728)
@@ -22,24 +22,6 @@
  *     
  *     - reads table properly (and overrides local settings)
  *     
- * - fetching with One and All
- * 
- *     - lazy-fetch a has_one related
- * 
- *     - lazy-fetch a belongs_to related
- * 
- *     - lazy-fetch a has_many related
- * 
- *     - lazy-fetch a has_many_through related
- * 
- *     - eager-fetch a has_one related
- * 
- *     - eager-fetch a belongs_to related
- * 
- *     - eager-fetch a has_many related
- * 
- *     - eager-fetch a has_many_through related
- * 
  * - test honoring of $_fetch_cols
  * 
  * - collections
@@ -51,7 +33,9 @@
  *     - delete from a collection
  * 
  *     - do unit-of-work on a collection
- *     
+ * 
+ * - automatic setting of related ID for belongs_to, has_one, and has_many
+ * 
  */
 class Test_Solar_Sql_Model extends Solar_Test {
     
@@ -134,7 +118,7 @@
      * Convenience method to get model objects with SQL dependency injection.
      * 
      */
-    protected function _getModel($name)
+    protected function _newModel($name)
     {
         $class = "Solar_Example_Model_$name";
         $model = Solar::factory($class, array('sql' => $this->_sql));
@@ -164,7 +148,7 @@
     
     protected function _populateSpecialColsTable()
     {
-        $model = $this->_getModel('TestSolarSpecialCols');
+        $model = $this->_newModel('TestSolarSpecialCols');
         for ($i = 1; $i <= 10; $i++) {
             $record = $model->fetchNew();
             $record->name = chr($i+96); //ascii 'a', 'b', etc
@@ -185,7 +169,7 @@
      */
     public function test__construct()
     {
-        $obj = $this->_getModel('TestSolarSpecialCols');
+        $obj = $this->_newModel('TestSolarSpecialCols');
         $this->assertInstance($obj, 'Solar_Sql_Model');
         $this->assertInstance($obj, 'Solar_Example_Model_TestSolarSpecialCols');
         
@@ -207,7 +191,7 @@
          * to work with
          */
         $this->_populateSpecialColsTable();
-        $model = $this->_getModel('TestSolarSpecialCols');
+        $model = $this->_newModel('TestSolarSpecialCols');
         for ($i = 0; $i < 5; $i++) {
             // id's are 11-15, all named 'z' with seq_foo of 88
             $record = $model->fetchNew();
@@ -303,7 +287,7 @@
      */
     public function test__get()
     {
-        $model = $this->_getModel('TestSolarSpecialCols');
+        $model = $this->_newModel('TestSolarSpecialCols');
         
         // reads from protected $_primary_col; should be no exception
         $actual = $model->primary_col;
@@ -327,7 +311,7 @@
     public function testCountPages()
     {
         $this->_populateSpecialColsTable();
-        $model = $this->_getModel('TestSolarSpecialCols');
+        $model = $this->_newModel('TestSolarSpecialCols');
         $model->setPaging(3);
         $actual = $model->countPages();
         $expect = array('count' => 10, 'pages' => 4);
@@ -350,7 +334,7 @@
     public function testDeleteRecord()
     {
         $this->_populateSpecialColsTable();
-        $model = $this->_getModel('TestSolarSpecialCols');
+        $model = $this->_newModel('TestSolarSpecialCols');
         
         $record = $model->fetch(7);
         $this->assertEquals($record->id, 7);
@@ -380,7 +364,7 @@
         $this->_populateSpecialColsTable();
         
         // fetch by number to get a Record
-        $model = $this->_getModel('TestSolarSpecialCols');
+        $model = $this->_newModel('TestSolarSpecialCols');
         $record = $model->fetch(3);
         $this->assertInstance($record, 'Solar_Sql_Model_Record');
         $this->assertInstance($record, 'Solar_Example_Model_TestSolarSpecialCols_Record');
@@ -409,7 +393,7 @@
         $this->_populateSpecialColsTable();
         
         // fetch by some WHERE clause
-        $model = $this->_getModel('TestSolarSpecialCols');
+        $model = $this->_newModel('TestSolarSpecialCols');
         $collection = $model->fetchAll(array('where' => 'id > 5'));
         
         // tests
@@ -433,7 +417,7 @@
         $this->_populateSpecialColsTable();
         
         // fetch by some WHERE clause
-        $model = $this->_getModel('TestSolarSpecialCols');
+        $model = $this->_newModel('TestSolarSpecialCols');
         $collection = $model->fetchAssoc(array(
             'where' => 'id > 5',
             'order' => 'name',
@@ -465,7 +449,7 @@
         $this->_populateSpecialColsTable();
         
         // fetch by some WHERE clause
-        $model = $this->_getModel('TestSolarSpecialCols');
+        $model = $this->_newModel('TestSolarSpecialCols');
         $actual = $model->fetchCol(array(
             'where' => 'id > 5',
             'order' => 'name',
@@ -485,7 +469,7 @@
      */
     public function testFetchNew()
     {
-        $model = $this->_getModel('TestSolarSqlDescribe');
+        $model = $this->_newModel('TestSolarSqlDescribe');
         $record = $model->fetchNew();
         
         // these are the default values on the test_solar_sql_describe table
@@ -507,7 +491,7 @@
         $this->_populateSpecialColsTable();
         
         // fetch by number to get a Record
-        $model = $this->_getModel('TestSolarSpecialCols');
+        $model = $this->_newModel('TestSolarSpecialCols');
         $record = $model->fetchOne(array(
             'where' => array('name = ?' => 'c'),
         ));
@@ -528,7 +512,7 @@
         $this->_populateSpecialColsTable();
         
         // fetch by some WHERE clause
-        $model = $this->_getModel('TestSolarSpecialCols');
+        $model = $this->_newModel('TestSolarSpecialCols');
         $actual = $model->fetchPairs(array(
             'where' => 'id > 5',
             'order' => 'name',
@@ -555,7 +539,7 @@
      */
     public function testGetPaging()
     {
-        $model = $this->_getModel('TestSolarSpecialCols');
+        $model = $this->_newModel('TestSolarSpecialCols');
         
         $expect = 50;
         $model->setPaging($expect);
@@ -571,7 +555,7 @@
      */
     public function testInsertRecord()
     {
-        $model = $this->_getModel('TestSolarFoo');
+        $model = $this->_newModel('TestSolarFoo');
         $record = $model->fetchNew();
         
         $email = 'nobody at example.com';
@@ -601,7 +585,7 @@
      */
     public function testInsertRecord_invalid()
     {
-        $model = $this->_getModel('TestSolarFoo');
+        $model = $this->_newModel('TestSolarFoo');
         
         // insert should fail
         $record = $model->fetchNew();
@@ -629,7 +613,7 @@
      */
     public function testInsertRecord_invalidAtDatabase()
     {
-        $model = $this->_getModel('TestSolarFoo');
+        $model = $this->_newModel('TestSolarFoo');
         
         // insert should succeed
         $record = $model->fetchNew();
@@ -660,7 +644,7 @@
      */
     public function testInsertRecord_inherit()
     {
-        $model = $this->_getModel('TestSolarFoo_Bar');
+        $model = $this->_newModel('TestSolarFoo_Bar');
         
         // it should self-set its inheritance value
         $record = $model->fetchNew();
@@ -684,30 +668,30 @@
     {
         $data = array();
         
-        $model = $this->_getModel('TestSolarFoo');
+        $model = $this->_newModel('TestSolarFoo');
         $collection = $model->newCollection($data);
         $this->assertInstance($collection, 'Solar_Example_Model_TestSolarFoo_Collection');
         
         // the Foo_Bar model doesn't have its own collection, should fall back to foo
-        $model = $this->_getModel('TestSolarFoo_Bar');
+        $model = $this->_newModel('TestSolarFoo_Bar');
         $collection = $model->newCollection($data);
         $this->assertInstance($collection, 'Solar_Example_Model_TestSolarFoo_Collection');
         
         // the Dib mode has no collection and is not inherited, should fall back to Solar_Sql
-        $model = $this->_getModel('TestSolarDib');
+        $model = $this->_newModel('TestSolarDib');
         $collection = $model->newCollection($data);
         $this->assertInstance($collection, 'Solar_Sql_Model_Collection');
     }
     
-    // /**
-    //  * 
-    //  * Test -- Returns a new filter object with the chain already prepared.
-    //  * 
-    //  */
-    // public function testNewFilterObject()
-    // {
-    //     $this->todo('stub');
-    // }
+    /**
+     * 
+     * Test -- Returns a new filter object with the chain already prepared.
+     * 
+     */
+    public function testNewFilterObject()
+    {
+        $this->todo('stub');
+    }
     
     /**
      * 
@@ -730,7 +714,7 @@
         
         
         // non-inherited
-        $model = $this->_getModel('TestSolarFoo');
+        $model = $this->_newModel('TestSolarFoo');
         $record = $model->newRecord($data);
         $this->assertInstance($record, 'Solar_Example_Model_TestSolarFoo_Record');
         
@@ -745,7 +729,7 @@
         $this->assertInstance($record, 'Solar_Example_Model_TestSolarFoo_Record');
         
         // the Dib model has no record of its own, should use Solar_Sql_Model_Record
-        $model = $this->_getModel('TestSolarDib');
+        $model = $this->_newModel('TestSolarDib');
         $record = $model->newRecord($data);
         $this->assertInstance($record, 'Solar_Sql_Model_Record');
     }
@@ -760,7 +744,7 @@
         $this->_populateSpecialColsTable();
         
         // set it
-        $model = $this->_getModel('TestSolarSpecialCols');
+        $model = $this->_newModel('TestSolarSpecialCols');
         $expect = 3;
         $model->setPaging($expect);
         
@@ -803,7 +787,7 @@
      */
     public function testUpdateRecord()
     {
-        $model = $this->_getModel('TestSolarFoo');
+        $model = $this->_newModel('TestSolarFoo');
         
         /**
          * insert a valid record
@@ -857,7 +841,7 @@
      */
     public function testUpdateRecord_invalid()
     {
-        $model = $this->_getModel('TestSolarFoo');
+        $model = $this->_newModel('TestSolarFoo');
         
         // insert should pass
         $record = $model->fetchNew();
@@ -890,7 +874,7 @@
      */
     public function testUpdateRecord_invalidAtDatabase()
     {
-        $model = $this->_getModel('TestSolarFoo');
+        $model = $this->_newModel('TestSolarFoo');
         
         // insert should succeed
         $record = $model->fetchNew();
@@ -926,7 +910,7 @@
      */
     public function testUpdateRecord_inherit()
     {
-        $model = $this->_getModel('TestSolarFoo_Bar');
+        $model = $this->_newModel('TestSolarFoo_Bar');
         
         // it should self-set its inheritance value
         $record = $model->fetchNew();
@@ -955,7 +939,7 @@
      */
     public function testSpecialColumns()
     {
-        $model = $this->_getModel('TestSolarSpecialCols');
+        $model = $this->_newModel('TestSolarSpecialCols');
         
         /**
          * Correct population of new columns
@@ -1021,4 +1005,6 @@
         $this->assertEquals($record->seq_foo, 2);
         $this->assertEquals($record->seq_bar, 3);
     }
+
+
 }

Added: branches/orm/tests/Test/Solar/Sql/ModelRelated/BelongsTo.php
===================================================================
--- branches/orm/tests/Test/Solar/Sql/ModelRelated/BelongsTo.php	                        (rev 0)
+++ branches/orm/tests/Test/Solar/Sql/ModelRelated/BelongsTo.php	2007-08-21 15:18:58 UTC (rev 2728)
@@ -0,0 +1,160 @@
+<?php
+class Test_Solar_Sql_ModelRelated_BelongsTo extends Test_Solar_Sql_ModelRelated {
+    
+    /**
+     * 
+     * Depends on the Solar_Example_Model_Nodes having added $this->_belongsTo().
+     * 
+     */
+    public function testAddRelated()
+    {
+        $nodes = $this->_newModel('nodes');
+        
+        // make sure that nodes belongs-to area
+        $expect = array (
+            'name' => 'area',
+            'type' => 'belongs_to',
+            'foreign_model' => 'Solar_Example_Model_Areas',
+            'foreign_table' => 'test_solar_areas',
+            'foreign_alias' => 'area',
+            'foreign_col' => 'id',
+            'foreign_inherit_col' => NULL,
+            'foreign_inherit_val' => NULL,
+            'foreign_primary_col' => 'id',
+            'native_col' => 'area_id',
+            'through' => NULL,
+            'through_table' => NULL,
+            'through_alias' => NULL,
+            'through_native_col' => NULL,
+            'through_foreign_col' => NULL,
+            'distinct' => NULL,
+            'where' => array(),
+            'group' => NULL,
+            'having' => NULL,
+            'order' =>  array(),
+            'paging' => 10,
+            'page' => 1,
+            'cols' =>  array(
+                0 => 'id',
+                1 => 'created',
+                2 => 'updated',
+                3 => 'user_id',
+                4 => 'name',
+            ),
+        );
+        
+        $this->assertSame($nodes->related['area'], $expect);
+    }
+    
+    public function testLazyFetchOne()
+    {
+        $this->_populateAll();
+        
+        // fetch one node, then see how many sql calls so far
+        $nodes = $this->_newModel('nodes');
+        $params = array(
+            'where' => array(
+                'id = ?' => rand(1, 10),
+            ),
+        );
+        $node = $nodes->fetchOne($params);
+        $count_before = count($this->_sql->getProfile());
+        
+        // lazy-fetch the area; make sure it's an area record with the right
+        // ID
+        $area = $node->area;
+        $this->assertInstance($area, 'Solar_Example_Model_Areas_Record');
+        $this->assertEquals($node->area_id, $area->id);
+        
+        // the reference to $area should result in one extra SQL call
+        $count_after = count($this->_sql->getProfile());
+        $this->assertEquals($count_after, $count_before + 1);
+        
+        // a second check should *not* make a new SQL call
+        $area = $node->area;
+        $this->assertInstance($area, 'Solar_Example_Model_Areas_Record');
+        $this->assertEquals($node->area_id, $area->id);
+        $count_final = count($this->_sql->getProfile());
+        $this->assertEquals($count_final, $count_after);
+    }
+    
+    public function testLazyFetchAll()
+    {
+        $this->_populateAll();
+        
+        // fetch all nodes, then see how many sql calls so far
+        $nodes = $this->_newModel('nodes');
+        $collection = $nodes->fetchAll();
+        $count_before = count($this->_sql->getProfile());
+        
+        // lazy-fetch each area
+        foreach ($collection as $node) {
+            $area = $node->area;
+            $this->assertInstance($area, 'Solar_Example_Model_Areas_Record');
+            $this->assertEquals($node->area_id, $area->id);
+        }
+        
+        // each reference to $area should result in one extra SQL call
+        $count_after = count($this->_sql->getProfile());
+        $this->assertEquals($count_after, $count_before + count($collection));
+        
+        // a second check should *not* make new SQL calls
+        foreach ($collection as $node) {
+            $area = $node->area;
+            $this->assertInstance($area, 'Solar_Example_Model_Areas_Record');
+            $this->assertEquals($node->area_id, $area->id);
+        }
+        
+        $count_final = count($this->_sql->getProfile());
+        $this->assertEquals($count_final, $count_after);
+    }
+    
+    public function testEagerFetchOne()
+    {
+        $this->_populateAll();
+        
+        // fetch one node with an eager area
+        // then see how many sql calls so far
+        $nodes = $this->_newModel('nodes');
+        $params = array(
+            'where' => array(
+                'nodes.id = ?' => rand(1, 10),
+            ),
+            'eager' => array('area'),
+        );
+        $node = $nodes->fetchOne($params);
+        $count_before = count($this->_sql->getProfile());
+        
+        // look at the area
+        $area = $node->area;
+        $this->assertInstance($area, 'Solar_Example_Model_Areas_Record');
+        $this->assertEquals($node->area_id, $area->id);
+        
+        // **should not** have been an extra SQL call
+        $count_after = count($this->_sql->getProfile());
+        $this->assertEquals($count_after, $count_before);
+    }
+    
+    public function testEagerFetchAll()
+    {
+        $this->_populateAll();
+        
+        // fetch all nodes with eager area
+        // then see how many sql calls so far
+        $nodes = $this->_newModel('nodes');
+        $params = array('eager' => 'area');
+        $collection = $nodes->fetchAll($params);
+        $count_before = count($this->_sql->getProfile());
+        
+        // look at each area
+        foreach ($collection as $node) {
+            $area = $node->area;
+            $this->assertInstance($area, 'Solar_Example_Model_Areas_Record');
+            $this->assertEquals($node->area_id, $area->id);
+        }
+        
+        // **should not** have been extra SQL calls
+        $count_after = count($this->_sql->getProfile());
+        $this->assertEquals($count_after, $count_before);
+    }
+}

Added: branches/orm/tests/Test/Solar/Sql/ModelRelated/HasOne.php
===================================================================
--- branches/orm/tests/Test/Solar/Sql/ModelRelated/HasOne.php	                        (rev 0)
+++ branches/orm/tests/Test/Solar/Sql/ModelRelated/HasOne.php	2007-08-21 15:18:58 UTC (rev 2728)
@@ -0,0 +1,161 @@
+<?php
+class Test_Solar_Sql_ModelRelated_HasOne extends Test_Solar_Sql_ModelRelated {
+    
+    /**
+     * 
+     * Depends on the Solar_Example_Model_Nodes having added $this->_hasOne().
+     * 
+     */
+    public function testAddRelated()
+    {
+        $nodes = $this->_newModel('nodes');
+        
+        // make sure that nodes has-one meta entry
+        $expect = array(
+            'name' => 'meta',
+            'type' => 'has_one',
+            'foreign_model' => 'Solar_Example_Model_Metas',
+            'foreign_table' => 'test_solar_metas',
+            'foreign_alias' => 'meta',
+            'foreign_col' => 'node_id',
+            'foreign_inherit_col' => NULL,
+            'foreign_inherit_val' => NULL,
+            'foreign_primary_col' => 'id',
+            'native_col' => 'id',
+            'through' => NULL,
+            'through_table' => NULL,
+            'through_alias' => NULL,
+            'through_native_col' => NULL,
+            'through_foreign_col' => NULL,
+            'distinct' => NULL,
+            'where' => array(),
+            'group' => NULL,
+            'having' => NULL,
+            'order' => array(),
+            'paging' => 10,
+            'page' => 1,
+            'cols' => array(
+                0 => 'id',
+                1 => 'node_id',
+                2 => 'last_comment_id',
+                3 => 'last_comment_by',
+                4 => 'last_comment_at',
+                5 => 'comment_count',
+            ),
+        );
+        
+        $this->assertSame($nodes->related['meta'], $expect);
+    }
+    
+    public function testLazyFetchOne()
+    {
+        $this->_populateAll();
+        
+        // fetch one node, then see how many sql calls so far
+        $nodes = $this->_newModel('nodes');
+        $params = array(
+            'where' => array(
+                'id = ?' => rand(1, 10),
+            ),
+        );
+        $node = $nodes->fetchOne($params);
+        $count_before = count($this->_sql->getProfile());
+        
+        // lazy-fetch the meta; make sure it's an meta record with the right
+        // ID
+        $meta = $node->meta;
+        $this->assertInstance($meta, 'Solar_Example_Model_Metas_Record');
+        $this->assertEquals($meta->node_id, $node->id);
+        
+        // the reference to $meta should result in one extra SQL call
+        $count_after = count($this->_sql->getProfile());
+        $this->assertEquals($count_after, $count_before + 1);
+        
+        // a second check should *not* make a new SQL call
+        $meta = $node->meta;
+        $this->assertInstance($meta, 'Solar_Example_Model_Metas_Record');
+        $this->assertEquals($meta->node_id, $node->id);
+        $count_final = count($this->_sql->getProfile());
+        $this->assertEquals($count_final, $count_after);
+    }
+    
+    public function testLazyFetchAll()
+    {
+        $this->_populateAll();
+        
+        // fetch all nodes, then see how many sql calls so far
+        $nodes = $this->_newModel('nodes');
+        $collection = $nodes->fetchAll();
+        $count_before = count($this->_sql->getProfile());
+        
+        // lazy-fetch each meta
+        foreach ($collection as $node) {
+            $meta = $node->meta;
+            $this->assertInstance($meta, 'Solar_Example_Model_Metas_Record');
+            $this->assertEquals($meta->node_id, $node->id);
+        }
+        
+        // each reference to $meta should result in one extra SQL call
+        $count_after = count($this->_sql->getProfile());
+        $this->assertEquals($count_after, $count_before + count($collection));
+        
+        // a second check should *not* make new SQL calls
+        foreach ($collection as $node) {
+            $meta = $node->meta;
+            $this->assertInstance($meta, 'Solar_Example_Model_Metas_Record');
+            $this->assertEquals($meta->node_id, $node->id);
+        }
+        
+        $count_final = count($this->_sql->getProfile());
+        $this->assertEquals($count_final, $count_after);
+    }
+    
+    public function testEagerFetchOne()
+    {
+        $this->_populateAll();
+        
+        // fetch one node with an eager meta
+        // then see how many sql calls so far
+        $nodes = $this->_newModel('nodes');
+        $params = array(
+            'where' => array(
+                'nodes.id = ?' => rand(1, 10),
+            ),
+            'eager' => array('meta'),
+        );
+        $node = $nodes->fetchOne($params);
+        $count_before = count($this->_sql->getProfile());
+        
+        // look at the meta
+        $meta = $node->meta;
+        $this->assertInstance($meta, 'Solar_Example_Model_Metas_Record');
+        $this->assertEquals($meta->node_id, $node->id);
+        
+        // **should not** have been an extra SQL call
+        $count_after = count($this->_sql->getProfile());
+        $this->assertEquals($count_after, $count_before);
+    }
+    
+    public function testEagerFetchAll()
+    {
+        $this->_populateAll();
+        
+        // fetch all nodes with eager meta
+        // then see how many sql calls so far
+        $nodes = $this->_newModel('nodes');
+        $params = array('eager' => 'meta');
+        $collection = $nodes->fetchAll($params);
+        $count_before = count($this->_sql->getProfile());
+        
+        // look at each meta
+        foreach ($collection as $node) {
+            $meta = $node->meta;
+            $this->assertInstance($meta, 'Solar_Example_Model_Metas_Record');
+            $this->assertEquals($meta->node_id, $node->id);
+        }
+        
+        // **should not** have been extra SQL calls
+        $count_after = count($this->_sql->getProfile());
+        $this->assertEquals($count_after, $count_before);
+    }
+}

Added: branches/orm/tests/Test/Solar/Sql/ModelRelated.php
===================================================================
--- branches/orm/tests/Test/Solar/Sql/ModelRelated.php	                        (rev 0)
+++ branches/orm/tests/Test/Solar/Sql/ModelRelated.php	2007-08-21 15:18:58 UTC (rev 2728)
@@ -0,0 +1,183 @@
+<?php
+abstract class Test_Solar_Sql_ModelRelated extends Solar_Test {
+    
+    /**
+     * 
+     * Configuration values.
+     * 
+     * @var array
+     * 
+     */
+    protected $_Test_Solar_Sql_Model = array(
+    );
+    
+    // the SQL connection
+    protected $_sql;
+    
+    // -----------------------------------------------------------------
+    // 
+    // Support methods.
+    // 
+    // -----------------------------------------------------------------
+    
+    /**
+     * 
+     * Constructor.
+     * 
+     * @param array $config User-defined configuration parameters.
+     * 
+     */
+    public function __construct($config)
+    {
+        parent::__construct($config);
+    }
+    
+    /**
+     * 
+     * Destructor; runs after all methods are complete.
+     * 
+     * @param array $config User-defined configuration parameters.
+     * 
+     */
+    public function __destruct()
+    {
+        parent::__destruct();
+    }
+    
+    /**
+     * 
+     * Setup; runs before each test method.
+     * 
+     */
+    public function setup()
+    {
+        parent::setup();
+        
+        $this->_sql = Solar::factory('Solar_Sql');
+        
+        $this->_sql->setProfiling(true);
+        
+        $this->_catalog = Solar::factory('Solar_Sql_Model_Catalog', array(
+            'sql' => $this->_sql
+        ));
+        
+        $this->_dropAll();
+    }
+    
+    /**
+     * 
+     * Setup; runs after each test method.
+     * 
+     */
+    public function teardown()
+    {
+        $this->_dropAll();
+        parent::teardown();
+    }
+    
+    /**
+     * 
+     * Convenience method to get model objects with SQL dependency injection.
+     * 
+     */
+    protected function _newModel($name)
+    {
+        $class = "Solar_Example_Model_" . ucfirst($name);
+        $model = Solar::factory($class, array('sql' => $this->_sql));
+        return $model;
+    }
+    
+    protected function _newModels()
+    {
+        $model = new StdClass();
+        $model->areas = $this->_newModel('areas');
+        $model->nodes = $this->_newModel('nodes');
+        $model->taggings = $this->_newModel('taggings');
+        $model->tags = $this->_newModel('tags');
+        return $model;
+    }
+    
+    protected function _dropAll()
+    {
+        // remove test_solar_* tables
+        $list = $this->_sql->fetchTableList();
+        foreach ($list as $name) {
+            if (substr($name, 0, 11) == 'test_solar_') {
+                $this->_sql->dropTable($name);
+            }
+        }
+        
+        // remove test_solar_* sequences
+        $drop = array('foo', 'bar');
+        foreach ($drop as $name) {
+            $this->_sql->dropSequence("test_solar_$name");
+        }
+        
+        // reset the catalog, so that new model instances re-create
+        // the tables correctly
+        $this->_catalog->reset();
+    }
+    
+    protected function _populateAll()
+    {
+        $this->_populateUsers();
+        $this->_populateAreas();
+        $this->_populateNodes();
+        $this->_populateMetas();
+    }
+    
+    protected function _populateUsers()
+    {
+        $users = $this->_newModel('users');
+        $handles = array('zim', 'dib', 'gir');
+        foreach ($handles as $key => $val) {
+            $user = $users->fetchNew();
+            $user->handle = $val;
+            $result = $user->save();
+            $this->assertTrue($result);
+        }
+    }
+    
+    protected function _populateAreas()
+    {
+        $areas = $this->_newModel('areas');
+        $names = array('Irk', 'Earth');
+        foreach ($names as $key => $val) {
+            $area = $areas->fetchNew();
+            $area->user_id = $key + 1;
+            $area->name = $val;
+            $result = $area->save();
+            $this->assertTrue($result);
+        }   
+    }
+    
+    protected function _populateNodes()
+    {
+        // create some nodes, some for area 1 and some for 2,
+        // and some for user 1 and some for user 2
+        $nodes = $this->_newModel('nodes');
+        for ($i = 1; $i <= 10; $i++) {
+            $node = $nodes->fetchNew();
+            $node->subj = "Subject Line $i: " . substr(md5($i), 0, 5);
+            $node->body = "Body for $i ... " . md5($i);
+            $node->area_id = $i % 2 + 1; // sometimes 1, sometimes 2
+            $node->user_id = ($i + 1) % 2 + 1; // sometimes 2, sometimes 1
+            $result = $node->save();
+            $this->assertTrue($result);
+        }
+    }
+    
+    protected function _populateMetas()
+    {
+        // one meta for each node
+        $nodes = $this->_newModel('nodes');
+        $metas = $this->_newModel('metas');
+        $collection = $nodes->fetchAll();
+        foreach ($collection as $node) {
+            $meta = $metas->fetchNew();
+            $meta->node_id = $node->id;
+            $result = $meta->save();
+            $this->assertTrue($result);
+        }
+    }
+}
\ No newline at end of file

Modified: branches/orm/tests/test.config.php
===================================================================
--- branches/orm/tests/test.config.php	2007-08-21 15:18:03 UTC (rev 2727)
+++ branches/orm/tests/test.config.php	2007-08-21 15:18:58 UTC (rev 2728)
@@ -16,7 +16,7 @@
  */
 
 $config['Solar_Sql'] = array(
-	'adapter' => 'Solar_Sql_Adapter_Sqlite',
+	'adapter' => 'Solar_Sql_Adapter_Mysql',
 );
 
 $config['Solar_Sql_Adapter_Mysql'] = array(




More information about the Solar-svn mailing list