[limb-svn] r5866 - in 3.x/trunk/limb/active_record: src tests/cases

svn at limb-project.com svn at limb-project.com
Fri May 11 18:13:24 MSD 2007


Author: pachanga
Date: 2007-05-11 18:13:24 +0400 (Fri, 11 May 2007)
New Revision: 5866
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5866

Modified:
   3.x/trunk/limb/active_record/src/lmbARManyToManyCollection.class.php
   3.x/trunk/limb/active_record/src/lmbAROneToManyCollection.class.php
   3.x/trunk/limb/active_record/src/lmbARRelationCollection.class.php
   3.x/trunk/limb/active_record/tests/cases/lmbARManyToManyCollectionTest.class.php
   3.x/trunk/limb/active_record/tests/cases/lmbAROneToManyCollectionTest.class.php
   3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordDirtyTest.class.php
   3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordManyToManyRelationsTest.class.php
   3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToManyRelationsTest.class.php
Log:
-- $error_list is passed to save method of relation collections

Modified: 3.x/trunk/limb/active_record/src/lmbARManyToManyCollection.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbARManyToManyCollection.class.php	2007-05-11 13:05:33 UTC (rev 5865)
+++ 3.x/trunk/limb/active_record/src/lmbARManyToManyCollection.class.php	2007-05-11 14:13:24 UTC (rev 5866)
@@ -1,13 +1,13 @@
 <?php
-/**
- * Limb Web Application Framework
- *
- * @link http://limb-project.com
- *
- * @copyright  Copyright &copy; 2004-2007 BIT
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- * @version    $Id$
- * @package    active_record
+/**
+ * Limb Web Application Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright  Copyright &copy; 2004-2007 BIT
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version    $Id$
+ * @package    active_record
  */
 lmb_require('limb/active_record/src/lmbARRelationCollection.class.php');
 
@@ -68,10 +68,10 @@
     $table->delete(new lmbSQLFieldCriteria($this->relation_info['field'], $this->owner->getId()));
   }
 
-  protected function _saveObject($object)
+  protected function _saveObject($object, $error_list = null)
   {
     $table = new lmbTableGateway($this->relation_info['table']);
-    $object->save();
+    $object->save($error_list);
     $table->insert(array($this->relation_info['field'] => $this->owner->getId(),
                          $this->relation_info['foreign_field'] => $object->getId()));
   }

Modified: 3.x/trunk/limb/active_record/src/lmbAROneToManyCollection.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbAROneToManyCollection.class.php	2007-05-11 13:05:33 UTC (rev 5865)
+++ 3.x/trunk/limb/active_record/src/lmbAROneToManyCollection.class.php	2007-05-11 14:13:24 UTC (rev 5866)
@@ -1,13 +1,13 @@
 <?php
-/**
- * Limb Web Application Framework
- *
- * @link http://limb-project.com
- *
- * @copyright  Copyright &copy; 2004-2007 BIT
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- * @version    $Id$
- * @package    active_record
+/**
+ * Limb Web Application Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright  Copyright &copy; 2004-2007 BIT
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version    $Id$
+ * @package    active_record
  */
 lmb_require('limb/active_record/src/lmbARRelationCollection.class.php');
 
@@ -52,10 +52,10 @@
                               new lmbSQLFieldCriteria($this->relation_info['field'], $this->owner->getId()));
   }
 
-  protected function _saveObject($object)
+  protected function _saveObject($object, $error_list = null)
   {
     $object->set($this->relation_info['field'], $this->owner->getId());
-    $object->save();
+    $object->save($error_list);
   }
 }
 

Modified: 3.x/trunk/limb/active_record/src/lmbARRelationCollection.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbARRelationCollection.class.php	2007-05-11 13:05:33 UTC (rev 5865)
+++ 3.x/trunk/limb/active_record/src/lmbARRelationCollection.class.php	2007-05-11 14:13:24 UTC (rev 5866)
@@ -174,14 +174,14 @@
     }
   }
 
