@@ -1662,4 +1662,80 @@ public function testMessageWithLabel2()
1662
1662
$ this ->assertSame ('Message Translated Label ' , $ error ->getMessage ());
1663
1663
}
1664
1664
}
1665
+
1666
+ public function testMessageWithLabelFormat1 ()
1667
+ {
1668
+ $ translator = $ this ->getMockBuilder (TranslatorInterface::class)->getMock ();
1669
+ $ translator ->expects ($ this ->any ())->method ('trans ' )->willReturnMap ([
1670
+ ['form.custom ' , [], null , null , 'Translated 1st Custom Label ' ],
1671
+ ]);
1672
+ $ this ->mapper = new ViolationMapper (null , $ translator );
1673
+
1674
+ $ parent = $ this ->getForm ('parent ' );
1675
+
1676
+ $ config = new FormConfigBuilder ('custom ' , null , $ this ->dispatcher , [
1677
+ 'error_mapping ' => [],
1678
+ 'label_format ' => 'form.%name% ' ,
1679
+ ]);
1680
+ $ config ->setMapped (true );
1681
+ $ config ->setInheritData (false );
1682
+ $ config ->setPropertyPath ('custom ' );
1683
+ $ config ->setCompound (true );
1684
+ $ config ->setDataMapper (new PropertyPathMapper ());
1685
+
1686
+ $ child = new Form ($ config );
1687
+ $ parent ->add ($ child );
1688
+
1689
+ $ parent ->submit ([]);
1690
+
1691
+ $ violation = new ConstraintViolation ('Message {{ label }} ' , null , [], null , 'data.custom ' , null );
1692
+ $ this ->mapper ->mapViolation ($ violation , $ parent );
1693
+
1694
+ $ this ->assertCount (1 , $ child ->getErrors (), $ child ->getName ().' should have an error, but has none ' );
1695
+
1696
+ $ errors = iterator_to_array ($ child ->getErrors ());
1697
+ if (isset ($ errors [0 ])) {
1698
+ /** @var FormError $error */
1699
+ $ error = $ errors [0 ];
1700
+ $ this ->assertSame ('Message Translated 1st Custom Label ' , $ error ->getMessage ());
1701
+ }
1702
+ }
1703
+
1704
+ public function testMessageWithLabelFormat2 ()
1705
+ {
1706
+ $ translator = $ this ->getMockBuilder (TranslatorInterface::class)->getMock ();
1707
+ $ translator ->expects ($ this ->any ())->method ('trans ' )->willReturnMap ([
1708
+ ['form_custom-id ' , [], null , null , 'Translated 2nd Custom Label ' ],
1709
+ ]);
1710
+ $ this ->mapper = new ViolationMapper (null , $ translator );
1711
+
1712
+ $ parent = $ this ->getForm ('parent ' );
1713
+
1714
+ $ config = new FormConfigBuilder ('custom-id ' , null , $ this ->dispatcher , [
1715
+ 'error_mapping ' => [],
1716
+ 'label_format ' => 'form_%id% ' ,
1717
+ ]);
1718
+ $ config ->setMapped (true );
1719
+ $ config ->setInheritData (false );
1720
+ $ config ->setPropertyPath ('custom-id ' );
1721
+ $ config ->setCompound (true );
1722
+ $ config ->setDataMapper (new PropertyPathMapper ());
1723
+
1724
+ $ child = new Form ($ config );
1725
+ $ parent ->add ($ child );
1726
+
1727
+ $ parent ->submit ([]);
1728
+
1729
+ $ violation = new ConstraintViolation ('Message {{ label }} ' , null , [], null , 'data.custom-id ' , null );
1730
+ $ this ->mapper ->mapViolation ($ violation , $ parent );
1731
+
1732
+ $ this ->assertCount (1 , $ child ->getErrors (), $ child ->getName ().' should have an error, but has none ' );
1733
+
1734
+ $ errors = iterator_to_array ($ child ->getErrors ());
1735
+ if (isset ($ errors [0 ])) {
1736
+ /** @var FormError $error */
1737
+ $ error = $ errors [0 ];
1738
+ $ this ->assertSame ('Message Translated 2nd Custom Label ' , $ error ->getMessage ());
1739
+ }
1740
+ }
1665
1741
}
0 commit comments