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

svn at limb-project.com svn at limb-project.com
Thu Apr 5 16:48:29 MSD 2007


Author: pachanga
Date: 2007-04-05 16:48:29 +0400 (Thu, 05 Apr 2007)
New Revision: 5538
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5538

Modified:
   3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php
   3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordDirtyTest.class.php
   3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php
Log:
-- new event added - lmbActiveRecord :: _onSave(), it's called both in case of creating and updating

Modified: 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php	2007-04-05 12:43:56 UTC (rev 5537)
+++ 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php	2007-04-05 12:48:29 UTC (rev 5538)
@@ -736,6 +736,8 @@
         throw new lmbValidationException('ActiveRecord "' . get_class($this) . '" validation failed',
                                          $this->getErrorList());
 
+      $this->_onSave();
+
       $this->_onUpdate();
 
       $this->_invokeListeners(self :: ON_UPDATE);
@@ -756,6 +758,8 @@
         throw new lmbValidationException('ActiveRecord "' . get_class($this) . '" validation failed',
                                          $this->getErrorList());
 
+      $this->_onSave();
+
       $this->_onCreate();
 
       $this->_invokeListeners(self :: ON_CREATE);
@@ -910,6 +914,8 @@
 
   protected function _onCreate(){}
 
+  protected function _onSave(){}
+
   protected function _onAfterUpdate(){}
 
   protected function _onAfterCreate(){}

Modified: 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordDirtyTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordDirtyTest.class.php	2007-04-05 12:43:56 UTC (rev 5537)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordDirtyTest.class.php	2007-04-05 12:48:29 UTC (rev 5538)
@@ -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/lmbActiveRecord.class.php');
 lmb_require('limb/dbal/src/lmbSimpleDb.class.php');
@@ -99,7 +99,7 @@
     $object->save();
     $str = ob_get_contents();
     ob_end_clean();
-    $this->assertEqual($str, '|on_before_save||on_before_create||on_create||on_after_create||on_after_save|');
+    $this->assertEqual($str, '|on_before_save||on_before_create||on_save||on_create||on_after_create||on_after_save|');
 
     ob_start();
     $object->save();

Modified: 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php	2007-04-05 12:43:56 UTC (rev 5537)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php	2007-04-05 12:48:29 UTC (rev 5538)
@@ -41,6 +41,11 @@
     echo '|on_after_save|';
   }
 
+  protected function _onSave()
+  {
+    echo '|on_save|';
+  }
+
   protected function _onUpdate()
   {
     echo '|on_update|';
@@ -192,7 +197,7 @@
     $this->assertEqual($record->get('id'), $object->getId());
   }
 
-  function testProperOrderOfCreateUpdateHooksCalls()
+  function testProperOrderOfCreateHooksCalls()
   {
     $object = new TestOneTableObjectWithHooks();
     $object->setContent('whatever');
@@ -201,9 +206,26 @@
     $object->save();
     $str = ob_get_contents();
     ob_end_clean();
-    $this->assertEqual($str, '|on_before_save||on_before_create||on_create||on_after_create||on_after_save|');
+    $this->assertEqual($str, '|on_before_save||on_before_create||on_save||on_create||on_after_create||on_after_save|');
   }
 
+  function testProperOrderOfUpdateHooksCalls()
+  {
+    $object = new TestOneTableObjectWithHooks();
+    $object->setContent('whatever');
+    ob_start();
+    $object->save();
+    ob_end_clean();
+
+    $object->setContent('other content');
+
+    ob_start();
+    $object->save();
+    $str = ob_get_contents();
+    ob_end_clean();
+    $this->assertEqual($str, '|on_before_save||on_before_update||on_save||on_update||on_after_update||on_after_save|');
+  }
+
   function testProperOrderOfDestroyHooksCalls()
   {
     $object = new TestOneTableObjectWithHooks();



More information about the limb-svn mailing list