|
|
@ -3,6 +3,7 @@ namespace yiiunit\framework\validators; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use yii\validators\RequiredValidator; |
|
|
|
use yii\validators\RequiredValidator; |
|
|
|
|
|
|
|
use yiiunit\data\validators\models\FakedValidationModel; |
|
|
|
use yiiunit\TestCase; |
|
|
|
use yiiunit\TestCase; |
|
|
|
|
|
|
|
|
|
|
|
class RequiredValidatorTest extends TestCase |
|
|
|
class RequiredValidatorTest extends TestCase |
|
|
@ -31,4 +32,23 @@ class RequiredValidatorTest extends TestCase |
|
|
|
$this->assertFalse($val->validateValue("should fail")); |
|
|
|
$this->assertFalse($val->validateValue("should fail")); |
|
|
|
$this->assertFalse($val->validateValue(true)); |
|
|
|
$this->assertFalse($val->validateValue(true)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testValidateAttribute() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// empty req-value |
|
|
|
|
|
|
|
$val = new RequiredValidator(); |
|
|
|
|
|
|
|
$m = FakedValidationModel::createWithAttributes(array('attr_val' => null)); |
|
|
|
|
|
|
|
$val->validateAttribute($m, 'attr_val'); |
|
|
|
|
|
|
|
$this->assertTrue($m->hasErrors('attr_val')); |
|
|
|
|
|
|
|
$this->assertTrue(stripos(current($m->getErrors('attr_val')), 'blank') !== false); |
|
|
|
|
|
|
|
$val = new RequiredValidator(array('requiredValue' => 55)); |
|
|
|
|
|
|
|
$m = FakedValidationModel::createWithAttributes(array('attr_val' => 56)); |
|
|
|
|
|
|
|
$val->validateAttribute($m, 'attr_val'); |
|
|
|
|
|
|
|
$this->assertTrue($m->hasErrors('attr_val')); |
|
|
|
|
|
|
|
$this->assertTrue(stripos(current($m->getErrors('attr_val')), 'must be') !== false); |
|
|
|
|
|
|
|
$val = new RequiredValidator(array('requiredValue' => 55)); |
|
|
|
|
|
|
|
$m = FakedValidationModel::createWithAttributes(array('attr_val' => 55)); |
|
|
|
|
|
|
|
$val->validateAttribute($m, 'attr_val'); |
|
|
|
|
|
|
|
$this->assertFalse($m->hasErrors('attr_val')); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |