This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c5506f
commit 72a3789
Showing
9 changed files
with
92 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\Component\Tests\Test; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Translation\Exception\InvalidResourceException; | ||
use Symfony\Component\Translation\Loader\XliffFileLoader; | ||
|
||
abstract class XliffValidatorTestCase extends TestCase | ||
{ | ||
/** | ||
* @var XliffFileLoader | ||
*/ | ||
protected $loader; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
protected $errors = []; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->loader = new XliffFileLoader(); | ||
} | ||
|
||
/** | ||
* @dataProvider getXliffPaths | ||
*/ | ||
public function testXliff($path) | ||
{ | ||
$this->validatePath($path); | ||
|
||
if (\count($this->errors) > 0) { | ||
$this->fail(sprintf('Unable to parse xliff files: %s', implode(', ', $this->errors))); | ||
} | ||
|
||
$this->assertCount( | ||
0, | ||
$this->errors, | ||
sprintf('Unable to parse xliff files: %s', implode(', ', $this->errors)) | ||
); | ||
} | ||
|
||
/** | ||
* @return array List all path to validate xliff | ||
*/ | ||
abstract public function getXliffPaths(); | ||
|
||
/** | ||
* @param string $file The path to the xliff file | ||
*/ | ||
protected function validateXliff($file) | ||
{ | ||
try { | ||
$this->loader->load($file, 'en'); | ||
$this->assertTrue(true, sprintf('Successful loading file: %s', $file)); | ||
} catch (InvalidResourceException $e) { | ||
$this->errors[] = sprintf('%s => %s', $file, $e->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $path The path to lookup for Xliff file | ||
*/ | ||
protected function validatePath($path) | ||
{ | ||
$files = glob(sprintf('%s/*.xliff', $path)); | ||
|
||
foreach ($files as $file) { | ||
$this->validateXliff($file); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters