mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 15:50:03 +01:00
104 lines
2.7 KiB
PHP
104 lines
2.7 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\Vowel
|
|
* @covers Respect\Validation\Exceptions\VowelException
|
|
*/
|
|
class VowelTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
/**
|
|
* @dataProvider providerForValidVowels
|
|
*/
|
|
public function testValidDataWithVowelsShouldReturnTrue($validVowels, $additional = '')
|
|
{
|
|
$validator = new Vowel($additional);
|
|
$this->assertTrue($validator->validate($validVowels));
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerForInvalidVowels
|
|
* @expectedException Respect\Validation\Exceptions\VowelException
|
|
*/
|
|
public function testInvalidVowelsShouldFailAndThrowVowelException($invalidVowels, $additional = '')
|
|
{
|
|
$validator = new Vowel($additional);
|
|
$this->assertFalse($validator->validate($invalidVowels));
|
|
$this->assertFalse($validator->assert($invalidVowels));
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerForInvalidParams
|
|
* @expectedException Respect\Validation\Exceptions\ComponentException
|
|
*/
|
|
public function testInvalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional)
|
|
{
|
|
$validator = new Vowel($additional);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerAdditionalChars
|
|
*/
|
|
public function testAdditionalCharsShouldBeRespected($additional, $query)
|
|
{
|
|
$validator = new Vowel($additional);
|
|
$this->assertTrue($validator->validate($query));
|
|
}
|
|
|
|
public function providerAdditionalChars()
|
|
{
|
|
return array(
|
|
array('!@#$%^&*(){}', '!@#$%^&*(){} aeo iu'),
|
|
array('[]?+=/\\-_|"\',<>.', "[]?+=/\\-_|\"',<>. \t \n aeo iu"),
|
|
);
|
|
}
|
|
|
|
public function providerForInvalidParams()
|
|
{
|
|
return array(
|
|
array(new \stdClass()),
|
|
array(array()),
|
|
array(0x2),
|
|
);
|
|
}
|
|
|
|
public function providerForValidVowels()
|
|
{
|
|
return array(
|
|
array(''),
|
|
array('a'),
|
|
array('e'),
|
|
array('i'),
|
|
array('o'),
|
|
array('u'),
|
|
array('aeiou'),
|
|
array('aei ou'),
|
|
array("\na\t"),
|
|
array('uoiea'),
|
|
);
|
|
}
|
|
|
|
public function providerForInvalidVowels()
|
|
{
|
|
return array(
|
|
array(null),
|
|
array('16'),
|
|
array('F'),
|
|
array('g'),
|
|
array('Foo'),
|
|
array(-50),
|
|
array('basic'),
|
|
);
|
|
}
|
|
}
|