Skip to content

Commit

Permalink
[Form] fixed a maxlength overring on a guessing
Browse files Browse the repository at this point in the history
  • Loading branch information
origaminal authored and fabpot committed Dec 12, 2014
1 parent 5284b59 commit 7248680
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/FormFactory.php
Expand Up @@ -113,11 +113,11 @@ public function createBuilderForProperty($class, $property, $data = null, array
$pattern = $patternGuess ? $patternGuess->getValue() : null;

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) {
$options = array_merge(array('attr' => array('maxlength' => $maxLength)), $options);
$options = array_replace_recursive(array('attr' => array('maxlength' => $maxLength)), $options);
}

if ($requiredGuess) {
Expand Down
35 changes: 35 additions & 0 deletions src/Symfony/Component/Form/Tests/FormFactoryTest.php
Expand Up @@ -504,6 +504,41 @@ public function testCreateBuilderUsesMaxLengthIfFound()
$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()
{
$this->guesser1->expects($this->once())
Expand Down

0 comments on commit 7248680

Please sign in to comment.