Merge remote-tracking branch 'wolf/develop' into develop

This commit is contained in:
Alexandre Gaigalas 2011-05-06 12:57:56 -03:00
commit 40aec39c4a
8 changed files with 99 additions and 7 deletions

View 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',
)
);
}

View file

@ -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)

View 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);
}
}

View file

@ -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);
}
}

View file

@ -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()

View 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')
);
}
}

View file

@ -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'));
}

View file

@ -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()