|
13 | 13 |
|
14 | 14 | use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
|
15 | 15 | use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
| 16 | +use Symfony\Component\Form\Extension\Validator\ValidatorExtension; |
16 | 17 | use Symfony\Component\Form\FormInterface;
|
| 18 | +use Symfony\Component\Form\Forms; |
17 | 19 | use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
|
| 20 | +use Symfony\Component\Validator\Validation; |
18 | 21 |
|
19 | 22 | class ChoiceTypeTest extends BaseTypeTest
|
20 | 23 | {
|
@@ -1815,6 +1818,38 @@ public function testAdjustFullNameForMultipleNonExpanded()
|
1815 | 1818 | $this->assertSame('name[]', $view->vars['full_name']);
|
1816 | 1819 | }
|
1817 | 1820 |
|
| 1821 | + public function testInvalidMessageAwarenessForMultiple() |
| 1822 | + { |
| 1823 | + $factory = Forms::createFormFactoryBuilder() |
| 1824 | + ->addExtensions([new ValidatorExtension(Validation::createValidator())]) |
| 1825 | + ->getFormFactory(); |
| 1826 | + $form = $factory->create(static::TESTED_TYPE, null, [ |
| 1827 | + 'multiple' => true, |
| 1828 | + 'expanded' => false, |
| 1829 | + 'choices' => $this->choices, |
| 1830 | + 'invalid_message' => 'You are not able to use value "{{ value }}"', |
| 1831 | + ]); |
| 1832 | + |
| 1833 | + $form->submit(['My invalid choice']); |
| 1834 | + $this->assertEquals("ERROR: You are not able to use value \"My invalid choice\"\n", (string) $form->getErrors(true)); |
| 1835 | + } |
| 1836 | + |
| 1837 | + public function testInvalidMessageAwarenessForMultipleWithoutScalarOrArrayViewData() |
| 1838 | + { |
| 1839 | + $factory = Forms::createFormFactoryBuilder() |
| 1840 | + ->addExtensions([new ValidatorExtension(Validation::createValidator())]) |
| 1841 | + ->getFormFactory(); |
| 1842 | + $form = $factory->create(static::TESTED_TYPE, null, [ |
| 1843 | + 'multiple' => true, |
| 1844 | + 'expanded' => false, |
| 1845 | + 'choices' => $this->choices, |
| 1846 | + 'invalid_message' => 'You are not able to use value "{{ value }}"', |
| 1847 | + ]); |
| 1848 | + |
| 1849 | + $form->submit(new \stdClass()); |
| 1850 | + $this->assertEquals("ERROR: You are not able to use value \"object\"\n", (string) $form->getErrors(true)); |
| 1851 | + } |
| 1852 | + |
1818 | 1853 | // https://github.com/symfony/symfony/issues/3298
|
1819 | 1854 | public function testInitializeWithEmptyChoices()
|
1820 | 1855 | {
|
|
0 commit comments