minor #38939 Validate XLIFF files in tests using the XSD (wouterj)
This PR was merged into the 4.4 branch.
Discussion
----------
Validate XLIFF files in tests using the XSD
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | no
| New feature? | no
| Deprecations? | no
| Tickets | -
| License | MIT
| Doc PR | -
The current tests only validated that the Xliff files were valid XML. This improves it to also validate the Xliff files against the correct XSD. This will avoid issues like https://github.com/symfony/symfony/issues/38935 in the future.
cc @Nyholm
Commits
-------
17dfa1d5fc
Validate XLIFF files in tests using the XSD
This commit is contained in:
commit
9947e14c11
@ -12,7 +12,7 @@
|
|||||||
namespace Symfony\Component\Form\Tests\Resources;
|
namespace Symfony\Component\Form\Tests\Resources;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Util\Xml\Loader;
|
use Symfony\Component\Translation\Util\XliffUtils;
|
||||||
|
|
||||||
class TranslationFilesTest extends TestCase
|
class TranslationFilesTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -21,13 +21,12 @@ class TranslationFilesTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTranslationFileIsValid($filePath)
|
public function testTranslationFileIsValid($filePath)
|
||||||
{
|
{
|
||||||
$loader = class_exists(Loader::class)
|
$document = new \DOMDocument();
|
||||||
? [new Loader(), 'loadFile']
|
$document->loadXML(file_get_contents($filePath));
|
||||||
: ['PHPUnit\Util\XML', 'loadfile'];
|
|
||||||
|
|
||||||
$loader($filePath, false, false, true);
|
$errors = XliffUtils::validateSchema($document);
|
||||||
|
|
||||||
$this->addToAssertionCount(1);
|
$this->assertCount(0, $errors, sprintf('"%s" is invalid:%s', $filePath, \PHP_EOL.implode(\PHP_EOL, array_column($errors, 'message'))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideTranslationFiles()
|
public function provideTranslationFiles()
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
namespace Symfony\Component\Security\Core\Tests\Resources;
|
namespace Symfony\Component\Security\Core\Tests\Resources;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Util\Xml\Loader;
|
use Symfony\Component\Translation\Util\XliffUtils;
|
||||||
|
|
||||||
class TranslationFilesTest extends TestCase
|
class TranslationFilesTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -21,13 +21,12 @@ class TranslationFilesTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTranslationFileIsValid($filePath)
|
public function testTranslationFileIsValid($filePath)
|
||||||
{
|
{
|
||||||
$loader = class_exists(Loader::class)
|
$document = new \DOMDocument();
|
||||||
? [new Loader(), 'loadFile']
|
$document->loadXML(file_get_contents($filePath));
|
||||||
: ['PHPUnit\Util\XML', 'loadfile'];
|
|
||||||
|
|
||||||
$loader($filePath, false, false, true);
|
$errors = XliffUtils::validateSchema($document);
|
||||||
|
|
||||||
$this->addToAssertionCount(1);
|
$this->assertCount(0, $errors, sprintf('"%s" is invalid:%s', $filePath, \PHP_EOL.implode(\PHP_EOL, array_column($errors, 'message'))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideTranslationFiles()
|
public function provideTranslationFiles()
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
"symfony/expression-language": "^3.4|^4.0|^5.0",
|
"symfony/expression-language": "^3.4|^4.0|^5.0",
|
||||||
"symfony/http-foundation": "^3.4|^4.0|^5.0",
|
"symfony/http-foundation": "^3.4|^4.0|^5.0",
|
||||||
"symfony/ldap": "^4.4|^5.0",
|
"symfony/ldap": "^4.4|^5.0",
|
||||||
|
"symfony/translation": "^4.4|^5.0",
|
||||||
"symfony/validator": "^3.4.31|^4.3.4|^5.0",
|
"symfony/validator": "^3.4.31|^4.3.4|^5.0",
|
||||||
"psr/log": "~1.0"
|
"psr/log": "~1.0"
|
||||||
},
|
},
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
namespace Symfony\Component\Validator\Tests\Resources;
|
namespace Symfony\Component\Validator\Tests\Resources;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Util\Xml\Loader;
|
use Symfony\Component\Translation\Util\XliffUtils;
|
||||||
|
|
||||||
class TranslationFilesTest extends TestCase
|
class TranslationFilesTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -21,13 +21,12 @@ class TranslationFilesTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTranslationFileIsValid($filePath)
|
public function testTranslationFileIsValid($filePath)
|
||||||
{
|
{
|
||||||
$loader = class_exists(Loader::class)
|
$document = new \DOMDocument();
|
||||||
? [new Loader(), 'loadFile']
|
$document->loadXML(file_get_contents($filePath));
|
||||||
: ['PHPUnit\Util\XML', 'loadfile'];
|
|
||||||
|
|
||||||
$loader($filePath, false, false, true);
|
$errors = XliffUtils::validateSchema($document);
|
||||||
|
|
||||||
$this->addToAssertionCount(1);
|
$this->assertCount(0, $errors, sprintf('"%s" is invalid:%s', $filePath, \PHP_EOL.implode(\PHP_EOL, array_column($errors, 'message'))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideTranslationFiles()
|
public function provideTranslationFiles()
|
||||||
|
Reference in New Issue
Block a user