This commit is contained in:
cuiliang
2016-06-11 19:49:57 +08:00
2065 changed files with 88639 additions and 74804 deletions

View File

@@ -72,4 +72,91 @@ class EachValidatorTest extends TestCase
$validator->validateAttribute($model, 'attr_one');
$this->assertNotContains('integer', $model->getFirstError('attr_one'));
}
}
<<<<<<< HEAD
}
=======
/**
* @depends testValidate
*/
public function testCustomMessageValue()
{
$model = FakedValidationModel::createWithAttributes([
'attr_one' => [
'TEXT',
],
]);
$validator = new EachValidator(['rule' => ['integer', 'message' => '{value} is not an integer']]);
$validator->validateAttribute($model, 'attr_one');
$this->assertSame('TEXT is not an integer', $model->getFirstError('attr_one'));
$model->clearErrors();
$validator->allowMessageFromRule = false;
$validator->message = '{value} is invalid';
$validator->validateAttribute($model, 'attr_one');
$this->assertEquals('TEXT is invalid', $model->getFirstError('attr_one'));
}
/**
* @see https://github.com/yiisoft/yii2/issues/10825
*
* @depends testValidate
*/
public function testSkipOnEmpty()
{
$validator = new EachValidator(['rule' => ['integer', 'skipOnEmpty' => true]]);
$this->assertTrue($validator->validate(['']));
$validator = new EachValidator(['rule' => ['integer', 'skipOnEmpty' => false]]);
$this->assertFalse($validator->validate(['']));
$model = FakedValidationModel::createWithAttributes([
'attr_one' => [
''
],
]);
$validator = new EachValidator(['rule' => ['integer', 'skipOnEmpty' => true]]);
$validator->validateAttribute($model, 'attr_one');
$this->assertFalse($model->hasErrors('attr_one'));
$model->clearErrors();
$validator = new EachValidator(['rule' => ['integer', 'skipOnEmpty' => false]]);
$validator->validateAttribute($model, 'attr_one');
$this->assertTrue($model->hasErrors('attr_one'));
}
/**
* @see https://github.com/yiisoft/yii2/issues/9935
*
* @depends testValidate
*/
public function testCompare()
{
$model = FakedValidationModel::createWithAttributes([
'attr_one' => [
'value1',
'value2',
'value3',
],
'attr_two' => 'value2',
]);
$validator = new EachValidator(['rule' => ['compare', 'compareAttribute' => 'attr_two']]);
$validator->validateAttribute($model, 'attr_one');
$this->assertNotEmpty($model->getErrors('attr_one'));
$this->assertEquals(3, count($model->attr_one));
$model = FakedValidationModel::createWithAttributes([
'attr_one' => [
'value1',
'value2',
'value3',
],
'attr_two' => 'value4',
]);
$validator = new EachValidator(['rule' => ['compare', 'compareAttribute' => 'attr_two', 'operator' => '!=']]);
$validator->validateAttribute($model, 'attr_one');
$this->assertEmpty($model->getErrors('attr_one'));
}
}
>>>>>>> master