@@ -38,7 +38,7 @@ public function testSupportsAllFilters(): void
3838 $ this ->assertTrue ($ configurator ->supports ($ filterDto , null , $ this ->entityDto , $ adminContext ));
3939 }
4040
41- public function testConfigureUsesFieldLabelWhenAvailable (): void
41+ public function testConfigureUsesFieldLabelAndWrapsInTranslatable (): void
4242 {
4343 $ configurator = $ this ->createConfigurator ();
4444 $ filter = TextFilter::new ('name ' );
@@ -51,37 +51,61 @@ public function testConfigureUsesFieldLabelWhenAvailable(): void
5151
5252 $ configurator ->configure ($ filterDto , $ fieldDto , $ this ->entityDto , $ adminContext );
5353
54- $ this ->assertSame ('Product Name ' , $ filterDto ->getLabel ());
54+ $ label = $ filterDto ->getLabel ();
55+ $ this ->assertInstanceOf (TranslatableMessage::class, $ label );
56+ $ this ->assertSame ('Product Name ' , $ label ->getMessage ());
5557 }
5658
57- public function testConfigureUsesFieldTranslatableMessageLabel (): void
59+ public function testConfigurePreservesTranslatableInterfaceFromField (): void
5860 {
5961 $ configurator = $ this ->createConfigurator ();
6062 $ filter = TextFilter::new ('name ' );
6163 $ filterDto = $ filter ->getAsDto ();
6264
65+ $ translatableLabel = new TranslatableMessage ('product.name ' , [], 'messages ' );
6366 $ field = TextField::new ('name ' );
6467 $ fieldDto = $ field ->getAsDto ();
65- $ fieldDto ->setLabel (new TranslatableMessage ( ' product.name ' ) );
68+ $ fieldDto ->setLabel ($ translatableLabel );
6669
6770 $ adminContext = $ this ->createAdminContext ();
6871
6972 $ configurator ->configure ($ filterDto , $ fieldDto , $ this ->entityDto , $ adminContext );
7073
71- $ this ->assertSame (' product.name ' , $ filterDto ->getLabel ());
74+ $ this ->assertSame ($ translatableLabel , $ filterDto ->getLabel ());
7275 }
7376
74- public function testConfigureHumanizesLabelWhenFieldIsNullAndEntityTranslationsDisabled (): void
77+ public function testConfigureHumanizesLabelAndWrapsInTranslatable (): void
7578 {
7679 $ configurator = $ this ->createConfigurator ();
7780 $ filter = TextFilter::new ('productName ' );
7881 $ filterDto = $ filter ->getAsDto ();
7982
80- $ adminContext = $ this ->createAdminContext (useEntityTranslations: false );
83+ $ adminContext = $ this ->createAdminContext ();
8184
8285 $ configurator ->configure ($ filterDto , null , $ this ->entityDto , $ adminContext );
8386
84- $ this ->assertSame ('Product Name ' , $ filterDto ->getLabel ());
87+ $ label = $ filterDto ->getLabel ();
88+ $ this ->assertInstanceOf (TranslatableMessage::class, $ label );
89+ $ this ->assertSame ('Product Name ' , $ label ->getMessage ());
90+ }
91+
92+ public function testConfigureUsesCorrectTranslationDomain (): void
93+ {
94+ $ configurator = $ this ->createConfigurator ();
95+ $ filter = TextFilter::new ('name ' );
96+ $ filterDto = $ filter ->getAsDto ();
97+
98+ $ field = TextField::new ('name ' , 'custom.translation.key ' );
99+ $ fieldDto = $ field ->getAsDto ();
100+
101+ $ adminContext = $ this ->createAdminContext (translationDomain: 'my_domain ' );
102+
103+ $ configurator ->configure ($ filterDto , $ fieldDto , $ this ->entityDto , $ adminContext );
104+
105+ $ label = $ filterDto ->getLabel ();
106+ $ this ->assertInstanceOf (TranslatableMessage::class, $ label );
107+ $ this ->assertSame ('custom.translation.key ' , $ label ->getMessage ());
108+ $ this ->assertSame ('my_domain ' , $ label ->getDomain ());
85109 }
86110
87111 public function testConfigureUsesEntityTranslationWhenFieldIsNullAndEntityTranslationsEnabled (): void
@@ -125,7 +149,7 @@ private function createConfigurator(): CommonConfigurator
125149 return new CommonConfigurator ($ generator );
126150 }
127151
128- private function createAdminContext (bool $ useEntityTranslations = false ): AdminContext
152+ private function createAdminContext (bool $ useEntityTranslations = false , string $ translationDomain = ' messages ' ): AdminContext
129153 {
130154 $ dashboardDto = Dashboard::new ()->getAsDto ();
131155 if ($ useEntityTranslations ) {
@@ -136,7 +160,7 @@ private function createAdminContext(bool $useEntityTranslations = false): AdminC
136160 RequestContext::forTesting (new Request ()),
137161 null ,
138162 DashboardContext::forTesting ($ dashboardDto ),
139- I18nContext::forTesting ('en ' , 'ltr ' )
163+ I18nContext::forTesting ('en ' , 'ltr ' , $ translationDomain )
140164 );
141165 }
142166}
0 commit comments