[Form] fixed a maxlength overring on a guessing

This commit is contained in:
origaminal 2014-11-23 06:56:17 +03:00 committed by Fabien Potencier
parent 5284b59fb9
commit 7248680eba
2 changed files with 37 additions and 2 deletions

View File

@ -113,11 +113,11 @@ class FormFactory implements FormFactoryInterface
$pattern = $patternGuess ? $patternGuess->getValue() : null; $pattern = $patternGuess ? $patternGuess->getValue() : null;
if (null !== $pattern) { if (null !== $pattern) {
$options = array_merge(array('attr' => array('pattern' => $pattern)), $options); $options = array_replace_recursive(array('attr' => array('pattern' => $pattern)), $options);
} }
if (null !== $maxLength) { if (null !== $maxLength) {
$options = array_merge(array('attr' => array('maxlength' => $maxLength)), $options); $options = array_replace_recursive(array('attr' => array('maxlength' => $maxLength)), $options);
} }
if ($requiredGuess) { if ($requiredGuess) {

View File

@ -504,6 +504,41 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('builderInstance', $this->builder); $this->assertEquals('builderInstance', $this->builder);
} }
public function testCreateBuilderUsesMaxLengthAndPattern()
{
$this->guesser1->expects($this->once())
->method('guessMaxLength')
->with('Application\Author', 'firstName')
->will($this->returnValue(new ValueGuess(
20,
Guess::HIGH_CONFIDENCE
)));
$this->guesser2->expects($this->once())
->method('guessPattern')
->with('Application\Author', 'firstName')
->will($this->returnValue(new ValueGuess(
'.{5,}',
Guess::HIGH_CONFIDENCE
)));
$factory = $this->getMockFactory(array('createNamedBuilder'));
$factory->expects($this->once())
->method('createNamedBuilder')
->with('firstName', 'text', null, array('attr' => array('maxlength' => 20, 'pattern' => '.{5,}', 'class' => 'tinymce')))
->will($this->returnValue('builderInstance'));
$this->builder = $factory->createBuilderForProperty(
'Application\Author',
'firstName',
null,
array('attr' => array('class' => 'tinymce'))
);
$this->assertEquals('builderInstance', $this->builder);
}
public function testCreateBuilderUsesRequiredSettingWithHighestConfidence() public function testCreateBuilderUsesRequiredSettingWithHighestConfidence()
{ {
$this->guesser1->expects($this->once()) $this->guesser1->expects($this->once())