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\MoFileLoader
;
15 use Symfony\Component\Config\
Resource\FileResource
;
17 class MoFileLoaderTest
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 MoFileLoader();
29 $resource = __DIR__
.'/../fixtures/resources.mo';
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 MoFileLoader();
40 $resource = __DIR__
.'/../fixtures/plurals.mo';
41 $catalogue = $loader->load($resource, 'en', 'domain1');
43 $this->assertEquals(array('foo' => 'bar', 'foos' => '{0} bar|{1} bars'), $catalogue->all('domain1'));
44 $this->assertEquals('en', $catalogue->getLocale());
45 $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
49 * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
51 public function testLoadNonExistingResource()
53 $loader = new MoFileLoader();
54 $resource = __DIR__
.'/../fixtures/non-existing.mo';
55 $loader->load($resource, 'en', 'domain1');
59 * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
61 public function testLoadInvalidResource()
63 $loader = new MoFileLoader();
64 $resource = __DIR__
.'/../fixtures/empty.mo';
65 $loader->load($resource, 'en', 'domain1');