XliffFileLoaderTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\Tests\Component\Translation\Loader;
  11. use Symfony\Component\Translation\Loader\XliffFileLoader;
  12. use Symfony\Component\Config\Resource\FileResource;
  13. class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testLoad()
  16. {
  17. $loader = new XliffFileLoader();
  18. $resource = __DIR__.'/../fixtures/resources.xliff';
  19. $catalogue = $loader->load($resource, 'en', 'domain1');
  20. $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
  21. $this->assertEquals('en', $catalogue->getLocale());
  22. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  23. }
  24. /**
  25. * @expectedException \RuntimeException
  26. */
  27. public function testLoadInvalidResource()
  28. {
  29. $loader = new XliffFileLoader();
  30. $catalogue = $loader->load(__DIR__.'/../fixtures/resources.php', 'en', 'domain1');
  31. }
  32. /**
  33. * @expectedException \RuntimeException
  34. */
  35. public function testLoadResourceDoesNotValidate()
  36. {
  37. $loader = new XliffFileLoader();
  38. $catalogue = $loader->load(__DIR__.'/../fixtures/non-valid.xliff', 'en', 'domain1');
  39. }
  40. /**
  41. * @expectedException \InvalidArgumentException
  42. */
  43. public function testLoadThrowsAnExceptionIfFileNotLocal()
  44. {
  45. $loader = new XliffFileLoader();
  46. $resource = 'http://example.com/resources.xliff';
  47. $loader->load($resource, 'en', 'domain1');
  48. }
  49. /**
  50. * @expectedException \RuntimeException
  51. * @expectedExceptionMessage Document types are not allowed.
  52. */
  53. public function testDocTypeIsNotAllowed()
  54. {
  55. $loader = new XliffFileLoader();
  56. $loader->load(__DIR__.'/../fixtures/withdoctype.xliff', 'en', 'domain1');
  57. }
  58. }