QtFileLoaderTest.php 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\Translation\Loader\QtFileLoader;
  13. use Symfony\Component\Config\Resource\FileResource;
  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(array('foo' => 'bar'), $catalogue->all('resources'));
  22. $this->assertEquals('en', $catalogue->getLocale());
  23. $this->assertEquals(array(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. }