738d4b3b2f1e660f838a685855ff932240d25542
[yaffs-website] / vendor / symfony / translation / Tests / Dumper / XliffFileDumperTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
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 Symfony\Component\Translation\Tests\Dumper;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Translation\MessageCatalogue;
16 use Symfony\Component\Translation\Dumper\XliffFileDumper;
17
18 class XliffFileDumperTest extends TestCase
19 {
20     public function testFormatCatalogue()
21     {
22         $catalogue = new MessageCatalogue('en_US');
23         $catalogue->add(array(
24             'foo' => 'bar',
25             'key' => '',
26             'key.with.cdata' => '<source> & <target>',
27         ));
28         $catalogue->setMetadata('foo', array('notes' => array(array('priority' => 1, 'from' => 'bar', 'content' => 'baz'))));
29         $catalogue->setMetadata('key', array('notes' => array(array('content' => 'baz'), array('content' => 'qux'))));
30
31         $dumper = new XliffFileDumper();
32
33         $this->assertStringEqualsFile(
34             __DIR__.'/../fixtures/resources-clean.xlf',
35             $dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR'))
36         );
37     }
38
39     public function testFormatCatalogueXliff2()
40     {
41         $catalogue = new MessageCatalogue('en_US');
42         $catalogue->add(array(
43             'foo' => 'bar',
44             'key' => '',
45             'key.with.cdata' => '<source> & <target>',
46         ));
47         $catalogue->setMetadata('key', array('target-attributes' => array('order' => 1)));
48
49         $dumper = new XliffFileDumper();
50
51         $this->assertStringEqualsFile(
52             __DIR__.'/../fixtures/resources-2.0-clean.xlf',
53             $dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR', 'xliff_version' => '2.0'))
54         );
55     }
56
57     public function testFormatCatalogueWithCustomToolInfo()
58     {
59         $options = array(
60             'default_locale' => 'en_US',
61             'tool_info' => array('tool-id' => 'foo', 'tool-name' => 'foo', 'tool-version' => '0.0', 'tool-company' => 'Foo'),
62         );
63
64         $catalogue = new MessageCatalogue('en_US');
65         $catalogue->add(array('foo' => 'bar'));
66
67         $dumper = new XliffFileDumper();
68
69         $this->assertStringEqualsFile(
70             __DIR__.'/../fixtures/resources-tool-info.xlf',
71             $dumper->formatCatalogue($catalogue, 'messages', $options)
72         );
73     }
74
75     public function testFormatCatalogueWithTargetAttributesMetadata()
76     {
77         $catalogue = new MessageCatalogue('en_US');
78         $catalogue->add(array(
79             'foo' => 'bar',
80         ));
81         $catalogue->setMetadata('foo', array('target-attributes' => array('state' => 'needs-translation')));
82
83         $dumper = new XliffFileDumper();
84
85         $this->assertStringEqualsFile(
86             __DIR__.'/../fixtures/resources-target-attributes.xlf',
87             $dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR'))
88         );
89     }
90
91     public function testFormatCatalogueWithNotesMetadata()
92     {
93         $catalogue = new MessageCatalogue('en_US');
94         $catalogue->add(array(
95             'foo' => 'bar',
96             'baz' => 'biz',
97         ));
98         $catalogue->setMetadata('foo', array('notes' => array(
99             array('category' => 'state', 'content' => 'new'),
100             array('category' => 'approved', 'content' => 'true'),
101             array('category' => 'section', 'content' => 'user login', 'priority' => '1'),
102         )));
103         $catalogue->setMetadata('baz', array('notes' => array(
104             array('id' => 'x', 'content' => 'x_content'),
105             array('appliesTo' => 'target', 'category' => 'quality', 'content' => 'Fuzzy'),
106         )));
107
108         $dumper = new XliffFileDumper();
109
110         $this->assertStringEqualsFile(
111             __DIR__.'/../fixtures/resources-notes-meta.xlf',
112             $dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR', 'xliff_version' => '2.0'))
113         );
114     }
115 }