diff --git a/common/tests/unit/validators/EmailValidatorTest.php b/common/tests/unit/validators/EmailValidatorTest.php index 8586ac2..d2d761b 100644 --- a/common/tests/unit/validators/EmailValidatorTest.php +++ b/common/tests/unit/validators/EmailValidatorTest.php @@ -102,17 +102,22 @@ class EmailValidatorTest extends TestCase { $this->assertNotSame(['error.email_is_tempmail'], $model->getErrors('field')); } - public function testValidateAttributeIdna() { + /** + * @dataProvider getValidateAttributeIdnaTestCases + */ + public function testValidateAttributeIdna(string $input, string $expectedOutput) { $this->getFunctionMock(YiiEmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(true); $this->getFunctionMock(YiiEmailValidator::class, 'dns_get_record')->expects($this->any())->willReturn(['127.0.0.1']); - $model = $this->createModel('qdushyantasunassm@❕.gq'); + $model = $this->createModel($input); $this->validator->validateAttribute($model, 'field'); - $this->assertSame('qdushyantasunassm@xn--bei.gq', $model->field); + $this->assertSame($expectedOutput, $model->field); + } - $model = $this->createModel('valid-email@gmail.com'); - $this->validator->validateAttribute($model, 'field'); - $this->assertSame('valid-email@gmail.com', $model->field); + public function getValidateAttributeIdnaTestCases() { + yield ['qdushyantasunassm@❕.gq', 'qdushyantasunassm@xn--bei.gq']; + yield ['Rafaelaabraão@gmail.com', 'xn--rafaelaabrao-dcb@gmail.com']; + yield ['valid-email@gmail.com', 'valid-email@gmail.com']; } public function testValidateAttributeUnique() { diff --git a/common/validators/EmailValidator.php b/common/validators/EmailValidator.php index 6cd5e38..ea6447a 100644 --- a/common/validators/EmailValidator.php +++ b/common/validators/EmailValidator.php @@ -40,7 +40,7 @@ class EmailValidator extends Validator { $idnaDomain = new validators\FilterValidator(['filter' => function(string $value): string { [$name, $domain] = explode('@', $value); - return $name . '@' . idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46); + return idn_to_ascii($name, 0, INTL_IDNA_VARIANT_UTS46) . '@' . idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46); }]); $unique = new validators\UniqueValidator();