MoFileLoaderTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. protected function setUp()
  16. {
  17. if (!class_exists('Symfony\Component\Config\Loader\Loader')) {
  18. $this->markTestSkipped('The "Config" component is not available');
  19. }
  20. }
  21. public function testLoad()
  22. {
  23. $loader = new MoFileLoader();
  24. $resource = __DIR__.'/../fixtures/resources.mo';
  25. $catalogue = $loader->load($resource, 'en', 'domain1');
  26. $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
  27. $this->assertEquals('en', $catalogue->getLocale());
  28. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  29. }
  30. public function testLoadPlurals()
  31. {
  32. $loader = new MoFileLoader();
  33. $resource = __DIR__.'/../fixtures/plurals.mo';
  34. $catalogue = $loader->load($resource, 'en', 'domain1');
  35. $this->assertEquals(array('foo' => 'bar', 'foos' => '{0} bar|{1} bars'), $catalogue->all('domain1'));
  36. $this->assertEquals('en', $catalogue->getLocale());
  37. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  38. }
  39. /**
  40. * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
  41. */
  42. public function testLoadNonExistingResource()
  43. {
  44. $loader = new MoFileLoader();
  45. $resource = __DIR__.'/../fixtures/non-existing.mo';
  46. $loader->load($resource, 'en', 'domain1');
  47. }
  48. /**
  49. * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
  50. */
  51. public function testLoadInvalidResource()
  52. {
  53. $loader = new MoFileLoader();
  54. $resource = __DIR__.'/../fixtures/empty.mo';
  55. $loader->load($resource, 'en', 'domain1');
  56. }
  57. }