IcuDatFileLoaderTest.php 2.3KB

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