]>
Commit | Line | Data |
---|---|---|
4f5b44bd NL |
1 | <?php |
2 | ||
3 | /* | |
4 | * This file is part of the Symfony package. | |
5 | * | |
6 | * (c) Fabien Potencier <fabien@symfony.com> | |
7 | * | |
8 | * For the full copyright and license information, please view the LICENSE | |
9 | * file that was distributed with this source code. | |
10 | */ | |
11 | ||
12 | namespace Symfony\Component\Translation\Tests\Loader; | |
13 | ||
14 | use Symfony\Component\Translation\Loader\IcuDatFileLoader; | |
15 | use Symfony\Component\Config\Resource\FileResource; | |
16 | ||
17 | class IcuDatFileLoaderTest extends LocalizedTestCase | |
18 | { | |
19 | protected function setUp() | |
20 | { | |
21 | if (!class_exists('Symfony\Component\Config\Loader\Loader')) { | |
22 | $this->markTestSkipped('The "Config" component is not available'); | |
23 | } | |
24 | ||
25 | if (!extension_loaded('intl')) { | |
26 | $this->markTestSkipped('This test requires intl extension to work.'); | |
27 | } | |
28 | } | |
29 | ||
30 | /** | |
31 | * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException | |
32 | */ | |
33 | public function testLoadInvalidResource() | |
34 | { | |
35 | $loader = new IcuDatFileLoader(); | |
36 | $loader->load(__DIR__.'/../fixtures/resourcebundle/corrupted/resources', 'es', 'domain2'); | |
37 | } | |
38 | ||
39 | public function testDatEnglishLoad() | |
40 | { | |
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'); | |
47 | ||
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()); | |
51 | } | |
52 | ||
53 | public function testDatFrenchLoad() | |
54 | { | |
55 | $loader = new IcuDatFileLoader(); | |
56 | $resource = __DIR__.'/../fixtures/resourcebundle/dat/resources'; | |
57 | $catalogue = $loader->load($resource, 'fr', 'domain1'); | |
58 | ||
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()); | |
62 | } | |
63 | ||
64 | /** | |
65 | * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException | |
66 | */ | |
67 | public function testLoadNonExistingResource() | |
68 | { | |
69 | $loader = new IcuDatFileLoader(); | |
70 | $loader->load(__DIR__.'/../fixtures/non-existing.txt', 'en', 'domain1'); | |
71 | } | |
72 | } |