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\XliffFileLoader
;
15 use Symfony\Component\Config\
Resource\FileResource
;
17 class XliffFileLoaderTest
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 XliffFileLoader();
29 $resource = __DIR__
.'/../fixtures/resources.xlf';
30 $catalogue = $loader->load($resource, 'en', 'domain1');
32 $this->assertEquals('en', $catalogue->getLocale());
33 $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
36 public function testLoadWithResname()
38 $loader = new XliffFileLoader();
39 $catalogue = $loader->load(__DIR__
.'/../fixtures/resname.xlf', 'en', 'domain1');
41 $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo'), $catalogue->all('domain1'));
44 public function testIncompleteResource()
46 $loader = new XliffFileLoader();
47 $catalogue = $loader->load(__DIR__
.'/../fixtures/resources.xlf', 'en', 'domain1');
49 $this->assertEquals(array('foo' => 'bar', 'key' => '', 'test' => 'with'), $catalogue->all('domain1'));
50 $this->assertFalse($catalogue->has('extra', 'domain1'));
53 public function testEncoding()
55 if (!function_exists('iconv') && !function_exists('mb_convert_encoding')) {
56 $this->markTestSkipped('The iconv and mbstring extensions are not available.');
59 $loader = new XliffFileLoader();
60 $catalogue = $loader->load(__DIR__
.'/../fixtures/encoding.xlf', 'en', 'domain1');
62 $this->assertEquals(utf8_decode('föö'), $catalogue->get('bar', 'domain1'));
63 $this->assertEquals(utf8_decode('bär'), $catalogue->get('foo', 'domain1'));
67 * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
69 public function testLoadInvalidResource()
71 $loader = new XliffFileLoader();
72 $loader->load(__DIR__
.'/../fixtures/resources.php', 'en', 'domain1');
76 * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
78 public function testLoadResourceDoesNotValidate()
80 $loader = new XliffFileLoader();
81 $loader->load(__DIR__
.'/../fixtures/non-valid.xlf', 'en', 'domain1');
85 * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
87 public function testLoadNonExistingResource()
89 $loader = new XliffFileLoader();
90 $resource = __DIR__
.'/../fixtures/non-existing.xlf';
91 $loader->load($resource, 'en', 'domain1');
95 * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
97 public function testLoadThrowsAnExceptionIfFileNotLocal()
99 $loader = new XliffFileLoader();
100 $resource = 'http://example.com/resources.xlf';
101 $loader->load($resource, 'en', 'domain1');
105 * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
106 * @expectedExceptionMessage Document types are not allowed.
108 public function testDocTypeIsNotAllowed()
110 $loader = new XliffFileLoader();
111 $loader->load(__DIR__
.'/../fixtures/withdoctype.xlf', 'en', 'domain1');