4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\Tests\Loader
;
14 use Symfony\Component\Translation\Loader\PoFileLoader
;
15 use Symfony\Component\Config\
Resource\FileResource
;
17 class PoFileLoaderTest
extends \PHPUnit_Framework_TestCase
19 protected function setUp()
21 if (!class_exists('Symfony\Component\Config\Loader\Loader')) {
22 $this->markTestSkipped('The "Config" component is not available');
26 public function testLoad()
28 $loader = new PoFileLoader();
29 $resource = __DIR__
.'/../fixtures/resources.po';
30 $catalogue = $loader->load($resource, 'en', 'domain1');
32 $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
33 $this->assertEquals('en', $catalogue->getLocale());
34 $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
37 public function testLoadPlurals()
39 $loader = new PoFileLoader();
40 $resource = __DIR__
.'/../fixtures/plurals.po';
41 $catalogue = $loader->load($resource, 'en', 'domain1');
43 $this->assertEquals(array('foo' => 'bar', 'foos' => 'bar|bars'), $catalogue->all('domain1'));
44 $this->assertEquals('en', $catalogue->getLocale());
45 $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
48 public function testLoadDoesNothingIfEmpty()
50 $loader = new PoFileLoader();
51 $resource = __DIR__
.'/../fixtures/empty.po';
52 $catalogue = $loader->load($resource, 'en', 'domain1');
54 $this->assertEquals(array(), $catalogue->all('domain1'));
55 $this->assertEquals('en', $catalogue->getLocale());
56 $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
60 * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
62 public function testLoadNonExistingResource()
64 $loader = new PoFileLoader();
65 $resource = __DIR__
.'/../fixtures/non-existing.po';
66 $loader->load($resource, 'en', 'domain1');
69 public function testLoadEmptyTranslation()
71 $loader = new PoFileLoader();
72 $resource = __DIR__
.'/../fixtures/empty-translation.po';
73 $catalogue = $loader->load($resource, 'en', 'domain1');
75 $this->assertEquals(array('foo' => ''), $catalogue->all('domain1'));
76 $this->assertEquals('en', $catalogue->getLocale());
77 $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());