Skip to content

Commit

Permalink
Merge pull request #35 from craue/fix-strict-check
Browse files Browse the repository at this point in the history
make strict check work again
  • Loading branch information
egulias committed Nov 6, 2014
2 parents 5c3a792 + 2ec7bab commit 518f80a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
9 changes: 2 additions & 7 deletions src/Egulias/EmailValidator/EmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function isValid($email, $checkDNS = false, $strict = false)
return false;
}

$dns = false;
$dns = true;
if ($checkDNS) {
$dns = $this->checkDNS();
}
Expand All @@ -95,12 +95,7 @@ public function isValid($email, $checkDNS = false, $strict = false)
return false;
}

return ($strict) ? $this->checkStrict($dns) : true;
}

private function checkStrict($dns)
{
return !($this->hasWarnings() && !$dns);
return !$strict || (!$this->hasWarnings() && $dns);
}

/**
Expand Down
21 changes: 16 additions & 5 deletions tests/egulias/Tests/EmailValidator/EmailValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ public function testValidEmailsWithWarningsCheck($warnings, $email)
$this->assertEquals($warnings, $this->validator->getWarnings());
}

/**
* @dataProvider getInvalidEmailsWithWarnings
*/
public function testInvalidEmailsWithDnsCheckAndStrictMode($warnings, $email)
{
$this->assertFalse($this->validator->isValid($email, true, true));

$this->assertEquals($warnings, $this->validator->getWarnings());
}

public function getInvalidEmailsWithWarnings()
{
return array(
Expand Down Expand Up @@ -301,14 +311,15 @@ public function getInvalidEmailsWithWarnings()
'parttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpart'.
'toolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpar'
),
array(
array(
EmailValidator::DNSWARN_NO_RECORD,
),
'test@test'
),
);
}

public function testInvalidEmailsWithDNSAndStrict()
{
$this->assertFalse($this->validator->isValid('test@test', true, true));
}

public function testInvalidEmailsWithStrict()
{
$this->assertFalse($this->validator->isValid('"test"@test', false, true));
Expand Down

0 comments on commit 518f80a

Please sign in to comment.