[Solar-svn] Revision 2706

pmjones at solarphp.com pmjones at solarphp.com
Wed Aug 15 20:28:17 CDT 2007


Branch: continued work on Model test series



Added: branches/orm/Solar/Example/Model/TestSolarDib/Setup/table_cols.php
===================================================================
--- branches/orm/Solar/Example/Model/TestSolarDib/Setup/table_cols.php	                        (rev 0)
+++ branches/orm/Solar/Example/Model/TestSolarDib/Setup/table_cols.php	2007-08-16 01:28:17 UTC (rev 2706)
@@ -0,0 +1,80 @@
+<?php
+return array (
+  'id' => 
+  array (
+    'name' => 'id',
+    'type' => 'int',
+    'size' => NULL,
+    'scope' => NULL,
+    'default' => NULL,
+    'require' => true,
+    'primary' => true,
+    'autoinc' => true,
+  ),
+  'created' => 
+  array (
+    'name' => 'created',
+    'type' => 'timestamp',
+    'size' => NULL,
+    'scope' => NULL,
+    'default' => NULL,
+    'require' => false,
+    'primary' => false,
+    'autoinc' => false,
+  ),
+  'updated' => 
+  array (
+    'name' => 'updated',
+    'type' => 'timestamp',
+    'size' => NULL,
+    'scope' => NULL,
+    'default' => NULL,
+    'require' => false,
+    'primary' => false,
+    'autoinc' => false,
+  ),
+  'inherit' => 
+  array (
+    'name' => 'inherit',
+    'type' => 'varchar',
+    'size' => 30,
+    'scope' => NULL,
+    'default' => NULL,
+    'require' => false,
+    'primary' => false,
+    'autoinc' => false,
+  ),
+  'name' => 
+  array (
+    'name' => 'name',
+    'type' => 'varchar',
+    'size' => 255,
+    'scope' => NULL,
+    'default' => NULL,
+    'require' => false,
+    'primary' => false,
+    'autoinc' => false,
+  ),
+  'email' => 
+  array (
+    'name' => 'email',
+    'type' => 'varchar',
+    'size' => 255,
+    'scope' => NULL,
+    'default' => NULL,
+    'require' => false,
+    'primary' => false,
+    'autoinc' => false,
+  ),
+  'uri' => 
+  array (
+    'name' => 'uri',
+    'type' => 'varchar',
+    'size' => 255,
+    'scope' => NULL,
+    'default' => NULL,
+    'require' => false,
+    'primary' => false,
+    'autoinc' => false,
+  ),
+);
\ No newline at end of file

Added: branches/orm/Solar/Example/Model/TestSolarDib/Setup/table_name.php
===================================================================
--- branches/orm/Solar/Example/Model/TestSolarDib/Setup/table_name.php	                        (rev 0)
+++ branches/orm/Solar/Example/Model/TestSolarDib/Setup/table_name.php	2007-08-16 01:28:17 UTC (rev 2706)
@@ -0,0 +1,2 @@
+<?php
+return 'test_solar_dib';
\ No newline at end of file

Added: branches/orm/Solar/Example/Model/TestSolarDib.php
===================================================================
--- branches/orm/Solar/Example/Model/TestSolarDib.php	                        (rev 0)
+++ branches/orm/Solar/Example/Model/TestSolarDib.php	2007-08-16 01:28:17 UTC (rev 2706)
@@ -0,0 +1,14 @@
+<?php
+class Solar_Example_Model_TestSolarDib extends Solar_Sql_Model {
+    
+    protected function _setup()
+    {
+        $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__)
+             . DIRECTORY_SEPARATOR
+             . 'Setup'
+             . DIRECTORY_SEPARATOR;
+        
+        $this->_table_name = Solar::run($dir . 'table_name.php');
+        $this->_table_cols = Solar::run($dir . 'table_cols.php');
+    }
+}
\ No newline at end of file

Added: branches/orm/Solar/Example/Model/TestSolarFoo/Bar/Record.php
===================================================================
--- branches/orm/Solar/Example/Model/TestSolarFoo/Bar/Record.php	                        (rev 0)
+++ branches/orm/Solar/Example/Model/TestSolarFoo/Bar/Record.php	2007-08-16 01:28:17 UTC (rev 2706)
@@ -0,0 +1,3 @@
+<?php
+class Solar_Example_Model_TestSolarFoo_Bar_Record extends Solar_Example_Model_TestSolarFoo_Record {
+}
\ No newline at end of file

