2010-06-24 09:40:05 +01:00
|
|
|
<?php
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-15 13:29:43 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2012-03-28 14:43:52 +01:00
|
|
|
namespace Symfony\Component\Validator\Tests\Constraints;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Validator\Constraints\Blank;
|
|
|
|
use Symfony\Component\Validator\Constraints\BlankValidator;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2014-08-08 09:10:43 +01:00
|
|
|
class BlankValidatorTest extends AbstractConstraintValidatorTest
|
2010-06-24 09:40:05 +01:00
|
|
|
{
|
2014-08-08 09:10:43 +01:00
|
|
|
protected function createValidator()
|
2011-06-14 09:44:38 +01:00
|
|
|
{
|
2014-08-08 09:10:43 +01:00
|
|
|
return new BlankValidator();
|
2011-06-14 09:44:38 +01:00
|
|
|
}
|
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function testNullIsValid()
|
|
|
|
{
|
2012-02-09 17:02:12 +00:00
|
|
|
$this->validator->validate(null, new Blank());
|
2014-08-08 09:10:43 +01:00
|
|
|
|
|
|
|
$this->assertNoViolation();
|
2010-06-24 10:24:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testBlankIsValid()
|
|
|
|
{
|
2012-02-09 17:02:12 +00:00
|
|
|
$this->validator->validate('', new Blank());
|
2014-08-08 09:10:43 +01:00
|
|
|
|
|
|
|
$this->assertNoViolation();
|
2010-06-24 10:24:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider getInvalidValues
|
|
|
|
*/
|
2014-04-10 16:39:39 +01:00
|
|
|
public function testInvalidValues($value, $valueAsString)
|
2010-06-24 10:24:08 +01:00
|
|
|
{
|
2012-02-01 12:53:45 +00:00
|
|
|
$constraint = new Blank(array(
|
2014-09-21 19:53:12 +01:00
|
|
|
'message' => 'myMessage',
|
2012-02-01 12:53:45 +00:00
|
|
|
));
|
|
|
|
|
2012-02-09 17:02:12 +00:00
|
|
|
$this->validator->validate($value, $constraint);
|
2014-08-08 09:10:43 +01:00
|
|
|
|
|
|
|
$this->assertViolation(
|
|
|
|
'myMessage',
|
|
|
|
array('{{ value }}' => $valueAsString)
|
|
|
|
);
|
2010-06-24 10:24:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getInvalidValues()
|
|
|
|
{
|
|
|
|
return array(
|
2014-04-10 16:39:39 +01:00
|
|
|
array('foobar', '"foobar"'),
|
|
|
|
array(0, '0'),
|
|
|
|
array(false, 'false'),
|
|
|
|
array(1234, '1234'),
|
2010-06-24 10:24:08 +01:00
|
|
|
);
|
|
|
|
}
|
2011-06-08 18:56:59 +01:00
|
|
|
}
|