IcuResFileLoaderTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\IcuResFileLoader;
  12. use Symfony\Component\Config\Resource\DirectoryResource;
  13. class IcuResFileLoaderTest extends LocalizedTestCase
  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. if (!extension_loaded('intl')) {
  21. $this->markTestSkipped('This test requires intl extension to work.');
  22. }
  23. }
  24. public function testLoad()
  25. {
  26. // resource is build using genrb command
  27. $loader = new IcuResFileLoader();
  28. $resource = __DIR__.'/../fixtures/resourcebundle/res';
  29. $catalogue = $loader->load($resource, 'en', 'domain1');
  30. $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
  31. $this->assertEquals('en', $catalogue->getLocale());
  32. $this->assertEquals(array(new DirectoryResource($resource)), $catalogue->getResources());
  33. }
  34. /**
  35. * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
  36. */
  37. public function testLoadNonExistingResource()
  38. {
  39. $loader = new IcuResFileLoader();
  40. $loader->load(__DIR__.'/../fixtures/non-existing.txt', 'en', 'domain1');
  41. }
  42. /**
  43. * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
  44. */
  45. public function testLoadInvalidResource()
  46. {
  47. $loader = new IcuResFileLoader();
  48. $loader->load(__DIR__.'/../fixtures/resourcebundle/corrupted', 'en', 'domain1');
  49. }
  50. }