MoFileLoaderTest.php 2.4 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\MoFileLoader;
  12. use Symfony\Component\Config\Resource\FileResource;
  13. class MoFileLoaderTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testLoad()
  16. {
  17. $loader = new MoFileLoader();
  18. $resource = __DIR__.'/../fixtures/resources.mo';
  19. $catalogue = $loader->load($resource, 'en', 'domain1');
  20. $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
  21. $this->assertEquals('en', $catalogue->getLocale());
  22. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  23. }
  24. public function testLoadPlurals()
  25. {
  26. $loader = new MoFileLoader();
  27. $resource = __DIR__.'/../fixtures/plurals.mo';
  28. $catalogue = $loader->load($resource, 'en', 'domain1');
  29. $this->assertEquals(array('foo' => 'bar', 'foos' => '{0} bar|{1} bars'), $catalogue->all('domain1'));
  30. $this->assertEquals('en', $catalogue->getLocale());
  31. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  32. }
  33. /**
  34. * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
  35. */
  36. public function testLoadNonExistingResource()
  37. {
  38. $loader = new MoFileLoader();
  39. $resource = __DIR__.'/../fixtures/non-existing.mo';
  40. $loader->load($resource, 'en', 'domain1');
  41. }
  42. /**
  43. * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
  44. */
  45. public function testLoadInvalidResource()
  46. {
  47. $loader = new MoFileLoader();
  48. $resource = __DIR__.'/../fixtures/empty.mo';
  49. $loader->load($resource, 'en', 'domain1');
  50. }
  51. public function testLoadEmptyTranslation()
  52. {
  53. $loader = new MoFileLoader();
  54. $resource = __DIR__.'/../fixtures/empty-translation.mo';
  55. $catalogue = $loader->load($resource, 'en', 'message');
  56. $this->assertEquals(array(), $catalogue->all('message'));
  57. $this->assertEquals('en', $catalogue->getLocale());
  58. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  59. }
  60. }