暫無描述

XliffFileDumperTest.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 Symfony\Component\Translation\MessageCatalogue;
  12. use Symfony\Component\Translation\Dumper\XliffFileDumper;
  13. class XliffFileDumperTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testFormatCatalogue()
  16. {
  17. $catalogue = new MessageCatalogue('en_US');
  18. $catalogue->add(array(
  19. 'foo' => 'bar',
  20. 'key' => '',
  21. 'key.with.cdata' => '<source> & <target>',
  22. ));
  23. $catalogue->setMetadata('foo', array('notes' => array(array('priority' => 1, 'from' => 'bar', 'content' => 'baz'))));
  24. $catalogue->setMetadata('key', array('notes' => array(array('content' => 'baz'), array('content' => 'qux'))));
  25. $dumper = new XliffFileDumper();
  26. $this->assertStringEqualsFile(
  27. __DIR__.'/../fixtures/resources-clean.xlf',
  28. $dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR'))
  29. );
  30. }
  31. public function testFormatCatalogueXliff2()
  32. {
  33. $catalogue = new MessageCatalogue('en_US');
  34. $catalogue->add(array(
  35. 'foo' => 'bar',
  36. 'key' => '',
  37. 'key.with.cdata' => '<source> & <target>',
  38. ));
  39. $catalogue->setMetadata('key', array('target-attributes' => array('order' => 1)));
  40. $dumper = new XliffFileDumper();
  41. $this->assertStringEqualsFile(
  42. __DIR__.'/../fixtures/resources-2.0-clean.xlf',
  43. $dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR', 'xliff_version' => '2.0'))
  44. );
  45. }
  46. public function testFormatCatalogueWithCustomToolInfo()
  47. {
  48. $options = array(
  49. 'default_locale' => 'en_US',
  50. 'tool_info' => array('tool-id' => 'foo', 'tool-name' => 'foo', 'tool-version' => '0.0', 'tool-company' => 'Foo'),
  51. );
  52. $catalogue = new MessageCatalogue('en_US');
  53. $catalogue->add(array('foo' => 'bar'));
  54. $dumper = new XliffFileDumper();
  55. $this->assertStringEqualsFile(
  56. __DIR__.'/../fixtures/resources-tool-info.xlf',
  57. $dumper->formatCatalogue($catalogue, 'messages', $options)
  58. );
  59. }
  60. public function testFormatCatalogueWithTargetAttributesMetadata()
  61. {
  62. $catalogue = new MessageCatalogue('en_US');
  63. $catalogue->add(array(
  64. 'foo' => 'bar',
  65. ));
  66. $catalogue->setMetadata('foo', array('target-attributes' => array('state' => 'needs-translation')));
  67. $dumper = new XliffFileDumper();
  68. $this->assertStringEqualsFile(
  69. __DIR__.'/../fixtures/resources-target-attributes.xlf',
  70. $dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR'))
  71. );
  72. }
  73. }