[Form] Fixed trimming choice values
This commit is contained in:
parent
10674688da
commit
00cdf5e0a5
@ -413,6 +413,7 @@ class ChoiceType extends AbstractType
|
|||||||
// See https://github.com/symfony/symfony/pull/5582
|
// See https://github.com/symfony/symfony/pull/5582
|
||||||
'data_class' => null,
|
'data_class' => null,
|
||||||
'choice_translation_domain' => true,
|
'choice_translation_domain' => true,
|
||||||
|
'trim' => false,
|
||||||
));
|
));
|
||||||
|
|
||||||
$resolver->setNormalizer('choices', $choicesNormalizer);
|
$resolver->setNormalizer('choices', $choicesNormalizer);
|
||||||
|
@ -2421,4 +2421,59 @@ class ChoiceTypeTest extends BaseTypeTest
|
|||||||
'multiple, expanded' => array(true, true, array(array())),
|
'multiple, expanded' => array(true, true, array(array())),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideTrimCases
|
||||||
|
*/
|
||||||
|
public function testTrimIsDisabled($multiple, $expanded)
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'multiple' => $multiple,
|
||||||
|
'expanded' => $expanded,
|
||||||
|
'choices' => array(
|
||||||
|
'a' => '1',
|
||||||
|
),
|
||||||
|
'choices_as_values' => true,
|
||||||
|
));
|
||||||
|
|
||||||
|
$submittedData = ' 1';
|
||||||
|
|
||||||
|
$form->submit($multiple ? (array) $submittedData : $submittedData);
|
||||||
|
|
||||||
|
// When the choice does not exist the transformation fails
|
||||||
|
$this->assertFalse($form->isSynchronized());
|
||||||
|
$this->assertNull($form->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideTrimCases
|
||||||
|
*/
|
||||||
|
public function testSubmitValueWithWhiteSpace($multiple, $expanded)
|
||||||
|
{
|
||||||
|
$valueWhitWhiteSpace = '1 ';
|
||||||
|
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'multiple' => $multiple,
|
||||||
|
'expanded' => $expanded,
|
||||||
|
'choices' => array(
|
||||||
|
'a' => $valueWhitWhiteSpace,
|
||||||
|
),
|
||||||
|
'choices_as_values' => true,
|
||||||
|
));
|
||||||
|
|
||||||
|
$form->submit($multiple ? (array) $valueWhitWhiteSpace : $valueWhitWhiteSpace);
|
||||||
|
|
||||||
|
$this->assertTrue($form->isSynchronized());
|
||||||
|
$this->assertSame($multiple ? (array) $valueWhitWhiteSpace : $valueWhitWhiteSpace, $form->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideTrimCases()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'Simple' => array(false, false),
|
||||||
|
'Multiple' => array(true, false),
|
||||||
|
'Simple expanded' => array(false, true),
|
||||||
|
'Multiple expanded' => array(true, true),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user