XliffFileDumperTest.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. }