-
-
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
Changes from 1 commit
720779a
9a60ed2
e28ee89
93861ac
078fd02
b56e9c2
43b88b0
d324743
2e62442
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Validator\Tests\Resources; | ||
|
||
class ConstraintTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
libxml_use_internal_errors(true); | ||
libxml_clear_errors(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't you do this in the foreach loop below ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Thank you. |
||
} | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. in fact, would be much better with a data There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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) |
||
$xlfFile = simplexml_load_file($filePath); | ||
$errors = libxml_get_errors(); | ||
|
||
if (!empty($errors)) { | ||
$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 commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to remove renderErrors, and replace |
||
} | ||
} | ||
|
||
private function renderErrors(array $errors) | ||
{ | ||
$firstError = $errors[0]; | ||
|
||
echo sprintf("\nErrors found in '%s' file\n", basename($firstError->file)); | ||
echo sprintf("(path: %s)\n\n", realpath($firstError->file)); | ||
|
||
foreach ($errors as $error) { | ||
echo sprintf(" Line %d, Column %d\n", $error->line, $error->column); | ||
echo sprintf(" %s\n", $error->message); | ||
} | ||
} | ||
} |
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.