66use Symfony \Bundle \FrameworkBundle \Console \Application ;
77use Symfony \Component \Console \Tester \CommandTester ;
88use Translation \Bundle \Tests \Functional \BaseTestCase ;
9+ use function file_put_contents ;
910
1011class CheckCommandTest extends BaseTestCase
1112{
@@ -18,11 +19,13 @@ protected function setUp(): void
1819 {
1920 parent ::setUp ();
2021
21- $ this ->kernel ->addConfigFile (__DIR__ . '/../app/config/normal_config.yaml ' );
22+ $ this ->kernel ->addConfigFile (__DIR__ . '/../app/config/normal_config.yaml ' );
2223 $ this ->bootKernel ();
2324 $ this ->application = new Application ($ this ->kernel );
2425
25- \file_put_contents (__DIR__ .'/../app/Resources/translations/messages.sv.xlf ' , <<<'XML'
26+ file_put_contents (
27+ __DIR__ . '/../app/Resources/translations/messages.sv.xlf ' ,
28+ <<<'XML'
2629<?xml version="1.0" encoding="utf-8"?>
2730<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="en" trgLang="sv">
2831 <file id="messages.sv">
@@ -72,7 +75,7 @@ public function testReportsMissingTranslations(): void
7275 $ this ->assertGreaterThan (0 , $ commandTester ->getStatusCode ());
7376 }
7477
75- public function testReportsNoNewTranslationMessages (): void
78+ public function testReportsEmptyTranslationMessages (): void
7679 {
7780 // run translation:extract first, so all translations are extracted
7881 (new CommandTester ($ this ->application ->find ('translation:extract ' )))->execute (['locale ' => 'sv ' ]);
@@ -81,6 +84,107 @@ public function testReportsNoNewTranslationMessages(): void
8184
8285 $ commandTester ->execute (['locale ' => 'sv ' , 'configuration ' => 'app ' ]);
8386
87+ $ this ->assertStringContainsString (
88+ '4 messages have empty translations, please provide translations for them ' ,
89+ $ commandTester ->getDisplay ()
90+ );
91+ $ this ->assertGreaterThan (0 , $ commandTester ->getStatusCode ());
92+ }
93+
94+ public function testReportsNoNewTranslationMessages (): void
95+ {
96+ file_put_contents (
97+ __DIR__ . '/../app/Resources/translations/messages.sv.xlf ' ,
98+ <<<'XML'
99+ <?xml version="1.0" encoding="utf-8"?>
100+ <xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="en" trgLang="sv">
101+ <file id="messages.sv">
102+ <unit id="gwCXP88" name="translated.title">
103+ <notes>
104+ <note category="file-source" priority="1">Resources/views/translated.html.twig:5</note>
105+ <note category="state" priority="1">new</note>
106+ </notes>
107+ <segment>
108+ <source>translated.title</source>
109+ <target>My translated title</target>
110+ </segment>
111+ </unit>
112+ <unit id="MVOZYWq" name="translated.heading">
113+ <notes>
114+ <note category="file-source" priority="1">Resources/views/translated.html.twig:8</note>
115+ </notes>
116+ <segment>
117+ <source>translated.heading</source>
118+ <target>My translated heading</target>
119+ </segment>
120+ </unit>
121+ <unit id="bJFCP77" name="translated.paragraph0">
122+ <notes>
123+ <note category="file-source" priority="1">Resources/views/translated.html.twig:9</note>
124+ </notes>
125+ <segment>
126+ <source>translated.paragraph0</source>
127+ <target>My translated paragraph0</target>
128+ </segment>
129+ </unit>
130+ <unit id="1QAmWwr" name="translated.paragraph1">
131+ <notes>
132+ <note category="file-source" priority="1">Resources/views/translated.html.twig:9</note>
133+ </notes>
134+ <segment>
135+ <source>translated.paragraph1</source>
136+ <target>My translated paragraph1</target>
137+ </segment>
138+ </unit>
139+ <unit id="7AdXS54" name="translated.paragraph2">
140+ <notes>
141+ <note category="file-source" priority="1">Resources/views/translated.html.twig:11</note>
142+ <note category="state" priority="1">new</note>
143+ </notes>
144+ <segment>
145+ <source>translated.paragraph2</source>
146+ <target>My translated paragraph2</target>
147+ </segment>
148+ </unit>
149+ <unit id="WvnvT8X" name="localized.email">
150+ <notes>
151+ <note category="file-source" priority="1">Resources/views/translated.html.twig:12</note>
152+ <note category="file-source" priority="1">Resources/views/translated.html.twig:12</note>
153+ <note category="state" priority="1">new</note>
154+ </notes>
155+ <segment>
156+ <source>localized.email</source>
157+ <target>My localized email</target>
158+ </segment>
159+ </unit>
160+ <unit id="ETjQiEP" name="translated.attribute">
161+ <notes>
162+ <note category="file-source" priority="1">Resources/views/translated.html.twig:14</note>
163+ <note category="state" priority="1">new</note>
164+ </notes>
165+ <segment>
166+ <source>translated.attribute</source>
167+ <target>My translated attribute</target>
168+ </segment>
169+ </unit>
170+ <unit id="GO15Lkx" name="not.in.source">
171+ <notes>
172+ <note category="state" priority="1">obsolete</note>
173+ </notes>
174+ <segment>
175+ <source>not.in.source</source>
176+ <target>This is not in the source code</target>
177+ </segment>
178+ </unit>
179+ </file>
180+ </xliff>
181+ XML
182+ );
183+
184+ $ commandTester = new CommandTester ($ this ->application ->find ('translation:check ' ));
185+
186+ $ commandTester ->execute (['locale ' => 'sv ' , 'configuration ' => 'app ' ]);
187+
84188 $ this ->assertStringContainsString (
85189 'No new translation messages ' ,
86190 $ commandTester ->getDisplay ()
0 commit comments