Merge pull request #33 from egulias/32_strict_and_dns_bug

#32 - Fixed usage of DNS check and strict parameter
This commit is contained in:
Eduardo Gulias Davis
2014-11-03 00:13:57 +01:00
2 changed files with 18 additions and 10 deletions
+8 -10
View File
@@ -84,7 +84,7 @@ class EmailValidator
return false;
}
$dns = true;
$dns = false;
if ($checkDNS) {
$dns = $this->checkDNS();
}
@@ -95,7 +95,12 @@ class EmailValidator
return false;
}
return ($strict) ? (!$this->hasWarnings() && $dns) : true;
return ($strict) ? $this->checkStrict($dns) : true;
}
private function checkStrict($dns)
{
return !($this->hasWarnings() && !$dns);
}
/**
@@ -144,16 +149,9 @@ class EmailValidator
protected function checkDNS()
{
$checked = false;
if (!function_exists('dns_get_record') && (
in_array(self::DNSWARN_NO_RECORD, $this->warnings) &&
in_array(self::DNSWARN_NO_MX_RECORD, $this->warnings)
)) {
return $checked;
}
$checked = true;
$result = checkdnsrr(trim($this->parser->getParsedDomainPart()), 'MX');
$checked = true;
if (!$result) {
$this->warnings[] = self::DNSWARN_NO_RECORD;
@@ -303,4 +303,14 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
),
);
}
public function testInvalidEmailsWithDNSAndStrict()
{
$this->assertFalse($this->validator->isValid('test@test', true, true));
}
public function testInvalidEmailsWithStrict()
{
$this->assertFalse($this->validator->isValid('"test"@test', false, true));
}
}