mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 15:50:03 +01:00
98 lines
2.5 KiB
PHP
98 lines
2.5 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\Prnt
|
|
* @covers Respect\Validation\Exceptions\PrntException
|
|
*/
|
|
class PrntTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
/**
|
|
* @dataProvider providerForValidPrint
|
|
*/
|
|
public function testValidDataWithPrintCharsShouldReturnTrue($validPrint, $additional = '')
|
|
{
|
|
$validator = new Prnt($additional);
|
|
$this->assertTrue($validator->validate($validPrint));
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerForInvalidPrint
|
|
* @expectedException Respect\Validation\Exceptions\PrntException
|
|
*/
|
|
public function testInvalidPrintShouldFailAndThrowPrntException($invalidPrint, $additional = '')
|
|
{
|
|
$validator = new Prnt($additional);
|
|
$this->assertFalse($validator->validate($invalidPrint));
|
|
$this->assertFalse($validator->assert($invalidPrint));
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerForInvalidParams
|
|
* @expectedException Respect\Validation\Exceptions\ComponentException
|
|
*/
|
|
public function testInvalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional)
|
|
{
|
|
$validator = new Prnt($additional);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerAdditionalChars
|
|
*/
|
|
public function testAdditionalCharsShouldBeRespected($additional, $query)
|
|
{
|
|
$validator = new Prnt($additional);
|
|
$this->assertTrue($validator->validate($query));
|
|
}
|
|
|
|
public function providerAdditionalChars()
|
|
{
|
|
return array(
|
|
array("\t\n", "\t\n "),
|
|
array("\v\r", "\v\r "),
|
|
);
|
|
}
|
|
|
|
public function providerForInvalidParams()
|
|
{
|
|
return array(
|
|
array(new \stdClass()),
|
|
array(array()),
|
|
array(0x2),
|
|
);
|
|
}
|
|
|
|
public function providerForValidPrint()
|
|
{
|
|
return array(
|
|
array(''),
|
|
array(' '),
|
|
array('LKA#@%.54'),
|
|
array('foobar'),
|
|
array('16-50'),
|
|
array('123'),
|
|
array('foo bar'),
|
|
array('#$%&*_'),
|
|
);
|
|
}
|
|
|
|
public function providerForInvalidPrint()
|
|
{
|
|
return array(
|
|
array(null),
|
|
array('foo'.chr(7).'bar'),
|
|
array('foo'.chr(10).'bar'),
|
|
);
|
|
}
|
|
}
|