-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Validate XLIFF translation files #17903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
You could add the tests to the phpunit bridge, imo the |
@javiereguiluz detailed error messages look the more useful to me |
|
||
namespace Symfony\Component\Validator\Tests\Resources; | ||
|
||
class ConstraintTest extends \PHPUnit_Framework_TestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class name doesn't equal the filename TranslationFilesTest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks.
public function setUp() | ||
{ | ||
libxml_use_internal_errors(true); | ||
libxml_clear_errors(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't you do this in the foreach loop below ?
I'd suggest also to move libxml_use_internal_errors(true);
in the test case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thank you.
This is not always a good idea. For instance, we have a base test case for ConstraintValidator in the Validator component. Moving it to the bridge would be a pain, as the logic in the testcase depends on the version of the component. So I would vote against moving everything to the bridge. |
public function testXlfFilesAreValid() | ||
{ | ||
$translationFiles = glob(__DIR__.'/../../Resources/translations/*.xlf'); | ||
foreach ($translationFiles as $filePath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in fact, would be much better with a data collector provider
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think he meant a data provider, not a data collector. And this is indeed a good idea as a failure in a file would not prevent validating subsequent files (as they would be separate tests)
$this->renderErrors($errors); | ||
} | ||
|
||
$this->assertEmpty($errors, sprintf('The "%s" file is not a valid XML file.', realpath($filePath))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to remove renderErrors, and replace $this->assertEmpty(...);
by
$this->assertSame(array(), $errors);
so that phpunit handles the output
Copy-pasting is probably the easiest here, yes. Moving this to the bridge will mean exposing it as a part of our API, which does not seem useful yet. a way to simplify the copy-pasted logic would be to use |
Refactored as suggested by Nicolas and now I'm going to try @stof's idea. |
@stof I've applied your ideas and the tests now look very simple. I've also copy+pasted the test in the 3 components. Thanks! |
/** | ||
* @dataProvider provideTranslationFiles | ||
*/ | ||
public function testTranslationFilesAreValid($filePath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically, this test concerns a single file, so you should use a singular in the test name (yeah, this is nit-picking 😄 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done the renaming.
👍 for this. And we indeed don't need to extract this to the bridge, given how simple the logic is now. |
👍 |
👍 (we may need the same test in one more places in Symfony 2.7+ in the Security component btw) |
Thank you @javiereguiluz. |
This PR was squashed before being merged into the 2.3 branch (closes #17903). Discussion ---------- Validate XLIFF translation files | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - In #17902 @stof proposed to add a simple test to validate `.xlf` files (to avoid issues like #17893). This is a proposal for that test. My questions: **1)** Do you agree displaying detailed error messages when the XML is not valid. Example output for the #17893 error:  Or is it enough displaying just the PHPUnit error message and let the user figure out the details?  **2)** How do I validate the translation files of the Security and Form components? Do I just copy+paste this test in those components? Commits ------- db03055 Validate XLIFF translation files
In #17902 @stof proposed to add a simple test to validate
.xlf
files (to avoid issues like #17893).This is a proposal for that test. My questions:
1) Do you agree displaying detailed error messages when the XML is not valid. Example output for the #17893 error:
Or is it enough displaying just the PHPUnit error message and let the user figure out the details?
2) How do I validate the translation files of the Security and Form components? Do I just copy+paste this test in those components?