mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 20:16:45 +00:00
Autoescape test addition; collision fix in Array Loader.
This commit is contained in:
committed by
Fabien Potencier
parent
c622995d6d
commit
da82b41ac2
@@ -80,7 +80,7 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
||||
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
|
||||
}
|
||||
|
||||
return $this->templates[$name];
|
||||
return $name.':'.$this->templates[$name];
|
||||
}
|
||||
|
||||
public function isFresh($name, $time)
|
||||
|
||||
@@ -22,7 +22,7 @@ class Twig_Profiler_Dumper_Blackfire
|
||||
$this->dumpProfile('main()', $profile, $data);
|
||||
$this->dumpChildren('main()', $profile, $data);
|
||||
|
||||
$start = microtime(true);
|
||||
$start = sprintf('%f', microtime(true));
|
||||
$str = <<<EOF
|
||||
file-format: BlackfireProbe
|
||||
cost-dimensions: wt mu pmu
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
"name" autoescape strategy
|
||||
--TEMPLATE--
|
||||
{{ br -}}
|
||||
{{ include('index.js.twig') -}}
|
||||
{{ include('index.html.twig') -}}
|
||||
{{ include('index.txt.twig') -}}
|
||||
--TEMPLATE(index.js.twig)--
|
||||
{{ br -}}
|
||||
--TEMPLATE(index.html.twig)--
|
||||
{{ br -}}
|
||||
--TEMPLATE(index.txt.twig)--
|
||||
@@ -14,5 +17,6 @@ return array('br' => '<br />')
|
||||
return array('autoescape' => 'name')
|
||||
--EXPECT--
|
||||
<br />
|
||||
\x3Cbr\x20\x2F\x3E
|
||||
<br />
|
||||
<br />
|
||||
|
||||
@@ -46,7 +46,29 @@ class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$loader = new Twig_Loader_Array(array('foo' => 'bar'));
|
||||
|
||||
$this->assertEquals('bar', $loader->getCacheKey('foo'));
|
||||
$this->assertEquals('foo:bar', $loader->getCacheKey('foo'));
|
||||
}
|
||||
|
||||
public function testGetCacheKeyWhenTemplateHasDuplicateContent()
|
||||
{
|
||||
$loader = new Twig_Loader_Array(array(
|
||||
'foo' => 'bar',
|
||||
'baz' => 'bar',
|
||||
));
|
||||
|
||||
$this->assertEquals('foo:bar', $loader->getCacheKey('foo'));
|
||||
$this->assertEquals('baz:bar', $loader->getCacheKey('baz'));
|
||||
}
|
||||
|
||||
public function testGetCacheKeyIsProtectedFromEdgeCollisions()
|
||||
{
|
||||
$loader = new Twig_Loader_Array(array(
|
||||
'foo__' => 'bar',
|
||||
'foo' => '__bar',
|
||||
));
|
||||
|
||||
$this->assertEquals('foo__:bar', $loader->getCacheKey('foo__'));
|
||||
$this->assertEquals('foo:__bar', $loader->getCacheKey('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +113,7 @@ class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase
|
||||
$loader->getCacheKey($name);
|
||||
$loader->getSourceContext($name);
|
||||
$loader->isFresh($name, time());
|
||||
$loader->setTemplate($name, 'foobar');
|
||||
$loader->setTemplate($name, 'foo:bar');
|
||||
|
||||
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
|
||||
// can be executed without crashing PHP
|
||||
|
||||
@@ -74,8 +74,8 @@ class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase
|
||||
new Twig_Loader_Array(array('foo' => 'foobar', 'bar' => 'foo')),
|
||||
));
|
||||
|
||||
$this->assertEquals('bar', $loader->getCacheKey('foo'));
|
||||
$this->assertEquals('foo', $loader->getCacheKey('bar'));
|
||||
$this->assertEquals('foo:bar', $loader->getCacheKey('foo'));
|
||||
$this->assertEquals('bar:foo', $loader->getCacheKey('bar'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user