Added: branches/orm/Solar/Example/Model/TestSolarFoo/Bar.php
===================================================================
--- branches/orm/Solar/Example/Model/TestSolarFoo/Bar.php	                        (rev 0)
+++ branches/orm/Solar/Example/Model/TestSolarFoo/Bar.php	2007-08-16 01:28:17 UTC (rev 2706)
@@ -0,0 +1,3 @@
+<?php
+class Solar_Example_Model_TestSolarFoo_Bar extends Solar_Example_Model_TestSolarFoo {
+}
\ No newline at end of file

Added: branches/orm/Solar/Example/Model/TestSolarFoo/Collection.php
===================================================================
--- branches/orm/Solar/Example/Model/TestSolarFoo/Collection.php	                        (rev 0)
+++ branches/orm/Solar/Example/Model/TestSolarFoo/Collection.php	2007-08-16 01:28:17 UTC (rev 2706)
@@ -0,0 +1,3 @@
+<?php
+class Solar_Example_Model_TestSolarFoo_Collection extends Solar_Sql_Model_Collection {
+}
\ No newline at end of file

Added: branches/orm/Solar/Example/Model/TestSolarFoo/Record.php
===================================================================
--- branches/orm/Solar/Example/Model/TestSolarFoo/Record.php	                        (rev 0)
+++ branches/orm/Solar/Example/Model/TestSolarFoo/Record.php	2007-08-16 01:28:17 UTC (rev 2706)
@@ -0,0 +1,3 @@
+<?php
+class Solar_Example_Model_TestSolarFoo_Record extends Solar_Sql_Model_Record {
+}
\ No newline at end of file

Added: branches/orm/Solar/Example/Model/TestSolarFoo/Setup/table_cols.php
===================================================================
--- branches/orm/Solar/Example/Model/TestSolarFoo/Setup/table_cols.php	                        (rev 0)
+++ branches/orm/Solar/Example/Model/TestSolarFoo/Setup/table_cols.php	2007-08-16 01:28:17 UTC (rev 2706)
@@ -0,0 +1,80 @@
+<?php
+return array (
+  'id' => 
+  array (
+    'name' => 'id',
+    'type' => 'int',
+    'size' => NULL,
+    'scope' => NULL,
+    'default' => NULL,
+    'require' => true,
+    'primary' => true,
+    'autoinc' => true,
+  ),
+  'created' => 
+  array (
+    'name' => 'created',
+    'type' => 'timestamp',
+    'size' => NULL,
+    'scope' => NULL,
+    'default' => NULL,
+    'require' => false,
+    'primary' => false,
+    'autoinc' => false,
+  ),
+  'updated' => 
+  array (
+    'name' => 'updated',
+    'type' => 'timestamp',
+    'size' => NULL,
+    'scope' => NULL,
+    'default' => NULL,
+    'require' => false,
+    'primary' => false,
+    'autoinc' => false,
+  ),
+  'inherit' => 
+  array (
+    'name' => 'inherit',
+    'type' => 'varchar',
+    'size' => 30,
+    'scope' => NULL,
+    'default' => NULL,
+    'require' => false,
+    'primary' => false,
+    'autoinc' => false,
+  ),
+  'name' => 
+  array (
+    'name' => 'name',
+    'type' => 'varchar',
+    'size' => 255,
+    'scope' => NULL,
+    'default' => NULL,
+    'require' => false,
+    'primary' => false,
+    'autoinc' => false,
+  ),
+  'email' => 
+  array (
+    'name' => 'email',
+    'type' => 'varchar',
+    'size' => 255,
+    'scope' => NULL,
+    'default' => NULL,
+    'require' => false,
+    'primary' => false,
+    'autoinc' => false,
+  ),
+  'uri' => 
+  array (
+    'name' => 'uri',
+    'type' => 'varchar',
+    'size' => 255,
+    'scope' => NULL,
+    'default' => NULL,
+    'require' => false,
+    'primary' => false,
+    'autoinc' => false,
+  ),
+);
\ No newline at end of file

