No Description

CsvFileLoaderTest.php 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\CsvFileLoader;
  12. use Symfony\Component\Config\Resource\FileResource;
  13. class CsvFileLoaderTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testLoad()
  16. {
  17. $loader = new CsvFileLoader();
  18. $resource = __DIR__.'/../fixtures/resources.csv';
  19. $catalogue = $loader->load($resource, 'en', 'domain1');
  20. $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
  21. $this->assertEquals('en', $catalogue->getLocale());
  22. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  23. }
  24. public function testLoadDoesNothingIfEmpty()
  25. {
  26. $loader = new CsvFileLoader();
  27. $resource = __DIR__.'/../fixtures/empty.csv';
  28. $catalogue = $loader->load($resource, 'en', 'domain1');
  29. $this->assertEquals(array(), $catalogue->all('domain1'));
  30. $this->assertEquals('en', $catalogue->getLocale());
  31. $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
  32. }
  33. /**
  34. * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
  35. */
  36. public function testLoadNonExistingResource()
  37. {
  38. $loader = new CsvFileLoader();
  39. $resource = __DIR__.'/../fixtures/not-exists.csv';
  40. $loader->load($resource, 'en', 'domain1');
  41. }
  42. /**
  43. * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
  44. */
  45. public function testLoadNonLocalResource()
  46. {
  47. $loader = new CsvFileLoader();
  48. $resource = 'http://example.com/resources.csv';
  49. $loader->load($resource, 'en', 'domain1');
  50. }
  51. }