diff --git a/framework/validators/CExistValidator.php b/framework/validators/CExistValidator.php index c67c326c2..9d8e2e98e 100644 --- a/framework/validators/CExistValidator.php +++ b/framework/validators/CExistValidator.php @@ -76,7 +76,7 @@ class CExistValidator extends CValidator if(is_array($value)) { // https://github.com/yiisoft/yii/issues/1955 - $this->addError($object,$attribute,Yii::t('yii','{attribute} must not have array value.')); + $this->addError($object,$attribute,Yii::t('yii','{attribute} is invalid.')); return; } diff --git a/framework/validators/CNumberValidator.php b/framework/validators/CNumberValidator.php index 98950bea0..5598a9088 100644 --- a/framework/validators/CNumberValidator.php +++ b/framework/validators/CNumberValidator.php @@ -81,7 +81,8 @@ class CNumberValidator extends CValidator if(is_array($value)) { // https://github.com/yiisoft/yii/issues/1955 - $this->addError($object,$attribute,Yii::t('yii','{attribute} must not have array value.')); + $message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must be a number.'); + $this->addError($object,$attribute,$message); return; } if($this->integerOnly) diff --git a/framework/validators/CRegularExpressionValidator.php b/framework/validators/CRegularExpressionValidator.php index 4b21d207d..048254c7b 100644 --- a/framework/validators/CRegularExpressionValidator.php +++ b/framework/validators/CRegularExpressionValidator.php @@ -48,12 +48,10 @@ class CRegularExpressionValidator extends CValidator return; if($this->pattern===null) throw new CException(Yii::t('yii','The "pattern" property must be specified with a valid regular expression.')); - if(is_array($value)) - { - // https://github.com/yiisoft/yii/issues/1955 - $this->addError($object,$attribute,Yii::t('yii','{attribute} must not have array value.')); - } - elseif((!$this->not && !preg_match($this->pattern,$value)) || ($this->not && preg_match($this->pattern,$value))) + // reason of array checking explained here: https://github.com/yiisoft/yii/issues/1955 + if(is_array($value) || + (!$this->not && !preg_match($this->pattern,$value)) || + ($this->not && preg_match($this->pattern,$value))) { $message=$this->message!==null?$this->message:Yii::t('yii','{attribute} is invalid.'); $this->addError($object,$attribute,$message); diff --git a/framework/validators/CStringValidator.php b/framework/validators/CStringValidator.php index fb7f00cbf..181b79542 100644 --- a/framework/validators/CStringValidator.php +++ b/framework/validators/CStringValidator.php @@ -83,7 +83,7 @@ class CStringValidator extends CValidator if(is_array($value)) { // https://github.com/yiisoft/yii/issues/1955 - $this->addError($object,$attribute,Yii::t('yii','{attribute} must not have array value.')); + $this->addError($object,$attribute,Yii::t('yii','{attribute} is invalid.')); return; } diff --git a/framework/validators/CUniqueValidator.php b/framework/validators/CUniqueValidator.php index fa491ee4a..e647f3f53 100644 --- a/framework/validators/CUniqueValidator.php +++ b/framework/validators/CUniqueValidator.php @@ -86,7 +86,7 @@ class CUniqueValidator extends CValidator if(is_array($value)) { // https://github.com/yiisoft/yii/issues/1955 - $this->addError($object,$attribute,Yii::t('yii','{attribute} must not have array value.')); + $this->addError($object,$attribute,Yii::t('yii','{attribute} is invalid.')); return; } diff --git a/tests/framework/validators/CExistValidatorTest.php b/tests/framework/validators/CExistValidatorTest.php index ff6fce09c..a2a814f55 100644 --- a/tests/framework/validators/CExistValidatorTest.php +++ b/tests/framework/validators/CExistValidatorTest.php @@ -138,6 +138,5 @@ EOD; $model->name = array('test_name'); $this->assertFalse($model->validate()); $this->assertTrue($model->hasErrors('name')); - $this->assertSame(array('Name must not have array value.'),$model->getErrors('name')); } } diff --git a/tests/framework/validators/CStringValidatorTest.php b/tests/framework/validators/CStringValidatorTest.php index c1fe58d1d..82122399b 100644 --- a/tests/framework/validators/CStringValidatorTest.php +++ b/tests/framework/validators/CStringValidatorTest.php @@ -29,7 +29,6 @@ class CStringValidatorTest extends CTestCase $model4->string1=array('1234567890'); $model4->validate(array('string1')); $this->assertTrue($model4->hasErrors('string1')); - $this->assertSame(array('String1 must not have array value.'),$model4->getErrors('string1')); } public function testMax() @@ -59,7 +58,6 @@ class CStringValidatorTest extends CTestCase $model4->string2=array('1234567890'); $model4->validate(array('string2')); $this->assertTrue($model4->hasErrors('string2')); - $this->assertSame(array('String2 must not have array value.'),$model4->getErrors('string2')); } public function testIs() @@ -96,6 +94,5 @@ class CStringValidatorTest extends CTestCase $model5->string3=array('1234567890'); $model5->validate(array('string3')); $this->assertTrue($model5->hasErrors('string3')); - $this->assertSame(array('String3 must not have array value.'),$model5->getErrors('string3')); } } diff --git a/tests/framework/validators/CUniqueValidatorTest.php b/tests/framework/validators/CUniqueValidatorTest.php index 955dd866e..ddb1d67a7 100644 --- a/tests/framework/validators/CUniqueValidatorTest.php +++ b/tests/framework/validators/CUniqueValidatorTest.php @@ -138,6 +138,5 @@ EOD; $model->name = array('test_name'); $this->assertFalse($model->validate()); $this->assertTrue($model->hasErrors('name')); - $this->assertSame(array('Name must not have array value.'),$model->getErrors('name')); } }