[limb-svn] r5950 - in 3.x/trunk/limb/active_record: src tests/cases
svn at limb-project.com
svn at limb-project.com
Wed Jun 6 17:54:07 MSD 2007
Author: pachanga
Date: 2007-06-06 17:54:07 +0400 (Wed, 06 Jun 2007)
New Revision: 5950
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5950
Modified:
3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php
3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php
3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTransactionTest.class.php
3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordValidationTest.class.php
Log:
-- lmbActiveRecord :: isValid() added
-- lmbActiveRecord :: _onValidate() is called after validator rules were processed
-- lmbActiveRecord :: trySave($error_list) puts non lmbValidationExceptions into $error_list
Modified: 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php 2007-06-06 13:19:57 UTC (rev 5949)
+++ 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php 2007-06-06 13:54:07 UTC (rev 5950)
@@ -25,8 +25,8 @@
* Base class responsible for ActiveRecord design pattern implementation. Inspired by Rails ActiveRecord class.
*
* @version $Id$
- * @package active_record
- */
+ * @package active_record
+ */
class lmbActiveRecord extends lmbObject
{
/**
@@ -947,8 +947,14 @@
{
$this->save($error_list);
}
+ catch(lmbValidationException $e)
+ {
+ return false;
+ }
catch(Exception $e)
{
+ if($error_list)
+ $error_list->addError('ActiveRecord :: save() exception: ' . $e->getMessage());
return false;
}
return true;
@@ -1029,13 +1035,19 @@
protected function _validate($validator)
{
+ $validator->setErrorList($this->_error_list);
+ $validator->validate($this);
+
$this->_onValidate();
- $validator->setErrorList($this->_error_list);
- $validator->validate($this);
return $this->_error_list->isValid();
}
+ function isValid()
+ {
+ return $this->_error_list->isValid();
+ }
+
protected static function _isCriteria($params)
{
if(is_object($params) || is_string($params))
Modified: 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php 2007-06-06 13:19:57 UTC (rev 5949)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php 2007-06-06 13:54:07 UTC (rev 5950)
@@ -1,10 +1,10 @@
<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/active_record/src/lmbActiveRecord.class.php');
lmb_require('limb/dbal/src/lmbSimpleDb.class.php');
@@ -16,6 +16,18 @@
protected $dummy;
}
+class TestOneTableObjectFailing extends lmbActiveRecord
+{
+ var $fail;
+ protected $_db_table_name = 'test_one_table_object';
+
+ protected function _onAfterSave()
+ {
+ if(is_object($this->fail))
+ throw $this->fail;
+ }
+}
+
class TestOneTableObjectWithCustomDestroy extends lmbActiveRecord
{
protected $_db_table_name = 'test_one_table_object';
Modified: 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTransactionTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTransactionTest.class.php 2007-06-06 13:19:57 UTC (rev 5949)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTransactionTest.class.php 2007-06-06 13:54:07 UTC (rev 5950)
@@ -1,26 +1,15 @@
<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/active_record/src/lmbActiveRecord.class.php');
lmb_require('limb/dbal/src/lmbSimpleDb.class.php');
+require_once(dirname(__FILE__) . '/lmbActiveRecordTest.class.php');//need TestOneTableObjectFailing
-class TestOneTableObjectFailing extends lmbActiveRecord
-{
- var $fail = false;
- protected $_db_table_name = 'test_one_table_object';
-
- protected function _onAfterSave()
- {
- if($this->fail)
- throw new Exception('catch me');
- }
-}
-
class lmbActiveRecordTransactionTest extends UnitTestCase
{
function setUp()
@@ -61,7 +50,7 @@
$obj = new TestOneTableObjectFailing();
$obj->setContent('hey');
- $obj->fail = true;
+ $obj->fail = new Exception('whatever');
$this->assertFalse($obj->trySave());
Modified: 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordValidationTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordValidationTest.class.php 2007-06-06 13:19:57 UTC (rev 5949)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordValidationTest.class.php 2007-06-06 13:54:07 UTC (rev 5950)
@@ -1,14 +1,15 @@
<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/active_record/src/lmbActiveRecord.class.php');
lmb_require('limb/validation/src/lmbValidator.class.php');
lmb_require('limb/validation/src/lmbErrorList.class.php');
+require_once(dirname(__FILE__) . '/lmbActiveRecordTest.class.php');//need TestOneTableObjectFailing
Mock :: generate('lmbValidator', 'MockValidator');
Mock :: generate('lmbErrorList', 'MockErrorList');
@@ -275,6 +276,51 @@
$this->assertEqual($record->get('annotation'), $annotation);
}
+ function testIsValid()
+ {
+ $object = $this->_createActiveRecordWithDataAndSave();
+ $this->assertTrue($object->isValid());
+ }
+
+ function testIsNotValid()
+ {
+ $error_list = new lmbErrorList();
+
+ $object = $this->_createActiveRecordWithDataAndSave();
+ $this->assertTrue($object->isValid());
+
+ $error_list->addError('whatever');//actually it's a dirty simulation but that's how it works really
+
+ $object->save($error_list);
+ $this->assertFalse($object->isValid());
+ }
+
+ function testValidationExceptionIsNotAddedToErrorList()
+ {
+ $error_list = new lmbErrorList();
+
+ $object = new TestOneTableObjectFailing();
+ $object->setContent('A-a-a-a');
+ $object->fail = new lmbValidationException('foo', $error_list);
+
+ $this->assertFalse($object->trySave($error_list));
+ $this->assertTrue($error_list->isEmpty());
+ }
+
+ function testNonValidationExceptionIsAddedToErrorList()
+ {
+ $error_list = new lmbErrorList();
+
+ $object = new TestOneTableObjectFailing();
+ $object->setContent('A-a-a-a');
+ $object->fail = new Exception('yo-yo');
+
+ $this->assertFalse($object->trySave($error_list));
+ $this->assertFalse($error_list->isEmpty());
+ $this->assertEqual(sizeof($error_list), 1);
+ $this->assertPattern('~yo-yo~', $error_list[0]->getMessage());
+ }
+
function _createActiveRecord()
{
$object = new lmbActiveRecordValidationStub();
More information about the limb-svn
mailing list