Skip to content

Commit 1cd4d48

Browse files
committed
bug #12548 [Form] fixed a maxlength overring on a guessing (origaminal)
This PR was squashed before being merged into the 2.5 branch (closes #12548). Discussion ---------- [Form] fixed a maxlength overring on a guessing | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11527 | License | MIT | Doc PR | - Commits ------- 7248680 [Form] fixed a maxlength overring on a guessing
2 parents 2a46e31 + 7248680 commit 1cd4d48

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/Symfony/Component/Form/FormFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ public function createBuilderForProperty($class, $property, $data = null, array
113113
$pattern = $patternGuess ? $patternGuess->getValue() : null;
114114

115115
if (null !== $pattern) {
116-
$options = array_merge(array('attr' => array('pattern' => $pattern)), $options);
116+
$options = array_replace_recursive(array('attr' => array('pattern' => $pattern)), $options);
117117
}
118118

119119
if (null !== $maxLength) {
120-
$options = array_merge(array('attr' => array('maxlength' => $maxLength)), $options);
120+
$options = array_replace_recursive(array('attr' => array('maxlength' => $maxLength)), $options);
121121
}
122122

123123
if ($requiredGuess) {

src/Symfony/Component/Form/Tests/FormFactoryTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,41 @@ public function testCreateBuilderUsesMaxLengthIfFound()
504504
$this->assertEquals('builderInstance', $this->builder);
505505
}
506506

507+
public function testCreateBuilderUsesMaxLengthAndPattern()
508+
{
509+
$this->guesser1->expects($this->once())
510+
->method('guessMaxLength')
511+
->with('Application\Author', 'firstName')
512+
->will($this->returnValue(new ValueGuess(
513+
20,
514+
Guess::HIGH_CONFIDENCE
515+
)));
516+
517+
$this->guesser2->expects($this->once())
518+
->method('guessPattern')
519+
->with('Application\Author', 'firstName')
520+
->will($this->returnValue(new ValueGuess(
521+
'.{5,}',
522+
Guess::HIGH_CONFIDENCE
523+
)));
524+
525+
$factory = $this->getMockFactory(array('createNamedBuilder'));
526+
527+
$factory->expects($this->once())
528+
->method('createNamedBuilder')
529+
->with('firstName', 'text', null, array('attr' => array('maxlength' => 20, 'pattern' => '.{5,}', 'class' => 'tinymce')))
530+
->will($this->returnValue('builderInstance'));
531+
532+
$this->builder = $factory->createBuilderForProperty(
533+
'Application\Author',
534+
'firstName',
535+
null,
536+
array('attr' => array('class' => 'tinymce'))
537+
);
538+
539+
$this->assertEquals('builderInstance', $this->builder);
540+
}
541+
507542
public function testCreateBuilderUsesRequiredSettingWithHighestConfidence()
508543
{
509544
$this->guesser1->expects($this->once())

0 commit comments

Comments
 (0)