No Description

JsonFileLoaderTest.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Translation\Tests\Loader;
  11. use Symfony\Component\Translation\Loader\JsonFileLoader;
  12. use Symfony\Component\Config\Resource\FileResource;
  13. class JsonFileLoaderTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected function setUp()
  16. {
  17. if (!class_exists('Symfony\Component\Config\Loader\Loader')) {
  18. $this->markTestSkipped('The "Config" component is not available');
  19. }
  20. }
  21. public function testLoad()
  22. {
  23. $loader = new JsonFileLoader();
  24. $resource = __DIR__.'/../fixtures/resources.json';
  25. $catalogue = $loader->load($resource, 'en', 'domain1');
  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. public function testLoadDoesNothingIfEmpty()
  31. {
  32. $loader = new JsonFileLoader();
  33. $resource = __DIR__.'/../fixtures/empty.json';
  34. $catalogue = $loader->load($resource, 'en', 'domain1');
  35. $this->assertEquals(array(), $catalogue->all('domain1'));
  36. $this->assertEquals('en', $catalogue->getLocale());
  37. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  38. }
  39. /**
  40. * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
  41. */
  42. public function testLoadNonExistingResource()
  43. {
  44. $loader = new JsonFileLoader();
  45. $resource = __DIR__.'/../fixtures/non-existing.json';
  46. $loader->load($resource, 'en', 'domain1');
  47. }
  48. /**
  49. * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
  50. * @expectedExceptionMessage Error parsing JSON - Syntax error, malformed JSON
  51. */
  52. public function testParseException()
  53. {
  54. $loader = new JsonFileLoader();
  55. $resource = __DIR__.'/../fixtures/malformed.json';
  56. $loader->load($resource, 'en', 'domain1');
  57. }
  58. }