ChainTest.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase
  11. {
  12. public function testGetSource()
  13. {
  14. $loader = new Twig_Loader_Chain(array(
  15. new Twig_Loader_Array(array('foo' => 'bar')),
  16. new Twig_Loader_Array(array('foo' => 'foobar', 'bar' => 'foo')),
  17. ));
  18. $this->assertEquals('bar', $loader->getSource('foo'));
  19. $this->assertEquals('foo', $loader->getSource('bar'));
  20. }
  21. /**
  22. * @expectedException Twig_Error_Loader
  23. */
  24. public function testGetSourceWhenTemplateDoesNotExist()
  25. {
  26. $loader = new Twig_Loader_Chain(array());
  27. $loader->getSource('foo');
  28. }
  29. public function testGetCacheKey()
  30. {
  31. $loader = new Twig_Loader_Chain(array(
  32. new Twig_Loader_Array(array('foo' => 'bar')),
  33. new Twig_Loader_Array(array('foo' => 'foobar', 'bar' => 'foo')),
  34. ));
  35. $this->assertEquals('bar', $loader->getCacheKey('foo'));
  36. $this->assertEquals('foo', $loader->getCacheKey('bar'));
  37. }
  38. /**
  39. * @expectedException Twig_Error_Loader
  40. */
  41. public function testGetCacheKeyWhenTemplateDoesNotExist()
  42. {
  43. $loader = new Twig_Loader_Chain(array());
  44. $loader->getCacheKey('foo');
  45. }
  46. public function testAddLoader()
  47. {
  48. $loader = new Twig_Loader_Chain();
  49. $loader->addLoader(new Twig_Loader_Array(array('foo' => 'bar')));
  50. $this->assertEquals('bar', $loader->getSource('foo'));
  51. }
  52. }