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\IcuDatFileLoader
;
15 use Symfony\Component\Config\
Resource\FileResource
;
17 class IcuDatFileLoaderTest
extends LocalizedTestCase
19 protected function setUp()
21 if (!class_exists('Symfony\Component\Config\Loader\Loader')) {
22 $this->markTestSkipped('The "Config" component is not available');
25 if (!extension_loaded('intl')) {
26 $this->markTestSkipped('This test requires intl extension to work.');
31 * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
33 public function testLoadInvalidResource()
35 $loader = new IcuDatFileLoader();
36 $loader->load(__DIR__
.'/../fixtures/resourcebundle/corrupted/resources', 'es', 'domain2');
39 public function testDatEnglishLoad()
41 // bundled resource is build using pkgdata command which at least in ICU 4.2 comes in extremely! buggy form
42 // you must specify an temporary build directory which is not the same as current directory and
43 // MUST reside on the same partition. pkgdata -p resources -T /srv -d.packagelist.txt
44 $loader = new IcuDatFileLoader();
45 $resource = __DIR__
.'/../fixtures/resourcebundle/dat/resources';
46 $catalogue = $loader->load($resource, 'en', 'domain1');
48 $this->assertEquals(array('symfony' => 'Symfony 2 is great'), $catalogue->all('domain1'));
49 $this->assertEquals('en', $catalogue->getLocale());
50 $this->assertEquals(array(new FileResource($resource.'.dat')), $catalogue->getResources());
53 public function testDatFrenchLoad()
55 $loader = new IcuDatFileLoader();
56 $resource = __DIR__
.'/../fixtures/resourcebundle/dat/resources';
57 $catalogue = $loader->load($resource, 'fr', 'domain1');
59 $this->assertEquals(array('symfony' => 'Symfony 2 est génial'), $catalogue->all('domain1'));
60 $this->assertEquals('fr', $catalogue->getLocale());
61 $this->assertEquals(array(new FileResource($resource.'.dat')), $catalogue->getResources());
65 * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
67 public function testLoadNonExistingResource()
69 $loader = new IcuDatFileLoader();
70 $loader->load(__DIR__
.'/../fixtures/non-existing.txt', 'en', 'domain1');