[Solar-svn] Revision 2764

pmjones at solarphp.com pmjones at solarphp.com
Thu Sep 20 13:24:16 CDT 2007


updated tests to match new code



Modified: branches/orm/tests/Test/Solar/Sql/Model.php
===================================================================
--- branches/orm/tests/Test/Solar/Sql/Model.php	2007-09-20 18:23:45 UTC (rev 2763)
+++ branches/orm/tests/Test/Solar/Sql/Model.php	2007-09-20 18:24:15 UTC (rev 2764)
@@ -197,8 +197,7 @@
             $record = $model->fetchNew();
             $record->name = 'z'; 
             $record->seq_foo = 88;
-            $valid = $model->insertRecord($record);
-            $this->assertTrue($valid);
+            $model->insert($record);
         }
         
         // add some extras so we can see if fetchAll() grabs more than it should
@@ -207,8 +206,7 @@
             $record = $model->fetchNew();
             $record->name = 'z'; 
             $record->seq_foo = 99;
-            $valid = $model->insertRecord($record);
-            $this->assertTrue($valid);
+            $model->insert($record);
         }
         
         /**
@@ -331,14 +329,14 @@
      * Test -- Deletes a record from the database.
      * 
      */
-    public function testDeleteRecord()
+    public function testDelete()
     {
         $this->_populateSpecialColsTable();
         $model = $this->_newModel('TestSolarSpecialCols');
         
         $record = $model->fetch(7);
         $this->assertEquals($record->id, 7);
-        $model->deleteRecord($record);
+        $model->delete($record);
         
         // the record should not allow modification now
         try {
@@ -553,7 +551,7 @@
      * Test -- Filters and inserts a Record into the table.
      * 
      */
-    public function testInsertRecord()
+    public function testInsert()
     {
         $model = $this->_newModel('TestSolarFoo');
         $record = $model->fetchNew();
@@ -567,7 +565,7 @@
         $record->name  = $name;
         
         // insert and make sure we got the ID back
-        $model->insertRecord($record);
+        $model->insert($record);
         $this->assertEquals($record->id, 1);
         
         // now fetch and make sure the insert "took"
@@ -583,15 +581,19 @@
      * for invalidation at the record level.
      * 
      */
-    public function testInsertRecord_invalid()
+    public function testInsert_invalid()
     {
         $model = $this->_newModel('TestSolarFoo');
         
         // insert should fail
         $record = $model->fetchNew();
         $record->email = 'not-an-email';
-        $valid = $model->insertRecord($record);
-        $this->assertFalse($valid);
+        try {
+            $model->insert($record);
+            $this->fail('should have thrown ERR_INVALID');
+        } catch (Exception $e) {
+            $this->assertInstance($e, 'Solar_Sql_Model_Record_Exception_Invalid');
+        }
         
         // should have failed on email
         $invalid = $record->getInvalid();
@@ -601,8 +603,7 @@
         
         // insert should pass
         $record->email = 'nobody at example.com';
-        $valid = $model->insertRecord($record);
-        $this->assertTrue($valid);
+        $model->insert($record);
     }
     
     /**
@@ -611,29 +612,25 @@
      * from the database.
      * 
      */
-    public function testInsertRecord_invalidAtDatabase()
+    public function testInsert_invalidAtDatabase()
     {
         $model = $this->_newModel('TestSolarFoo');
         
         // insert should succeed
         $record = $model->fetchNew();
         $record->email = 'nobody at example.com';
-        $valid = $model->insertRecord($record);
-        $this->assertTrue($valid);
+        $model->insert($record);
         
         // insert should fail **at database** because of unique index on the
         // email column.
         $record = $model->fetchNew();
         $record->email = 'nobody at example.com';
-        $valid = $model->insertRecord($record);
-        $this->assertFalse($valid);
-        
-        // database failures are considered invalidations of
-        // the record as a whole, thus the '*' key.
-        $invalid = $record->getInvalid();
-        $actual = array_keys($invalid);
-        $expect = array('*');
-        $this->assertSame($actual, $expect);
+        try {
+            $model->insert($record);
+            $this->fail('should have thrown ERR_QUERY_FAILED');
+        } catch (Exception $e) {
+            $this->assertInstance($e, 'Solar_Sql_Adapter_Exception_QueryFailed');
+        }
     }
     
     /**
@@ -642,7 +639,7 @@
      * for single-table inheritance value.
      * 
      */
-    public function testInsertRecord_inherit()
+    public function testInsert_inherit()
     {
         $model = $this->_newModel('TestSolarFoo_Bar');
         
@@ -652,8 +649,7 @@
         
         // if we clear the inheritance value, it should self-set again
         $record->inherit = null;
-        $valid = $model->insertRecord($record);
-        $this->assertTrue($valid);
+        $model->insert($record);
         $this->assertEquals($record->inherit, 'Bar');
     }
     
@@ -685,16 +681,6 @@
     
     /**
      * 
-     * Test -- Returns a new filter object with the chain already prepared.
-     * 
-     */
-    public function testNewFilterObject()
-    {
-        $this->todo('stub');
-    }
-    
-    /**
-     * 
      * Test -- Returns the appropriate record object for an inheritance model.
      * 
      * Takes single-table inheritance into account.
@@ -785,7 +771,7 @@
      * Test -- Filters and updates a Record in the table.
      * 
      */
-    public function testUpdateRecord()
+    public function testUpdate()
     {
         $model = $this->_newModel('TestSolarFoo');
         
@@ -803,7 +789,7 @@
         $record->name  = $name;
         
         // insert and make sure we got the ID back
-        $model->insertRecord($record);
+        $model->insert($record);
         $this->assertEquals($record->id, 1);
         
         /**
@@ -819,7 +805,7 @@
         // change something and update
         $name = 'Another Example';
         $record->name = $name;
-        $model->updateRecord($record);
+        $model->update($record, null);
         
         // did it change in the record?
         $this->assertEquals($record->email, $email);
@@ -839,20 +825,23 @@
      * for invalidation at the record level.
      * 
      */
-    public function testUpdateRecord_invalid()
+    public function testUpdate_invalid()
     {
         $model = $this->_newModel('TestSolarFoo');
         
         // insert should pass
         $record = $model->fetchNew();
         $record->email = 'nobody at example.com';
-        $valid = $model->insertRecord($record);
-        $this->assertTrue($valid);
+        $model->insert($record);
         
         // update should fail
         $record->email = 'not-an-email';
-        $valid = $model->updateRecord($record);
-        $this->assertFalse($valid);
+        try {
+            $model->update($record, null);
+            $this->fail('should have thrown ERR_INVALID');
+        } catch (Exception $e) {
+            $this->assertInstance($e, 'Solar_Sql_Model_Record_Exception_Invalid');
+        }
         
         // should have failed on email
         $invalid = $record->getInvalid();
@@ -862,8 +851,7 @@
         
         // update should pass
         $record->email = 'another at example.com';
-        $valid = $model->updateRecord($record);
-        $this->assertTrue($valid);
+        $model->update($record, null);
     }
     
     /**
@@ -872,34 +860,29 @@
      * from the database.
      * 
      */
-    public function testUpdateRecord_invalidAtDatabase()
+    public function testUpdate_invalidAtDatabase()
     {
         $model = $this->_newModel('TestSolarFoo');
         
         // insert should succeed
         $record = $model->fetchNew();
         $record->email = 'nobody at example.com';
-        $valid = $model->insertRecord($record);
-        $this->assertTrue($valid);
+        $model->insert($record);
         
         // insert another record to work with
         $record = $model->fetchNew();
         $record->email = 'another at example.com';
-        $valid = $model->insertRecord($record);
-        $this->assertTrue($valid);
+        $model->insert($record);
         
         // now modify the more-recent record, and fail the uniqueness index
         // at the database.
         $record->email = 'nobody at example.com';
-        $valid = $model->updateRecord($record);
-        $this->assertFalse($valid);
-        
-        // database failures are considered invalidations of
-        // the record as a whole, thus the '*' key.
-        $invalid = $record->getInvalid();
-        $actual = array_keys($invalid);
-        $expect = array('*');
-        $this->assertSame($actual, $expect);
+        try {
+            $model->update($record, null);
+            $this->fail('should have thrown ERR_QUERY_FAILED');
+        } catch (Exception $e) {
+            $this->assertInstance($e, 'Solar_Sql_Adapter_Exception_QueryFailed');
+        }
     }
     
     /**
@@ -908,7 +891,7 @@
      * for single-table inheritance value.
      * 
      */
-    public function testUpdateRecord_inherit()
+    public function testUpdate_inherit()
     {
         $model = $this->_newModel('TestSolarFoo_Bar');
         
@@ -918,15 +901,14 @@
         
         // if we clear the inheritance value, it should self-set again
         $record->inherit = null;
-        $valid = $model->insertRecord($record);
-        $this->assertTrue($valid);
+        $model->insert($record);
         $this->assertEquals($record->inherit, 'Bar');
         
         // if we fetch, clear, and update, it should self-set *again*
         $record = $model->fetch(1);
         $this->assertEquals($record->inherit, 'Bar');
         $record->inherit = null;
-        $model->updateRecord($record);
+        $model->update($record, null);
         $this->assertEquals($record->inherit, 'Bar');
         $record = $model->fetch(1);
         $this->assertEquals($record->inherit, 'Bar');
@@ -946,7 +928,7 @@
          */
         
         $record = $model->fetchNew();
-        $model->insertRecord($record);
+        $model->insert($record);
         $now = date('Y-m-d H:i:s');
         
         // autoincremented id
@@ -966,7 +948,7 @@
          */
         $record = $model->fetch(1);
         $record->seq_bar = null;
-        $model->updateRecord($record);
+        $model->update($record, null);
         $now = date('Y-m-d H:i:s');
         
         // created should be as original

Modified: branches/orm/tests/Test/Solar/Sql/ModelRelated.php
===================================================================
--- branches/orm/tests/Test/Solar/Sql/ModelRelated.php	2007-09-20 18:23:45 UTC (rev 2763)
+++ branches/orm/tests/Test/Solar/Sql/ModelRelated.php	2007-09-20 18:24:15 UTC (rev 2764)
@@ -135,8 +135,7 @@
         foreach ($handles as $key => $val) {
             $user = $users->fetchNew();
             $user->handle = $val;
-            $result = $user->save();
-            $this->assertTrue($result);
+            $user->save();
         }
     }
     
@@ -148,8 +147,7 @@
             $area = $areas->fetchNew();
             $area->user_id = $key + 1;
             $area->name = $val;
-            $result = $area->save();
-            $this->assertTrue($result);
+            $area->save();
         }   
     }
     
@@ -165,8 +163,7 @@
             $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);
+            $node->save();
         }
     }
     
@@ -179,8 +176,7 @@
         foreach ($collection as $node) {
             $meta = $metas->fetchNew();
             $meta->node_id = $node->id;
-            $result = $meta->save();
-            $this->assertTrue($result);
+            $meta->save();
         }
     }
     
@@ -194,8 +190,7 @@
         foreach ($list as $name) {
             $tag = $tags->fetchNew();
             $tag->name = $name;
-            $result = $tag->save();
-            $this->assertTrue($result);
+            $tag->save();
         }
     }
     
@@ -237,8 +232,7 @@
                 $tagging = $taggings->fetchNew();
                 $tagging->node_id = $node->id;
                 $tagging->tag_id = $tag->id;
-                $result = $tagging->save();
-                $this->assertTrue($result);
+                $tagging->save();
             }
         }
     }




More information about the Solar-svn mailing list