mirror of
https://github.com/Respect/Validation.git
synced 2024-06-27 17:50:13 +02:00
Fix return value email validator
add tests for email validator
This commit is contained in:
parent
f98843b6cf
commit
0615574123
|
@ -11,6 +11,6 @@ class Email extends AbstractRule
|
|||
return false;
|
||||
}
|
||||
|
||||
return filter_var($input, FILTER_VALIDATE_EMAIL);
|
||||
return (bool) filter_var($input, FILTER_VALIDATE_EMAIL);
|
||||
}
|
||||
}
|
55
tests/library/Respect/Validation/Rules/EmailTest.php
Normal file
55
tests/library/Respect/Validation/Rules/EmailTest.php
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class EmailTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @dataProvider providerForValidEmail
|
||||
*/
|
||||
public function testEmailValid($validEmail)
|
||||
{
|
||||
$validator = new Email();
|
||||
$this->assertTrue($validator->validate($validEmail));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForInvalidEmail
|
||||
* @expectedException Respect\Validation\Exceptions\EmailException
|
||||
*/
|
||||
public function testEmailInvalid($invalidEmail)
|
||||
{
|
||||
$validator = new Email();
|
||||
$this->assertFalse($validator->validate($invalidEmail));
|
||||
$this->assertFalse($validator->assert($invalidEmail));
|
||||
}
|
||||
|
||||
public function providerForValidEmail()
|
||||
{
|
||||
return array(
|
||||
array('test@test.com'),
|
||||
array('mail+mail@gmail.com'),
|
||||
array('mail.email@e.test.com'),
|
||||
array('a@a.a')
|
||||
);
|
||||
}
|
||||
|
||||
public function providerForInvalidEmail()
|
||||
{
|
||||
return array(
|
||||
array('test@test'),
|
||||
array('test'),
|
||||
array('test@тест.рф'),
|
||||
array('@test.com'),
|
||||
array('mail@test@test.com'),
|
||||
array('test.test@'),
|
||||
array('test.@test.com'),
|
||||
array('test@.test.com'),
|
||||
array('test@test..com'),
|
||||
array('test@test.com.'),
|
||||
array('.test@test.com')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue