|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the PHP Translation package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) PHP Translation team <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Translation\Converter\Tests\Functional\Service; |
|
13
|
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
use Translation\Bundle\Model\Metadata; |
|
16
|
|
|
use Translation\Converter\Reader\JmsReader; |
|
17
|
|
|
use Translation\Converter\Service\Converter; |
|
18
|
|
|
use Translation\SymfonyStorage\Loader\XliffLoader; |
|
19
|
|
|
use Symfony\Component\Translation\Loader; |
|
20
|
|
|
|
|
21
|
|
|
class ConverterTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
protected static $fixturesDir; |
|
24
|
|
|
|
|
25
|
|
|
protected static $outputDir; |
|
26
|
|
|
|
|
27
|
|
|
public static function setUpBeforeClass() |
|
28
|
|
|
{ |
|
29
|
|
|
self::$outputDir = sys_get_temp_dir().'/translation_converter_output'; |
|
30
|
|
|
self::$fixturesDir = __DIR__.'/../../Fixtures'; |
|
31
|
|
|
parent::setUpBeforeClass(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
protected function setUp() |
|
35
|
|
|
{ |
|
36
|
|
|
@mkdir(self::$outputDir, 0777, true); |
|
|
|
|
|
|
37
|
|
|
$files = glob(self::$outputDir.'/*'); |
|
38
|
|
|
foreach ($files as $file) { |
|
39
|
|
|
if (is_file($file)) { |
|
40
|
|
|
unlink($file); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testConvertJMS() |
|
46
|
|
|
{ |
|
47
|
|
|
$reader = new JmsReader(); |
|
48
|
|
|
$converter = new Converter($reader, ['xlf', 'xliff']); |
|
49
|
|
|
$converter->convert(self::$fixturesDir, self::$outputDir, ['en']); |
|
50
|
|
|
|
|
51
|
|
|
$catalogue = (new XliffLoader())->load(self::$outputDir.'/messages.en.xlf', 'en'); |
|
52
|
|
|
$this->assertEquals('This is a bar.', $catalogue->get('bar')); |
|
53
|
|
|
$meta = new Metadata($catalogue->getMetadata('bar')); |
|
54
|
|
|
$this->assertTrue($meta->isApproved()); |
|
55
|
|
|
$this->assertEquals('new', $meta->getState()); |
|
56
|
|
|
$this->assertEquals('Tests/Translation/XliffMessageUpdaterTest.php', $meta->getSourceLocations()[0]['path']); |
|
57
|
|
|
|
|
58
|
|
|
$catalogue = (new XliffLoader())->load(self::$outputDir.'/xliff.en.xlf', 'en'); |
|
59
|
|
|
$this->assertEquals('This is a bar.', $catalogue->get('bar')); |
|
60
|
|
|
$meta = new Metadata($catalogue->getMetadata('bar')); |
|
61
|
|
|
$this->assertTrue($meta->isApproved()); |
|
62
|
|
|
$this->assertEquals('new', $meta->getState()); |
|
63
|
|
|
$this->assertEquals('Tests/Translation/XliffMessageUpdaterTest.php', $meta->getSourceLocations()[0]['path']); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testConvertYaml() |
|
67
|
|
|
{ |
|
68
|
|
|
$reader = new Loader\YamlFileLoader(); |
|
69
|
|
|
$converter = new Converter($reader, 'yml'); |
|
70
|
|
|
$converter->convert(self::$fixturesDir, self::$outputDir, ['en']); |
|
71
|
|
|
|
|
72
|
|
|
$catalogue = (new XliffLoader())->load(self::$outputDir.'/admin.en.xlf', 'en'); |
|
73
|
|
|
$this->assertEquals('Business', $catalogue->get('en.symbol.anonymous')); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: