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