From dabbb81e074a87c9a2e30d7f79da7917a1ae5498 Mon Sep 17 00:00:00 2001 From: githubjeka Date: Thu, 21 Jan 2016 21:23:51 +0300 Subject: [PATCH] Added test for check the invalid attribute --- .../validators/UniqueValidatorTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/framework/validators/UniqueValidatorTest.php b/tests/framework/validators/UniqueValidatorTest.php index 53990a63f85..62bf975c9c4 100644 --- a/tests/framework/validators/UniqueValidatorTest.php +++ b/tests/framework/validators/UniqueValidatorTest.php @@ -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@mail.com', 'email2@mail.com',]; + $validator->targetAttribute = ['email', 'name']; + $validator->validateAttribute($customerModel, 'name'); + $this->assertEquals($messageError, $customerModel->getFirstError('name')); + } + public function testValidateAttributeDefault() { $val = new UniqueValidator();