From 7248680eba0dce50521d99caf1a289b31e3a1ad7 Mon Sep 17 00:00:00 2001 From: origaminal Date: Sun, 23 Nov 2014 06:56:17 +0300 Subject: [PATCH] [Form] fixed a maxlength overring on a guessing --- src/Symfony/Component/Form/FormFactory.php | 4 +-- .../Component/Form/Tests/FormFactoryTest.php | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Form/FormFactory.php b/src/Symfony/Component/Form/FormFactory.php index 8a7b1cab05d9..cfca4588bd8b 100644 --- a/src/Symfony/Component/Form/FormFactory.php +++ b/src/Symfony/Component/Form/FormFactory.php @@ -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) { diff --git a/src/Symfony/Component/Form/Tests/FormFactoryTest.php b/src/Symfony/Component/Form/Tests/FormFactoryTest.php index a06b49876e1c..59e9e8085cc5 100644 --- a/src/Symfony/Component/Form/Tests/FormFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/FormFactoryTest.php @@ -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())