2012-07-22 15:17:31 +02:00
|
|
|
<?php
|
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2015-06-08 16:47:14 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
2012-07-22 15:17:31 +02:00
|
|
|
|
|
|
|
class BaseTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
protected $object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForBase
|
|
|
|
*/
|
|
|
|
public function testBase($base, $input)
|
|
|
|
{
|
|
|
|
$object = new Base($base);
|
2013-01-23 08:49:20 +01:00
|
|
|
$this->assertTrue($object->__invoke($input));
|
2012-07-22 15:17:31 +02:00
|
|
|
$this->assertTrue($object->check($input));
|
|
|
|
$this->assertTrue($object->assert($input));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForInvalidBase
|
|
|
|
*/
|
|
|
|
public function testInvalidBase($base, $input)
|
|
|
|
{
|
|
|
|
$object = new Base($base);
|
2013-01-23 08:49:20 +01:00
|
|
|
$this->assertFalse($object->__invoke($input));
|
2012-07-22 15:17:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForExceptionBase
|
|
|
|
* @expectedException Respect\Validation\Exceptions\BaseException
|
|
|
|
*/
|
|
|
|
public function testExceptionBase($base, $input)
|
|
|
|
{
|
|
|
|
$object = new Base($base);
|
2013-01-23 08:49:20 +01:00
|
|
|
$this->assertTrue($object->__invoke($input));
|
2012-07-22 15:17:31 +02:00
|
|
|
$this->assertTrue($object->assert($input));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForCustomBase
|
|
|
|
*/
|
|
|
|
public function testCustomBase($base, $custom, $input)
|
|
|
|
{
|
|
|
|
$object = new Base($base, $custom);
|
2013-01-23 08:49:20 +01:00
|
|
|
$this->assertTrue($object->__invoke($input));
|
2012-07-22 15:17:31 +02:00
|
|
|
$this->assertTrue($object->check($input));
|
|
|
|
$this->assertTrue($object->assert($input));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForBase()
|
|
|
|
{
|
|
|
|
return array(
|
2013-01-23 08:49:20 +01:00
|
|
|
array(2, ''),
|
|
|
|
array(3, ''),
|
|
|
|
array(8, ''),
|
|
|
|
array(16, ''),
|
|
|
|
array(20, ''),
|
|
|
|
array(50, ''),
|
|
|
|
array(62, ''),
|
2012-07-22 15:17:31 +02:00
|
|
|
array(2, '011010001'),
|
|
|
|
array(3, '0120122001'),
|
|
|
|
array(8, '01234567520'),
|
|
|
|
array(16, '012a34f5675c20d'),
|
|
|
|
array(20, '012ah34f5675hic20dj'),
|
|
|
|
array(50, '012ah34f56A75FGhic20dj'),
|
2013-01-23 08:49:20 +01:00
|
|
|
array(62, 'Z01xSsg5675hic20dj'),
|
2012-07-22 15:17:31 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForInvalidBase()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array(2, '01210103001'),
|
|
|
|
array(3, '0120125f2001'),
|
|
|
|
array(8, '01234dfZ567520'),
|
|
|
|
array(16, '012aXS34f5675c20d'),
|
|
|
|
array(20, '012ahZX34f5675hic20dj'),
|
|
|
|
array(50, '012ahGZ34f56A75FGhic20dj'),
|
2013-01-23 08:49:20 +01:00
|
|
|
array(61, 'Z01xSsg5675hic20dj'),
|
2012-07-22 15:17:31 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForCustomBase()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array(2, 'xy', 'xyyxyxxy'),
|
2015-06-08 16:47:14 +02:00
|
|
|
array(3, 'pfg', 'gfpffp'),
|
2012-07-22 15:17:31 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForExceptionBase()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array(63, '01210103001'),
|
2015-06-08 16:47:14 +02:00
|
|
|
array(125, '0120125f2001'),
|
2012-07-22 15:17:31 +02:00
|
|
|
);
|
|
|
|
}
|
2013-01-14 23:44:49 +01:00
|
|
|
}
|