4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\Tests\Dumper;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Translation\MessageCatalogue;
16 use Symfony\Component\Translation\Dumper\XliffFileDumper;
18 class XliffFileDumperTest extends TestCase
20 public function testFormatCatalogue()
22 $catalogue = new MessageCatalogue('en_US');
23 $catalogue->add(array(
26 'key.with.cdata' => '<source> & <target>',
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'))));
31 $dumper = new XliffFileDumper();
33 $this->assertStringEqualsFile(
34 __DIR__.'/../fixtures/resources-clean.xlf',
35 $dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR'))
39 public function testFormatCatalogueXliff2()
41 $catalogue = new MessageCatalogue('en_US');
42 $catalogue->add(array(
45 'key.with.cdata' => '<source> & <target>',
47 $catalogue->setMetadata('key', array('target-attributes' => array('order' => 1)));
49 $dumper = new XliffFileDumper();
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'))
57 public function testFormatCatalogueWithCustomToolInfo()
60 'default_locale' => 'en_US',
61 'tool_info' => array('tool-id' => 'foo', 'tool-name' => 'foo', 'tool-version' => '0.0', 'tool-company' => 'Foo'),
64 $catalogue = new MessageCatalogue('en_US');
65 $catalogue->add(array('foo' => 'bar'));
67 $dumper = new XliffFileDumper();
69 $this->assertStringEqualsFile(
70 __DIR__.'/../fixtures/resources-tool-info.xlf',
71 $dumper->formatCatalogue($catalogue, 'messages', $options)
75 public function testFormatCatalogueWithTargetAttributesMetadata()
77 $catalogue = new MessageCatalogue('en_US');
78 $catalogue->add(array(
81 $catalogue->setMetadata('foo', array('target-attributes' => array('state' => 'needs-translation')));
83 $dumper = new XliffFileDumper();
85 $this->assertStringEqualsFile(
86 __DIR__.'/../fixtures/resources-target-attributes.xlf',
87 $dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR'))
91 public function testFormatCatalogueWithNotesMetadata()
93 $catalogue = new MessageCatalogue('en_US');
94 $catalogue->add(array(
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'),
103 $catalogue->setMetadata('baz', array('notes' => array(
104 array('id' => 'x', 'content' => 'x_content'),
105 array('appliesTo' => 'target', 'category' => 'quality', 'content' => 'Fuzzy'),
108 $dumper = new XliffFileDumper();
110 $this->assertStringEqualsFile(
111 __DIR__.'/../fixtures/resources-notes-meta.xlf',
112 $dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR', 'xliff_version' => '2.0'))