QtFileLoaderTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\Loader;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Config\Resource\FileResource;
  13. use Symfony\Component\Translation\Loader\QtFileLoader;
  14. class QtFileLoaderTest extends TestCase
  15. {
  16. public function testLoad()
  17. {
  18. $loader = new QtFileLoader();
  19. $resource = __DIR__.'/../fixtures/resources.ts';
  20. $catalogue = $loader->load($resource, 'en', 'resources');
  21. $this->assertEquals([
  22. 'foo' => 'bar',
  23. 'foo_bar' => 'foobar',
  24. 'bar_foo' => 'barfoo',
  25. ], $catalogue->all('resources'));
  26. $this->assertEquals('en', $catalogue->getLocale());
  27. $this->assertEquals([new FileResource($resource)], $catalogue->getResources());
  28. }
  29. /**
  30. * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
  31. */
  32. public function testLoadNonExistingResource()
  33. {
  34. $loader = new QtFileLoader();
  35. $resource = __DIR__.'/../fixtures/non-existing.ts';
  36. $loader->load($resource, 'en', 'domain1');
  37. }
  38. /**
  39. * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
  40. */
  41. public function testLoadNonLocalResource()
  42. {
  43. $loader = new QtFileLoader();
  44. $resource = 'http://domain1.com/resources.ts';
  45. $loader->load($resource, 'en', 'domain1');
  46. }
  47. /**
  48. * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
  49. */
  50. public function testLoadInvalidResource()
  51. {
  52. $loader = new QtFileLoader();
  53. $resource = __DIR__.'/../fixtures/invalid-xml-resources.xlf';
  54. $loader->load($resource, 'en', 'domain1');
  55. }
  56. public function testLoadEmptyResource()
  57. {
  58. $loader = new QtFileLoader();
  59. $resource = __DIR__.'/../fixtures/empty.xlf';
  60. if (method_exists($this, 'expectException')) {
  61. $this->expectException('Symfony\Component\Translation\Exception\InvalidResourceException');
  62. $this->expectExceptionMessage(sprintf('Unable to load "%s".', $resource));
  63. } else {
  64. $this->setExpectedException('Symfony\Component\Translation\Exception\InvalidResourceException', sprintf('Unable to load "%s".', $resource));
  65. }
  66. $loader->load($resource, 'en', 'domain1');
  67. }
  68. }