Added: branches/orm/Solar/Example/Model/TestSolarFoo/Setup/table_name.php
===================================================================
--- branches/orm/Solar/Example/Model/TestSolarFoo/Setup/table_name.php	                        (rev 0)
+++ branches/orm/Solar/Example/Model/TestSolarFoo/Setup/table_name.php	2007-08-16 01:28:17 UTC (rev 2706)
@@ -0,0 +1,2 @@
+<?php
+return 'test_solar_foo';
\ No newline at end of file

Added: branches/orm/Solar/Example/Model/TestSolarFoo.php
===================================================================
--- branches/orm/Solar/Example/Model/TestSolarFoo.php	                        (rev 0)
+++ branches/orm/Solar/Example/Model/TestSolarFoo.php	2007-08-16 01:28:17 UTC (rev 2706)
@@ -0,0 +1,14 @@
+<?php
+class Solar_Example_Model_TestSolarFoo extends Solar_Sql_Model {
+    
+    protected function _setup()
+    {
+        $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__)
+             . DIRECTORY_SEPARATOR
+             . 'Setup'
+             . DIRECTORY_SEPARATOR;
+        
+        $this->_table_name = Solar::run($dir . 'table_name.php');
+        $this->_table_cols = Solar::run($dir . 'table_cols.php');
+    }
+}
\ No newline at end of file

Modified: branches/orm/Solar/Example/Model/TestSolarSpecialCols.php
===================================================================
--- branches/orm/Solar/Example/Model/TestSolarSpecialCols.php	2007-08-16 01:24:14 UTC (rev 2705)
+++ branches/orm/Solar/Example/Model/TestSolarSpecialCols.php	2007-08-16 01:28:17 UTC (rev 2706)
@@ -3,7 +3,7 @@
     
     protected function _setup()
     {
-        $dir = str_replace('_', DIRECTORY_SEPARATOR, $this->_class)
+        $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__)
              . DIRECTORY_SEPARATOR
              . 'Setup'
              . DIRECTORY_SEPARATOR;
@@ -11,16 +11,13 @@
         $this->_table_name = Solar::run($dir . 'table_name.php');
         $this->_table_cols = Solar::run($dir . 'table_cols.php');
         
-        $this->_primary_col = 'id';
-        $this->_created_col = 'created';
-        $this->_updated_col = 'updated';
-        $this->_inherit_col = 'inherit';
-        
+        // recognize sequence columns
         $this->_sequence_cols = array(
             'seq_foo' => 'test_solar_foo',
             'seq_bar' => 'test_solar_bar',
         );
         
+        // recognize serialize columns
         $this->_serialize_cols = 'serialize';
     }
 }
\ No newline at end of file

Modified: branches/orm/Solar/Example/Model/TestSolarSqlDescribe.php
===================================================================
--- branches/orm/Solar/Example/Model/TestSolarSqlDescribe.php	2007-08-16 01:24:14 UTC (rev 2705)
+++ branches/orm/Solar/Example/Model/TestSolarSqlDescribe.php	2007-08-16 01:28:17 UTC (rev 2706)
@@ -3,7 +3,7 @@
     
     protected function _setup()
     {
-        $dir = str_replace('_', DIRECTORY_SEPARATOR, $this->_class)
+        $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__)
              . DIRECTORY_SEPARATOR
              . 'Setup'
              . DIRECTORY_SEPARATOR;

Modified: branches/orm/tests/Test/Solar/Sql/Model.php
===================================================================
--- branches/orm/tests/Test/Solar/Sql/Model.php	2007-08-16 01:24:14 UTC (rev 2705)
+++ branches/orm/tests/Test/Solar/Sql/Model.php	2007-08-16 01:28:17 UTC (rev 2706)
@@ -34,12 +34,8 @@
  *     - save
  *     - pass validation
  * 
- * - delete a record
- * 
  * - fetching
  * 
- *     - magic fetchAllBy, fetchOneBy
- * 
  *     - lazy-fetch a has_one related
  * 
  *     - lazy-fetch a belongs_to related
@@ -67,11 +63,7 @@
  *     - delete from a collection
  * 
  *     - do unit-of-work on a collection
