|
14 | 14 | use Symfony\Component\Form\CallbackTransformer; |
15 | 15 | use Symfony\Component\Form\DataMapperInterface; |
16 | 16 | use Symfony\Component\Form\Exception\InvalidArgumentException; |
| 17 | +use Symfony\Component\Form\Exception\LogicException; |
17 | 18 | use Symfony\Component\Form\Exception\TransformationFailedException; |
18 | 19 | use Symfony\Component\Form\Extension\Core\Type\CurrencyType; |
19 | 20 | use Symfony\Component\Form\Extension\Core\Type\FormType; |
@@ -774,6 +775,67 @@ public function testErrorBubblingDoesNotSkipCompoundFieldsWithInheritDataConfigu |
774 | 775 | $this->assertSame($error, $form->get('inherit_data_type')->getErrors()[0]); |
775 | 776 | $this->assertCount(0, $form->get('inherit_data_type')->get('child')->getErrors()); |
776 | 777 | } |
| 778 | + |
| 779 | + public function testFormAttrOnRoot() |
| 780 | + { |
| 781 | + $view = $this->factory |
| 782 | + ->createNamedBuilder('parent', self::TESTED_TYPE, null, [ |
| 783 | + 'form_attr' => true, |
| 784 | + ]) |
| 785 | + ->add('child1', $this->getTestedType()) |
| 786 | + ->add('child2', $this->getTestedType()) |
| 787 | + ->getForm() |
| 788 | + ->createView(); |
| 789 | + $this->assertArrayNotHasKey('form', $view->vars['attr']); |
| 790 | + $this->assertSame($view->vars['id'], $view['child1']->vars['attr']['form']); |
| 791 | + $this->assertSame($view->vars['id'], $view['child2']->vars['attr']['form']); |
| 792 | + } |
| 793 | + |
| 794 | + public function testFormAttrOnChild() |
| 795 | + { |
| 796 | + $view = $this->factory |
| 797 | + ->createNamedBuilder('parent', self::TESTED_TYPE) |
| 798 | + ->add('child1', $this->getTestedType(), [ |
| 799 | + 'form_attr' => true, |
| 800 | + ]) |
| 801 | + ->add('child2', $this->getTestedType()) |
| 802 | + ->getForm() |
| 803 | + ->createView(); |
| 804 | + $this->assertArrayNotHasKey('form', $view->vars['attr']); |
| 805 | + $this->assertSame($view->vars['id'], $view['child1']->vars['attr']['form']); |
| 806 | + $this->assertArrayNotHasKey('form', $view['child2']->vars['attr']); |
| 807 | + } |
| 808 | + |
| 809 | + public function testFormAttrAsBoolWithNoId() |
| 810 | + { |
| 811 | + $this->expectException(LogicException::class); |
| 812 | + $this->expectErrorMessage('form_attr'); |
| 813 | + $this->factory |
| 814 | + ->createNamedBuilder('', self::TESTED_TYPE, null, [ |
| 815 | + 'form_attr' => true, |
| 816 | + ]) |
| 817 | + ->add('child1', $this->getTestedType()) |
| 818 | + ->add('child2', $this->getTestedType()) |
| 819 | + ->getForm() |
| 820 | + ->createView(); |
| 821 | + } |
| 822 | + |
| 823 | + public function testFormAttrAsStringWithNoId() |
| 824 | + { |
| 825 | + $stringId = 'custom-identifier'; |
| 826 | + $view = $this->factory |
| 827 | + ->createNamedBuilder('', self::TESTED_TYPE, null, [ |
| 828 | + 'form_attr' => $stringId, |
| 829 | + ]) |
| 830 | + ->add('child1', $this->getTestedType()) |
| 831 | + ->add('child2', $this->getTestedType()) |
| 832 | + ->getForm() |
| 833 | + ->createView(); |
| 834 | + $this->assertArrayNotHasKey('form', $view->vars['attr']); |
| 835 | + $this->assertSame($stringId, $view->vars['id']); |
| 836 | + $this->assertSame($view->vars['id'], $view['child1']->vars['attr']['form']); |
| 837 | + $this->assertSame($view->vars['id'], $view['child2']->vars['attr']['form']); |
| 838 | + } |
777 | 839 | } |
778 | 840 |
|
779 | 841 | class Money |
|
0 commit comments