-  function save()
+  function save($error_list = null)
   {
     $this->_ensureDataset();
 
     if(is_a($this->dataset, 'lmbCollection'))
     {
       foreach($this->dataset as $object)
-        $this->_saveObject($object);
+        $this->_saveObject($object, $error_list);
     }
 
     $this->reset();
@@ -279,7 +279,7 @@
 
   abstract protected function _removeRelatedRecords();
 
-  abstract protected function _saveObject($object);
+  abstract protected function _saveObject($object, $error_list = null);
 
   function addDecorator($decorator, $params = array())
   {

Modified: 3.x/trunk/limb/active_record/tests/cases/lmbARManyToManyCollectionTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbARManyToManyCollectionTest.class.php	2007-05-11 13:05:33 UTC (rev 5865)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbARManyToManyCollectionTest.class.php	2007-05-11 14:13:24 UTC (rev 5866)
@@ -19,9 +19,9 @@
 {
   var $save_calls = 0;
 
-  function save()
+  function save($error_list = null)
   {
-    parent :: save();
+    parent :: save($error_list);
     $this->save_calls++;
   }
 }

Modified: 3.x/trunk/limb/active_record/tests/cases/lmbAROneToManyCollectionTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbAROneToManyCollectionTest.class.php	2007-05-11 13:05:33 UTC (rev 5865)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbAROneToManyCollectionTest.class.php	2007-05-11 14:13:24 UTC (rev 5866)
@@ -49,9 +49,9 @@
 {
   var $save_calls = 0;
 
-  function save()
+  function save($error_list = null)
   {
-    parent :: save();
+    parent :: save($error_list);
     $this->save_calls++;
   }
 }

Modified: 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordDirtyTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordDirtyTest.class.php	2007-05-11 13:05:33 UTC (rev 5865)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordDirtyTest.class.php	2007-05-11 14:13:24 UTC (rev 5866)
@@ -99,7 +99,7 @@
     $object->save();
     $str = ob_get_contents();
     ob_end_clean();
-    $this->assertEqual($str, '|on_before_save||on_before_create||on_save||on_create||on_after_create||on_after_save|');
+    $this->assertEqual($str, '|on_before_save||on_before_create||on_validate||on_save||on_create||on_after_create||on_after_save|');
 
     ob_start();
     $object->save();

Modified: 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordManyToManyRelationsTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordManyToManyRelationsTest.class.php	2007-05-11 13:05:33 UTC (rev 5865)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordManyToManyRelationsTest.class.php	2007-05-11 14:13:24 UTC (rev 5866)
@@ -11,6 +11,7 @@
  */
 lmb_require('limb/active_record/src/lmbActiveRecord.class.php');
 lmb_require('limb/dbal/src/lmbSimpleDb.class.php');
+lmb_require('limb/validation/src/rule/lmbRequiredRule.class.php');
 
 class GroupForTest extends lmbActiveRecord
 {
@@ -20,6 +21,21 @@
                                                         'foreign_field' => 'user_id',
                                                         'table' => 'user2group_for_test',
                                                         'class' => 'UserForTest'));
+
+  protected $_test_validator;
+
+  function setValidator($validator)
+  {
+    $this->_test_validator = $validator;
+  }
+
+  function _createValidator()
+  {
+    if($this->_test_validator)
+      return $this->_test_validator;
+
+    return parent :: _createValidator();
+  }
 }
 
 class UserForTest extends lmbActiveRecord
@@ -243,6 +259,24 @@
     $user = new UserForTestWithCustomCollection();
     $this->assertTrue($user->getGroups() instanceof GroupsForTestCollectionStub);
   }
+
+  function testErrorListIsSharedWithCollection()
+  {
+    $user = new UserForTest();
+    $user->setFirstName('Bob');
+
+    $group = new GroupForTest();
+
+    $validator = new lmbValidator();
+    $validator->addRequiredRule('title');
+    $group->setValidator($validator);
+
+    $user->addToGroups($group);
+    $user->addToGroups($group);
+
+    $error_list = new lmbErrorList();
+    $this->assertFalse($user->trySave($error_list));
+  }
 }
 
 ?>

Modified: 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToManyRelationsTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToManyRelationsTest.class.php	2007-05-11 13:05:33 UTC (rev 5865)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordOneToManyRelationsTest.class.php	2007-05-11 14:13:24 UTC (rev 5866)
@@ -30,6 +30,20 @@
                                       'alt_course' => array('field' => 'alt_course_id',
                                                             'class' => 'CourseForTest',
                                                             'can_be_null' => true));
+  protected $_test_validator;
+
+  function setValidator($validator)
+  {
+    $this->_test_validator = $validator;
+  }
+
+  function _createValidator()
+  {
+    if($this->_test_validator)
+      return $this->_test_validator;
+
+    return parent :: _createValidator();
+  }
 }
 
 class LecturesForTestCollectionStub extends lmbAROneToManyCollection{}
@@ -289,6 +303,21 @@
     $this->assertEqual($lectures->at(0)->getTitle(), $l3->getTitle());
   }
 
+  function testErrorListIsSharedWithCollection()
+  {
+    $course = $this->_initCourse();
+
+    $l = new LectureForTest();
+    $validator = new lmbValidator();
+    $validator->addRequiredRule('title');
+    $l->setValidator($validator);
+
+    $course->addToLectures($l);
+
+    $error_list = new lmbErrorList();
+    $this->assertFalse($course->trySave($error_list));
+  }
+
   function _initCourse()
   {
     $course = new CourseForTest();



More information about the limb-svn mailing list