CsvFileLoaderTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. 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 CsvFileLoader();
  24. $resource = __DIR__.'/../fixtures/resources.csv';
  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 CsvFileLoader();
  33. $resource = __DIR__.'/../fixtures/empty.csv';
  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 CsvFileLoader();
  45. $resource = __DIR__.'/../fixtures/not-exists.csv';
  46. $loader->load($resource, 'en', 'domain1');
  47. }
  48. /**
  49. * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
  50. */
  51. public function testLoadNonLocalResource()
  52. {
  53. $loader = new CsvFileLoader();
  54. $resource = 'http://example.com/resources.csv';
  55. $loader->load($resource, 'en', 'domain1');
  56. }
  57. }