mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 10:56:38 +00:00
added Twig_LoaderArray::setTemplate()
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 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
|
||||
|
||||
@@ -39,6 +39,17 @@ class Twig_Loader_Array implements Twig_LoaderInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?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()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user