forked from yiisoft/yii2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request yiisoft#10639 from githubjeka/test-uniqvalid
UniqueValidatorTest: Added test for check the invalid attribute
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
|