ArrayTest.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_ArrayTest extends PHPUnit_Framework_TestCase
  11. {
  12. public function testGetSource()
  13. {
  14. $loader = new Twig_Loader_Array(array('foo' => 'bar'));
  15. $this->assertEquals('bar', $loader->getSource('foo'));
  16. }
  17. /**
  18. * @expectedException Twig_Error_Loader
  19. */
  20. public function testGetSourceWhenTemplateDoesNotExist()
  21. {
  22. $loader = new Twig_Loader_Array(array());
  23. $loader->getSource('foo');
  24. }
  25. public function testGetCacheKey()
  26. {
  27. $loader = new Twig_Loader_Array(array('foo' => 'bar'));
  28. $this->assertEquals('bar', $loader->getCacheKey('foo'));
  29. }
  30. /**
  31. * @expectedException Twig_Error_Loader
  32. */
  33. public function testGetCacheKeyWhenTemplateDoesNotExist()
  34. {
  35. $loader = new Twig_Loader_Array(array());
  36. $loader->getCacheKey('foo');
  37. }
  38. public function testSetTemplate()
  39. {
  40. $loader = new Twig_Loader_Array(array());
  41. $loader->setTemplate('foo', 'bar');
  42. $this->assertEquals('bar', $loader->getSource('foo'));
  43. }
  44. public function testIsFresh()
  45. {
  46. $loader = new Twig_Loader_Array(array('foo' => 'bar'));
  47. $this->assertTrue($loader->isFresh('foo', time()));
  48. }
  49. /**
  50. * @expectedException Twig_Error_Loader
  51. */
  52. public function testIsFreshWhenTemplateDoesNotExist()
  53. {
  54. $loader = new Twig_Loader_Array(array());
  55. $loader->isFresh('foo', time());
  56. }
  57. public function testTemplateReference()
  58. {
  59. $name = new Twig_Test_Loader_TemplateReference('foo');
  60. $loader = new Twig_Loader_Array(array('foo' => 'bar'));
  61. $loader->getCacheKey($name);
  62. $loader->getSource($name);
  63. $loader->isFresh($name, time());
  64. $loader->setTemplate($name, 'foobar');
  65. }
  66. }
  67. class Twig_Test_Loader_TemplateReference
  68. {
  69. private $name;
  70. public function __construct($name)
  71. {
  72. $this->name = $name;
  73. }
  74. public function __toString()
  75. {
  76. return $this->name;
  77. }
  78. }