@@ -40,6 +40,23 @@ public function testLintCorrectFile()
4040$ this ->assertContains ('OK ' ,trim ($ tester ->getDisplay ()));
4141 }
4242
43+ /**
44+ * @dataProvider provideStrictFilenames
45+ */
46+ public function testStrictFilenames ($ requireStrictFileNames ,$ fileNamePattern ,$ targetLanguage ,$ mustFail )
47+ {
48+ $ tester =$ this ->createCommandTester ($ requireStrictFileNames );
49+ $ filename =$ this ->createFile ('note ' ,$ targetLanguage ,$ fileNamePattern );
50+
51+ $ tester ->execute (
52+ array ('filename ' =>$ filename ),
53+ array ('verbosity ' => OutputInterface::VERBOSITY_VERBOSE ,'decorated ' =>false )
54+ );
55+
56+ $ this ->assertEquals ($ mustFail ?1 :0 ,$ tester ->getStatusCode ());
57+ $ this ->assertContains ($ mustFail ?'[WARNING] 0 XLIFF files have valid syntax and 1 contain errors. ' :'[OK] All 1 XLIFF files contain valid syntax. ' ,$ tester ->getDisplay ());
58+ }
59+
4360public function testLintIncorrectXmlSyntax ()
4461 {
4562$ tester =$ this ->createCommandTester ();
@@ -102,7 +119,7 @@ public function testGetHelp()
102119/**
103120 * @return string Path to the new file
104121 */
105- private function createFile ($ sourceContent ='note ' ,$ targetLanguage ='en ' )
122+ private function createFile ($ sourceContent ='note ' ,$ targetLanguage ='en ' , $ fileNamePattern = ' messages.%locale%.xlf ' )
106123 {
107124$ xliffContent =<<<XLIFF
108125<?xml version="1.0"?>
@@ -118,7 +135,7 @@ private function createFile($sourceContent = 'note', $targetLanguage = 'en')
118135</xliff>
119136XLIFF ;
120137
121- $ filename =sprintf ('%s/translation-xliff-lint-test/messages.en.xlf ' ,sys_get_temp_dir ());
138+ $ filename =sprintf ('%s/translation-xliff-lint-test/%s ' ,sys_get_temp_dir (), str_replace ( ' %locale% ' , ' en ' , $ fileNamePattern ));
122139file_put_contents ($ filename ,$ xliffContent );
123140
124141$ this ->files [] =$ filename ;
@@ -129,11 +146,11 @@ private function createFile($sourceContent = 'note', $targetLanguage = 'en')
129146/**
130147 * @return CommandTester
131148 */
132- private function createCommandTester ($ application =null )
149+ private function createCommandTester ($ requireStrictFileNames = true , $ application =null )
133150 {
134151if (!$ application ) {
135152$ application =new Application ();
136- $ application ->add (new XliffLintCommand ());
153+ $ application ->add (new XliffLintCommand (null , null , null , $ requireStrictFileNames ));
137154 }
138155
139156$ command =$ application ->find ('lint:xliff ' );
@@ -160,4 +177,16 @@ protected function tearDown()
160177 }
161178rmdir (sys_get_temp_dir ().'/translation-xliff-lint-test ' );
162179 }
180+
181+ public function provideStrictFilenames ()
182+ {
183+ yield array (false ,'messages.%locale%.xlf ' ,'en ' ,false );
184+ yield array (false ,'messages.%locale%.xlf ' ,'es ' ,true );
185+ yield array (false ,'%locale%.messages.xlf ' ,'en ' ,false );
186+ yield array (false ,'%locale%.messages.xlf ' ,'es ' ,true );
187+ yield array (true ,'messages.%locale%.xlf ' ,'en ' ,false );
188+ yield array (true ,'messages.%locale%.xlf ' ,'es ' ,true );
189+ yield array (true ,'%locale%.messages.xlf ' ,'en ' ,true );
190+ yield array (true ,'%locale%.messages.xlf ' ,'es ' ,true );
191+ }
163192}