- * 
- * - single table inheritance
- * 
- * - record and collection class hierarchy traversal
- * 
+ *     
  */
 class Test_Solar_Sql_Model extends Solar_Test {
     
@@ -358,15 +350,32 @@
         $this->assertEquals($actual, $expect);
     }
     
-    // /**
-    //  * 
-    //  * Test -- Deletes a record from the database.
-    //  * 
-    //  */
-    // public function testDeleteRecord()
-    // {
-    //     $this->todo('stub');
-    // }
+    /**
+     * 
+     * Test -- Deletes a record from the database.
+     * 
+     */
+    public function testDeleteRecord()
+    {
+        $this->_populateSpecialColsTable();
+        $model = $this->_getModel('TestSolarSpecialCols');
+        
+        $record = $model->fetch(7);
+        $this->assertEquals($record->id, 7);
+        $model->deleteRecord($record);
+        
+        // the record should not allow modification now
+        try {
+            $record->name = 'foo';
+            $this->fail('should not have been able to modify deleted record');
+        } catch (Solar_Exception $e) {
+            // this is the expected case
+        }
+        
+        // should not be able to retrieve the record
+        $record = $model->fetch(7);
+        $this->assertNull($record);
+    }
     
     /**
      * 
@@ -572,19 +581,35 @@
     // {
     //     $this->todo('stub');
     // }
-    // 
+    
+    /**
+     * 
+     * Test -- Returns the appropriate collection object for this model.
+     * 
+     * Takes single-table inheritance into account.
+     * 
+     */
+    public function testNewCollection()
+    {
+        $data = array();
+        
+        $model = $this->_getModel('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');
+        $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');
+        $collection = $model->newCollection($data);
+        $this->assertInstance($collection, 'Solar_Sql_Model_Collection');
+    }
+    
     // /**
     //  * 
-    //  * Test -- Returns the appropriate collection object for this model.
-    //  * 
-    //  */
-    // public function testNewCollection()
-    // {
-    //     $this->todo('stub');
-    // }
-    // 
-    // /**
-    //  * 
     //  * Test -- Returns a new filter object with the chain already prepared.
     //  * 
     //  */
@@ -592,19 +617,50 @@
     // {
     //     $this->todo('stub');
     // }
-    // 
-    // /**
-    //  * 
-    //  * Test -- Returns the appropriate record object for an inheritance model.
-    //  * 
-    //  */
-    // public function testNewRecord()
-    // {
-    //     $this->todo('stub');
-    // }
     
     /**
      * 
+     * Test -- Returns the appropriate record object for an inheritance model.
+     * 
+     * Takes single-table inheritance into account.
+     * 
+     */
+    public function testNewRecord()
+    {
+        $data = array(
+          'id'      => '88',
+          'created' => date('Y-m-d H:i:s'),
+          'updated' => date('Y-m-d H:i:s'),
+          'inherit' => null,
+          'name'    => null,
+          'email'   => null,
+          'uri'     => null,
+        );
+        
+        
+        // non-inherited
+        $model = $this->_getModel('TestSolarFoo');
+        $record = $model->newRecord($data);
+        $this->assertInstance($record, 'Solar_Example_Model_TestSolarFoo_Record');
+        
+        // single-table inherited when available
+        $data['inherit'] = 'Bar';
+        $record = $model->newRecord($data);
+        $this->assertInstance($record, 'Solar_Example_Model_TestSolarFoo_Bar_Record');
+        
+        // parent when inherited not available
+        $data['inherit'] = 'No_Such_Class';
+        $record = $model->newRecord($data);
+        $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');
+        $record = $model->newRecord($data);
+        $this->assertInstance($record, 'Solar_Sql_Model_Record');
+    }
+    
+    /**
+     * 
      * Test -- Sets the number of records per page.
      * 
      */
@@ -621,7 +677,10 @@
         $actual = $model->getPaging();
         $this->assertEquals($actual, $expect);
         
-        // make sure it's honored
+        /**
+         * make sure the setting is honored
+         */
+         
         // get the first page of 3 records
         $collection = $model->fetchAll(array('order' => 'id', 'page' => 1));
         $this->assertEquals(count($collection), 3);




More information about the Solar-svn mailing list