PoFileLoaderTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\PoFileLoader;
  12. use Symfony\Component\Config\Resource\FileResource;
  13. class PoFileLoaderTest 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 PoFileLoader();
  24. $resource = __DIR__.'/../fixtures/resources.po';
  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 PoFileLoader();
  33. $resource = __DIR__.'/../fixtures/plurals.po';
  34. $catalogue = $loader->load($resource, 'en', 'domain1');
  35. $this->assertEquals(array('foo' => 'bar', 'foos' => 'bar|bars'), $catalogue->all('domain1'));
  36. $this->assertEquals('en', $catalogue->getLocale());
  37. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  38. }
  39. public function testLoadDoesNothingIfEmpty()
  40. {
  41. $loader = new PoFileLoader();
  42. $resource = __DIR__.'/../fixtures/empty.po';
  43. $catalogue = $loader->load($resource, 'en', 'domain1');
  44. $this->assertEquals(array(), $catalogue->all('domain1'));
  45. $this->assertEquals('en', $catalogue->getLocale());
  46. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  47. }
  48. /**
  49. * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
  50. */
  51. public function testLoadNonExistingResource()
  52. {
  53. $loader = new PoFileLoader();
  54. $resource = __DIR__.'/../fixtures/non-existing.po';
  55. $loader->load($resource, 'en', 'domain1');
  56. }
  57. public function testLoadEmptyTranslation()
  58. {
  59. $loader = new PoFileLoader();
  60. $resource = __DIR__.'/../fixtures/empty-translation.po';
  61. $catalogue = $loader->load($resource, 'en', 'domain1');
  62. $this->assertEquals(array('foo' => ''), $catalogue->all('domain1'));
  63. $this->assertEquals('en', $catalogue->getLocale());
  64. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  65. }
  66. }