No Description

IcuDatFileLoaderTest.php 2.5KB

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