Commit 45d92f1c by Carsten Brandt

refactored emailvalidator test

parent 7b5b93ef
...@@ -41,17 +41,23 @@ class EmailValidatorTest extends TestCase ...@@ -41,17 +41,23 @@ class EmailValidatorTest extends TestCase
$this->assertFalse($validator->validateValue('info@örtliches.de')); $this->assertFalse($validator->validateValue('info@örtliches.de'));
$this->assertFalse($validator->validateValue('sam@рмкреатиф.ru')); $this->assertFalse($validator->validateValue('sam@рмкреатиф.ru'));
$this->assertFalse($validator->validateValue('Informtation info@oertliches.de')); $this->assertFalse($validator->validateValue('Informtation info@oertliches.de'));
$this->assertTrue($validator->validateValue('test@example.com'));
$this->assertTrue($validator->validateValue('John Smith <john.smith@example.com>'));
$this->assertFalse($validator->validateValue('John Smith <example.com>'));
} }
public function testValidateIdnValue() public function testValidateValueIdn()
{ {
if (!extension_loaded("intl")) { if (!function_exists('idn_to_ascii')) {
$this->markTestSkipped("intl not installed. Skipping."); $this->markTestSkipped('Intl extension required');
return;
} }
$validator = new EmailValidator(); $validator = new EmailValidator();
$validator->enableIDN = true; $validator->enableIDN = true;
$this->assertTrue($validator->validateValue('5011@example.com'));
$this->assertTrue($validator->validateValue('example@äüößìà.de'));
$this->assertTrue($validator->validateValue('example@xn--zcack7ayc9a.de'));
$this->assertTrue($validator->validateValue('info@örtliches.de')); $this->assertTrue($validator->validateValue('info@örtliches.de'));
$this->assertTrue($validator->validateValue('sam@рмкреатиф.ru')); $this->assertTrue($validator->validateValue('sam@рмкреатиф.ru'));
$this->assertTrue($validator->validateValue('sam@rmcreative.ru')); $this->assertTrue($validator->validateValue('sam@rmcreative.ru'));
...@@ -73,6 +79,9 @@ class EmailValidatorTest extends TestCase ...@@ -73,6 +79,9 @@ class EmailValidatorTest extends TestCase
$this->assertTrue($validator->validateValue('Carsten Brandt <mail@cebe.cc>')); $this->assertTrue($validator->validateValue('Carsten Brandt <mail@cebe.cc>'));
$this->assertTrue($validator->validateValue('"Carsten Brandt" <mail@cebe.cc>')); $this->assertTrue($validator->validateValue('"Carsten Brandt" <mail@cebe.cc>'));
$this->assertTrue($validator->validateValue('<mail@cebe.cc>')); $this->assertTrue($validator->validateValue('<mail@cebe.cc>'));
$this->assertTrue($validator->validateValue('test@example.com'));
$this->assertTrue($validator->validateValue('John Smith <john.smith@example.com>'));
$this->assertFalse($validator->validateValue('John Smith <example.com>'));
} }
public function testValidateValueMx() public function testValidateValueMx()
...@@ -96,24 +105,4 @@ class EmailValidatorTest extends TestCase ...@@ -96,24 +105,4 @@ class EmailValidatorTest extends TestCase
$val->validateAttribute($model, 'attr_email'); $val->validateAttribute($model, 'attr_email');
$this->assertFalse($model->hasErrors('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(['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(['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>'));
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment