* 1.2.0
+ * added Twig_Loader_Array::setTemplate()
* added an optimization for the set tag when used to capture a large chunk of static text
* changed name regex to match PHP one "[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*" (works for blocks, tags, functions, filters, and macros)
* removed the possibility to use the "extends" tag from a block
}
/**
+ * Adds or overrides a template.
+ *
+ * @param string $name The template name
+ * @param string $template The template source
+ */
+ public function setTemplate($name, $template)
+ {
+ $this->templates[$name] = $template;
+ }
+
+ /**
* Gets the source code of a template, given its name.
*
* @param string $name The name of the template to load
--- /dev/null
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase
+{
+ public function testGetSource()
+ {
+ $loader = new Twig_Loader_Array(array('foo' => 'bar'));
+
+ $this->assertEquals('bar', $loader->getSource('foo'));
+ }
+
+ /**
+ * @expectedException Twig_Error_Loader
+ */
+ public function testGetSourceWhenTemplateDoesNotExist()
+ {
+ $loader = new Twig_Loader_Array(array());
+
+ $loader->getSource('foo');
+ }
+
+ public function testGetCacheKey()
+ {
+ $loader = new Twig_Loader_Array(array('foo' => 'bar'));
+
+ $this->assertEquals('bar', $loader->getCacheKey('foo'));
+ }
+
+ /**
+ * @expectedException Twig_Error_Loader
+ */
+ public function testGetCacheKeyWhenTemplateDoesNotExist()
+ {
+ $loader = new Twig_Loader_Array(array());
+
+ $loader->getCacheKey('foo');
+ }
+
+ public function testSetTemplate()
+ {
+ $loader = new Twig_Loader_Array(array());
+ $loader->setTemplate('foo', 'bar');
+
+ $this->assertEquals('bar', $loader->getSource('foo'));
+ }
+
+ public function testIsFresh()
+ {
+ $loader = new Twig_Loader_Array(array('foo' => 'bar'));
+ $this->assertTrue($loader->isFresh('foo', time()));
+ }
+}