[limb-svn] r5986 - in 3.x/trunk/limb/validation: src/rule tests/cases/rule

svn at limb-project.com svn at limb-project.com
Wed Jun 13 10:25:43 MSD 2007


Author: pachanga
Date: 2007-06-13 10:25:43 +0400 (Wed, 13 Jun 2007)
New Revision: 5986
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5986

Modified:
   3.x/trunk/limb/validation/src/rule/lmbRequiredRule.class.php
   3.x/trunk/limb/validation/tests/cases/rule/lmbRequiredRuleTest.class.php
Log:
-- lmbRequiredRule trims string content for validation

Modified: 3.x/trunk/limb/validation/src/rule/lmbRequiredRule.class.php
===================================================================
--- 3.x/trunk/limb/validation/src/rule/lmbRequiredRule.class.php	2007-06-11 09:39:42 UTC (rev 5985)
+++ 3.x/trunk/limb/validation/src/rule/lmbRequiredRule.class.php	2007-06-13 06:25:43 UTC (rev 5986)
@@ -1,29 +1,29 @@
 <?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com 
- * @copyright  Copyright &copy; 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 &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
 lmb_require('limb/validation/src/rule/lmbValidationRule.interface.php');
 lmb_require('limb/i18n/common.inc.php');
 
-/**
- * Checks that field is present in datasource and has not empty value
- * Example of usage:
- * <code>
- *  lmb_require('limb/validation/src/rule/lmbRequiredRule.class.php');
- *  $validator->addRule(new lmbRequiredRule('title'));
- *  //or
- *  $validator->addRule(new lmbHandle('limb/validation/src/rule/lmbRequiredRule', array('title')));
- *  // or
- *  $validator->addRequiredRule('title');
- * </code>
- * @see lmbValidator :: addRequiredRule()
- * @package validation
- * @version $Id$
- */
+/**
+ * Checks that field is present in datasource and has not empty value
+ * Example of usage:
+ * <code>
+ *  lmb_require('limb/validation/src/rule/lmbRequiredRule.class.php');
+ *  $validator->addRule(new lmbRequiredRule('title'));
+ *  //or
+ *  $validator->addRule(new lmbHandle('limb/validation/src/rule/lmbRequiredRule', array('title')));
+ *  // or
+ *  $validator->addRequiredRule('title');
+ * </code>
+ * @see lmbValidator :: addRequiredRule()
+ * @package validation
+ * @version $Id$
+ */
 class lmbRequiredRule implements lmbValidationRule
 {
   /**
@@ -51,7 +51,7 @@
   function validate($datasource, $error_list)
   {
     $value = $datasource->get($this->field_name);
-    if(is_null($value) || $value === '')
+    if(is_null($value) || (is_string($value) && trim($value) === ''))
     {
       $error = $this->custom_error ? $this->custom_error : lmb_i18n('{Field} is required', 'validation');
       $error_list->addError($error, array('Field' => $this->field_name));

Modified: 3.x/trunk/limb/validation/tests/cases/rule/lmbRequiredRuleTest.class.php
===================================================================
--- 3.x/trunk/limb/validation/tests/cases/rule/lmbRequiredRuleTest.class.php	2007-06-11 09:39:42 UTC (rev 5985)
+++ 3.x/trunk/limb/validation/tests/cases/rule/lmbRequiredRuleTest.class.php	2007-06-13 06:25:43 UTC (rev 5986)
@@ -1,10 +1,10 @@
 <?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com 
- * @copyright  Copyright &copy; 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 &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
 require_once(dirname(__FILE__) . '/lmbValidationRuleTestCase.class.php');
 lmb_require('limb/validation/src/rule/lmbRequiredRule.class.php');
@@ -85,6 +85,19 @@
     $rule->validate($dataspace, $this->error_list);
   }
 
+  function testRequiredRuleWithSpacedString()
+  {
+    $rule = new lmbRequiredRule('testfield');
+
+    $dataspace = new lmbSet();
+    $dataspace->set('testfield', "\n\t   \n\t");
+
+    $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} is required', 'validation'),
+                                                         array('Field'=>'testfield')));
+
+    $rule->validate($dataspace, $this->error_list);
+  }
+
   function testRequiredRuleFailure()
   {
     $rule = new lmbRequiredRule('testfield');



More information about the limb-svn mailing list