QtFileLoaderTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 Symfony\Component\Translation\Loader\QtFileLoader;
  12. use Symfony\Component\Config\Resource\FileResource;
  13. class QtFileLoaderTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected function setUp()
  16. {
  17. if (!class_exists('Symfony\Component\Config\Loader\Loader')) {
  18. $this->markTestSkipped('The "Config" component is not available');
  19. }
  20. }
  21. public function testLoad()
  22. {
  23. $loader = new QtFileLoader();
  24. $resource = __DIR__.'/../fixtures/resources.ts';
  25. $catalogue = $loader->load($resource, 'en', 'resources');
  26. $this->assertEquals(array('foo' => 'bar'), $catalogue->all('resources'));
  27. $this->assertEquals('en', $catalogue->getLocale());
  28. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  29. }
  30. /**
  31. * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
  32. */
  33. public function testLoadNonExistingResource()
  34. {
  35. $loader = new QtFileLoader();
  36. $resource = __DIR__.'/../fixtures/non-existing.ts';
  37. $loader->load($resource, 'en', 'domain1');
  38. }
  39. /**
  40. * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
  41. */
  42. public function testLoadNonLocalResource()
  43. {
  44. $loader = new QtFileLoader();
  45. $resource = 'http://domain1.com/resources.ts';
  46. $loader->load($resource, 'en', 'domain1');
  47. }
  48. /**
  49. * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
  50. */
  51. public function testLoadInvalidResource()
  52. {
  53. $loader = new QtFileLoader();
  54. $resource = __DIR__.'/../fixtures/invalid-xml-resources.xlf';
  55. $loader->load($resource, 'en', 'domain1');
  56. }
  57. }