mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 15:50:03 +01:00
114 lines
3.1 KiB
PHP
114 lines
3.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Respect/Validation.
|
|
*
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
*
|
|
* For the full copyright and license information, please view the "LICENSE.md"
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
/**
|
|
* @group rule
|
|
* @covers Respect\Validation\Rules\Alpha
|
|
* @covers Respect\Validation\Exceptions\AlphaException
|
|
*/
|
|
class AlphaTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
/**
|
|
* @dataProvider providerForValidAlpha
|
|
*/
|
|
public function testValidAlphanumericCharsShouldReturnTrue($validAlpha, $additional)
|
|
{
|
|
$validator = new Alpha($additional);
|
|
$this->assertTrue($validator->validate($validAlpha));
|
|
$this->assertTrue($validator->check($validAlpha));
|
|
$this->assertTrue($validator->assert($validAlpha));
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerForInvalidAlpha
|
|
* @expectedException Respect\Validation\Exceptions\AlphaException
|
|
*/
|
|
public function testInvalidAlphanumericCharsShouldThrowAlphaException($invalidAlpha, $additional)
|
|
{
|
|
$validator = new Alpha($additional);
|
|
$this->assertFalse($validator->validate($invalidAlpha));
|
|
$this->assertFalse($validator->assert($invalidAlpha));
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerForInvalidParams
|
|
* @expectedException Respect\Validation\Exceptions\ComponentException
|
|
*/
|
|
public function testInvalidConstructorParamsShouldThrowComponentException($additional)
|
|
{
|
|
$validator = new Alpha($additional);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerAdditionalChars
|
|
*/
|
|
public function testAdditionalCharsShouldBeRespected($additional, $query)
|
|
{
|
|
$validator = new Alpha($additional);
|
|
$this->assertTrue($validator->validate($query));
|
|
}
|
|
|
|
public function providerAdditionalChars()
|
|
{
|
|
return array(
|
|
array('!@#$%^&*(){}', '!@#$%^&*(){} abc'),
|
|
array('[]?+=/\\-_|"\',<>.', "[]?+=/\\-_|\"',<>. \t \n abc"),
|
|
);
|
|
}
|
|
|
|
public function providerForInvalidParams()
|
|
{
|
|
return array(
|
|
array(new \stdClass()),
|
|
array(array()),
|
|
array(0x2),
|
|
);
|
|
}
|
|
|
|
public function providerForValidAlpha()
|
|
{
|
|
return array(
|
|
array('', ''),
|
|
array('alganet', ''),
|
|
array('alganet', 'alganet'),
|
|
array('0alg-anet0', '0-9'),
|
|
array('a', ''),
|
|
array("\t", ''),
|
|
array("\n", ''),
|
|
array('foobar', ''),
|
|
array('rubinho_', '_'),
|
|
array('google.com', '.'),
|
|
array('alganet alganet', ''),
|
|
array("\nabc", ''),
|
|
array("\tdef", ''),
|
|
array("\nabc \t", ''),
|
|
);
|
|
}
|
|
|
|
public function providerForInvalidAlpha()
|
|
{
|
|
return array(
|
|
array('@#$', ''),
|
|
array('_', ''),
|
|
array('dgç', ''),
|
|
array('122al', ''),
|
|
array('122', ''),
|
|
array(11123, ''),
|
|
array(1e21, ''),
|
|
array(0, ''),
|
|
array(null, ''),
|
|
array(new \stdClass(), ''),
|
|
array(array(), ''),
|
|
);
|
|
}
|
|
}
|