mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-28 04:59:03 +08:00
Additional tests in EmailValidator.
This commit is contained in:
@@ -64,7 +64,9 @@ class EmailValidator extends Validator
|
||||
{
|
||||
parent::init();
|
||||
if ($this->enableIDN && !function_exists('idn_to_ascii')) {
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new InvalidConfigException('In order to use IDN validation intl extension must be installed and enabled.');
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
if ($this->message === null) {
|
||||
$this->message = Yii::t('yii', '{attribute} is not a valid email address.');
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace yiiunit\framework\validators;
|
||||
|
||||
use yii\validators\EmailValidator;
|
||||
use yiiunit\TestCase;
|
||||
|
||||
@@ -25,4 +26,33 @@ class EmailValidatorTest extends TestCase
|
||||
$this->assertTrue($validator->validateValue('5011@gmail.com'));
|
||||
$this->assertFalse($validator->validateValue('test@example.com'));
|
||||
}
|
||||
|
||||
public function testValidateAttribute()
|
||||
{
|
||||
$val = new EmailValidator();
|
||||
$model = new FakedValidationModel();
|
||||
$model->attr_email = '5011@gmail.com';
|
||||
$val->validateAttribute($model, 'attr_email');
|
||||
$this->assertFalse($model->hasErrors('attr_email'));
|
||||
}
|
||||
|
||||
public function testValidateValueIdn()
|
||||
{
|
||||
if (!function_exists('idn_to_ascii')) {
|
||||
$this->markTestSkipped('Intl extension required');
|
||||
return;
|
||||
}
|
||||
$val = new EmailValidator(array('enableIDN' => true));
|
||||
$this->assertTrue($val->validateValue('5011@example.com'));
|
||||
$this->assertTrue($val->validateValue('example@äüößìà.de'));
|
||||
$this->assertTrue($val->validateValue('example@xn--zcack7ayc9a.de'));
|
||||
}
|
||||
|
||||
public function testValidateValueWithName()
|
||||
{
|
||||
$val = new EmailValidator(array('allowName' => true));
|
||||
$this->assertTrue($val->validateValue('test@example.com'));
|
||||
$this->assertTrue($val->validateValue('John Smith <john.smith@example.com>'));
|
||||
$this->assertFalse($val->validateValue('John Smith <example.com>'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user