XliffFileDumperTest.php 4.0KB

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