mirror of
https://github.com/Respect/Validation.git
synced 2024-06-27 17:50:13 +02:00
Merge remote-tracking branch 'wolf/develop' into develop
This commit is contained in:
commit
40aec39c4a
17
library/Respect/Validation/Exceptions/EmailException.php
Normal file
17
library/Respect/Validation/Exceptions/EmailException.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class EmailException extends ValidationException
|
||||
{
|
||||
|
||||
public static $defaultTemplates = array(
|
||||
self::MODE_DEFAULT => array(
|
||||
self::STANDARD => '{{name}} must be valid email',
|
||||
),
|
||||
self::MODE_NEGATIVE => array(
|
||||
self::STANDARD => '{{name}} must not be email',
|
||||
)
|
||||
);
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@ class Call extends AbstractRelated
|
|||
|
||||
public function getReferenceValue($input)
|
||||
{
|
||||
return call_user_func($this->reference, &$input);
|
||||
return call_user_func_array($this->reference, array(&$input));
|
||||
}
|
||||
|
||||
public function hasReference($input)
|
||||
|
|
16
library/Respect/Validation/Rules/Email.php
Normal file
16
library/Respect/Validation/Rules/Email.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class Email extends AbstractRule
|
||||
{
|
||||
|
||||
public function validate($input)
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) filter_var($input, FILTER_VALIDATE_EMAIL);
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ class Regex extends AbstractRule
|
|||
|
||||
public function validate($input)
|
||||
{
|
||||
return preg_match("/{$this->regex}/", $input);
|
||||
return (bool) preg_match($this->regex, $input);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -184,7 +184,7 @@ class NegativeTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testRegex()
|
||||
{
|
||||
$this->doTestValidator(v::regex('^[a-f]+$'), 'abcdxxxef');
|
||||
$this->doTestValidator(v::regex('/^[a-f]+$/'), 'abcdxxxef');
|
||||
}
|
||||
|
||||
public function testString()
|
||||
|
|
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')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,8 +7,12 @@ class RegexTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testRegexOk()
|
||||
{
|
||||
$v = new Regex('w+');
|
||||
$this->assertTrue($v->assert('wpoiur'));
|
||||
$v = new Regex('/^[a-z]+$/');
|
||||
$this->assertTrue($v->validate('wpoiur'));
|
||||
$this->assertFalse($v->validate('wPoiUur'));
|
||||
|
||||
$v = new Regex('/^[a-z]+$/i');
|
||||
$this->assertTrue($v->validate('wPoiur'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,7 +20,7 @@ class RegexTest extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testRegexNot()
|
||||
{
|
||||
$v = new Regex('^w+$');
|
||||
$v = new Regex('/^w+$/');
|
||||
$this->assertTrue($v->assert('w poiur'));
|
||||
}
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testRegex()
|
||||
{
|
||||
v::regex('^[a-f]+$')->assert('abcdef');
|
||||
v::regex('/^[a-f]+$/')->assert('abcdef');
|
||||
}
|
||||
|
||||
public function testString()
|
||||
|
|
Loading…
Reference in a new issue