QtFileLoaderTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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(['foo' => 'bar'], $catalogue->all('resources'));
  22. $this->assertEquals('en', $catalogue->getLocale());
  23. $this->assertEquals([new FileResource($resource)], $catalogue->getResources());
  24. }
  25. /**
  26. * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
  27. */
  28. public function testLoadNonExistingResource()
  29. {
  30. $loader = new QtFileLoader();
  31. $resource = __DIR__.'/../fixtures/non-existing.ts';
  32. $loader->load($resource, 'en', 'domain1');
  33. }
  34. /**
  35. * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
  36. */
  37. public function testLoadNonLocalResource()
  38. {
  39. $loader = new QtFileLoader();
  40. $resource = 'http://domain1.com/resources.ts';
  41. $loader->load($resource, 'en', 'domain1');
  42. }
  43. /**
  44. * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
  45. */
  46. public function testLoadInvalidResource()
  47. {
  48. $loader = new QtFileLoader();
  49. $resource = __DIR__.'/../fixtures/invalid-xml-resources.xlf';
  50. $loader->load($resource, 'en', 'domain1');
  51. }
  52. public function testLoadEmptyResource()
  53. {
  54. $loader = new QtFileLoader();
  55. $resource = __DIR__.'/../fixtures/empty.xlf';
  56. if (method_exists($this, 'expectException')) {
  57. $this->expectException('Symfony\Component\Translation\Exception\InvalidResourceException');
  58. $this->expectExceptionMessage(sprintf('Unable to load "%s".', $resource));
  59. } else {
  60. $this->setExpectedException('Symfony\Component\Translation\Exception\InvalidResourceException', sprintf('Unable to load "%s".', $resource));
  61. }
  62. $loader->load($resource, 'en', 'domain1');
  63. }
  64. }