Skip to content

Commit

Permalink
Merge pull request yiisoft#10639 from githubjeka/test-uniqvalid
Browse files Browse the repository at this point in the history
UniqueValidatorTest: Added test for check the invalid attribute
  • Loading branch information
samdark committed Jan 22, 2016
2 parents c9580b5 + dabbb81 commit c79ebf4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/framework/validators/UniqueValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ public function testAssureMessageSetOnInit()
$this->assertTrue(is_string($val->message));
}

public function testValidateInvalidAttribute()
{
$validator = new UniqueValidator();
$messageError = Yii::t('yii', '{attribute} is invalid.', ['attribute' => 'Name']);

/** @var Customer $customerModel */
$customerModel = Customer::findOne(1);
$customerModel->name = ['test array data'];
$validator->validateAttribute($customerModel, 'name');
$this->assertEquals($messageError, $customerModel->getFirstError('name'));

$customerModel->clearErrors();

$customerModel->name = 'test data';
$customerModel->email = ['[email protected]', '[email protected]',];
$validator->targetAttribute = ['email', 'name'];
$validator->validateAttribute($customerModel, 'name');
$this->assertEquals($messageError, $customerModel->getFirstError('name'));
}

public function testValidateAttributeDefault()
{
$val = new UniqueValidator();
Expand Down

0 comments on commit c79ebf4

Please sign in to comment.