Add namespace.
This commit is contained in:
27
Tests/validator/EmailValidatorTest.php
Normal file
27
Tests/validator/EmailValidatorTest.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage UnitTests
|
||||
* @since 2011-10-07
|
||||
*
|
||||
* Unit tests for RegexValdator class
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../validator/iValidator.php';
|
||||
require_once dirname(__FILE__) . '/../../validator/Validator.php';
|
||||
require_once dirname(__FILE__) . '/../../validator/RegexValidator.php';
|
||||
require_once dirname(__FILE__) . '/../../validator/EmailValidator.php';
|
||||
|
||||
class EmailValidatorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testConstruct()
|
||||
{
|
||||
$validator = new EmailValidator();
|
||||
$this->assertTrue($validator->isValid('mail@mail.erw'));
|
||||
$this->assertFalse($validator->isValid('asdasd'));
|
||||
}
|
||||
}
|
35
Tests/validator/EqualValidatorTest.php
Normal file
35
Tests/validator/EqualValidatorTest.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage UnitTests
|
||||
* @since 2011-10-07
|
||||
*
|
||||
* Unit tests for RegexValdator class
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../validator/iValidator.php';
|
||||
require_once dirname(__FILE__) . '/../../validator/Validator.php';
|
||||
require_once dirname(__FILE__) . '/../../validator/EqualValidator.php';
|
||||
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
|
||||
|
||||
class EqualValidatorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$validator = new EqualValidator('token');
|
||||
$this->assertFalse($validator->isValid('not token'));
|
||||
$this->assertTrue($validator->isValid('token'));
|
||||
}
|
||||
|
||||
public function testNullToken()
|
||||
{
|
||||
$validator = new EqualValidator(null);
|
||||
$this->setExpectedException('InitializationException','Token not defined');
|
||||
$validator->isValid('not token');
|
||||
}
|
||||
|
||||
}
|
||||
|
37
Tests/validator/NotEmptyValidatorTest.php
Normal file
37
Tests/validator/NotEmptyValidatorTest.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage UnitTests
|
||||
* @since 2011-10-07
|
||||
*
|
||||
* Unit tests for RegexValdator class
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../validator/iValidator.php';
|
||||
require_once dirname(__FILE__) . '/../../validator/Validator.php';
|
||||
require_once dirname(__FILE__) . '/../../validator/NotEmptyValidator.php';
|
||||
|
||||
class NotEmptyValidatorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testValidator()
|
||||
{
|
||||
$validator = new NotEmptyValidator();
|
||||
$this->assertFalse($validator->isValid(''));
|
||||
$this->assertTrue($validator->isValid('token'));
|
||||
$this->assertTrue($validator->isValid(1212));
|
||||
$this->assertTrue($validator->isValid(array(1,2,2)));
|
||||
$this->assertFalse($validator->isValid(array()));
|
||||
$this->assertNotEmpty($validator->getMessage());
|
||||
}
|
||||
|
||||
public function testEmptyValue()
|
||||
{
|
||||
$validator = new NotEmptyValidator(null);
|
||||
$this->assertFalse($validator->isValid(null));
|
||||
}
|
||||
|
||||
}
|
||||
|
75
Tests/validator/RegexValidatorTest.php
Normal file
75
Tests/validator/RegexValidatorTest.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage UnitTests
|
||||
* @since 2011-10-07
|
||||
*
|
||||
* Unit tests for RegexValdator class
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../validator/iValidator.php';
|
||||
require_once dirname(__FILE__) . '/../../validator/Validator.php';
|
||||
require_once dirname(__FILE__) . '/../../validator/RegexValidator.php';
|
||||
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
|
||||
|
||||
class RegexValidatorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testIsValid()
|
||||
{
|
||||
$validator = new RegexValidator('/^[a-z]*$/i');
|
||||
|
||||
$this->assertTrue($validator->isValid('anTon', array(1,2,3)));
|
||||
$this->assertFalse($validator->isValid('12ejkas,.21'));
|
||||
}
|
||||
|
||||
public function testGetMessage()
|
||||
{
|
||||
$validator = new RegexValidator('/^[a-z0-9]*$/i');
|
||||
$this->assertTrue($validator->isValid('ton342ad21y'));
|
||||
$this->assertEmpty($validator->getMessage());
|
||||
$this->assertFalse($validator->isValid('!!#asd'));
|
||||
$this->assertNotEmpty($validator->getMessage());
|
||||
}
|
||||
|
||||
public function testSetMessage()
|
||||
{
|
||||
$validator = new RegexValidator('/a/i');
|
||||
$validator->isValid('2sa131');
|
||||
$this->assertEmpty($validator->getMessage());
|
||||
$validator->setMessage('i am ok');
|
||||
$validator->isValid('2131');
|
||||
$this->assertSame('i am ok', $validator->getMessage());
|
||||
}
|
||||
|
||||
|
||||
public function testNullMessage()
|
||||
{
|
||||
$validator = new RegexValidator('/a/i');
|
||||
$validator->setMessage(null, null);
|
||||
|
||||
$this->setExpectedException('GeneralException', 'Message template "regex_not_match" unknown.');
|
||||
|
||||
$validator->isValid('1212');
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO: RegexValidator - wrong regex throws an error. Check this.
|
||||
*/
|
||||
public function testWrongRegexp()
|
||||
{
|
||||
$validator = new RegexValidator('/^[a-z][0-9]$*/i');
|
||||
$this->setExpectedException('PHPUnit_Framework_Error');
|
||||
$this->assertFalse($validator->isValid('to423$%ny'));
|
||||
}
|
||||
|
||||
public function testRegexReturnsFalse()
|
||||
{
|
||||
$validator = new RegexValidator('/(?:\D+|<\d+>)*[!?]/');
|
||||
$this->setExpectedException('GeneralException', 'regex');
|
||||
$this->assertFalse($validator->isValid('foobar foobar foobar'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user