Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / translation / Tests / Loader / JsonFileLoaderTest.php
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 PHPUnit\Framework\TestCase;
15 use Symfony\Component\Translation\Loader\JsonFileLoader;
16 use Symfony\Component\Config\Resource\FileResource;
17
18 class JsonFileLoaderTest extends TestCase
19 {
20     public function testLoad()
21     {
22         $loader = new JsonFileLoader();
23         $resource = __DIR__.'/../fixtures/resources.json';
24         $catalogue = $loader->load($resource, 'en', 'domain1');
25
26         $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
27         $this->assertEquals('en', $catalogue->getLocale());
28         $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
29     }
30
31     public function testLoadDoesNothingIfEmpty()
32     {
33         $loader = new JsonFileLoader();
34         $resource = __DIR__.'/../fixtures/empty.json';
35         $catalogue = $loader->load($resource, 'en', 'domain1');
36
37         $this->assertEquals(array(), $catalogue->all('domain1'));
38         $this->assertEquals('en', $catalogue->getLocale());
39         $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
40     }
41
42     /**
43      * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
44      */
45     public function testLoadNonExistingResource()
46     {
47         $loader = new JsonFileLoader();
48         $resource = __DIR__.'/../fixtures/non-existing.json';
49         $loader->load($resource, 'en', 'domain1');
50     }
51
52     /**
53      * @expectedException           \Symfony\Component\Translation\Exception\InvalidResourceException
54      * @expectedExceptionMessage    Error parsing JSON - Syntax error, malformed JSON
55      */
56     public function testParseException()
57     {
58         $loader = new JsonFileLoader();
59         $resource = __DIR__.'/../fixtures/malformed.json';
60         $loader->load($resource, 'en', 'domain1');
61     }
62 }