IcuDatFileLoaderTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\IcuDatFileLoader;
  12. use Symfony\Component\Config\Resource\FileResource;
  13. class IcuDatFileLoaderTest 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. /**
  25. * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
  26. */
  27. public function testLoadInvalidResource()
  28. {
  29. $loader = new IcuDatFileLoader();
  30. $loader->load(__DIR__.'/../fixtures/resourcebundle/corrupted/resources', 'es', 'domain2');
  31. }
  32. public function testDatEnglishLoad()
  33. {
  34. // bundled resource is build using pkgdata command which at least in ICU 4.2 comes in extremely! buggy form
  35. // you must specify an temporary build directory which is not the same as current directory and
  36. // MUST reside on the same partition. pkgdata -p resources -T /srv -d.packagelist.txt
  37. $loader = new IcuDatFileLoader();
  38. $resource = __DIR__.'/../fixtures/resourcebundle/dat/resources';
  39. $catalogue = $loader->load($resource, 'en', 'domain1');
  40. $this->assertEquals(array('symfony' => 'Symfony 2 is great'), $catalogue->all('domain1'));
  41. $this->assertEquals('en', $catalogue->getLocale());
  42. $this->assertEquals(array(new FileResource($resource.'.dat')), $catalogue->getResources());
  43. }
  44. public function testDatFrenchLoad()
  45. {
  46. $loader = new IcuDatFileLoader();
  47. $resource = __DIR__.'/../fixtures/resourcebundle/dat/resources';
  48. $catalogue = $loader->load($resource, 'fr', 'domain1');
  49. $this->assertEquals(array('symfony' => 'Symfony 2 est génial'), $catalogue->all('domain1'));
  50. $this->assertEquals('fr', $catalogue->getLocale());
  51. $this->assertEquals(array(new FileResource($resource.'.dat')), $catalogue->getResources());
  52. }
  53. /**
  54. * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
  55. */
  56. public function testLoadNonExistingResource()
  57. {
  58. $loader = new IcuDatFileLoader();
  59. $loader->load(__DIR__.'/../fixtures/non-existing.txt', 'en', 'domain1');
  60. }
  61. }