bug #20271 Changes related to Twig 1.27 (fabpot)
This PR was merged into the 2.7 branch. Discussion ---------- Changes related to Twig 1.27 | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Commits -------317d46f
[TwigBundle] fixed usage of getSource in testsb9a4586
[TwigBridge] fixed Twig_Source required argument
This commit is contained in:
commit
122ac67823
@ -23,7 +23,7 @@ class RoutingExtensionTest extends \PHPUnit_Framework_TestCase
|
|||||||
$twig = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
|
$twig = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
|
||||||
$twig->addExtension(new RoutingExtension($this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface')));
|
$twig->addExtension(new RoutingExtension($this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface')));
|
||||||
|
|
||||||
$nodes = $twig->parse($twig->tokenize(new \Twig_Source($template)));
|
$nodes = $twig->parse($twig->tokenize(new \Twig_Source($template, '')));
|
||||||
|
|
||||||
$this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter);
|
$this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ class TwigNodeProvider
|
|||||||
new \Twig_Node_Expression_Array(array(), 0),
|
new \Twig_Node_Expression_Array(array(), 0),
|
||||||
new \Twig_Node_Expression_Array(array(), 0),
|
new \Twig_Node_Expression_Array(array(), 0),
|
||||||
null,
|
null,
|
||||||
new \Twig_Source('')
|
new \Twig_Source('', '')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class FormThemeTokenParserTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
|
$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
|
||||||
$env->addTokenParser(new FormThemeTokenParser());
|
$env->addTokenParser(new FormThemeTokenParser());
|
||||||
$stream = $env->tokenize(new \Twig_Source($source));
|
$stream = $env->tokenize(new \Twig_Source($source, ''));
|
||||||
$parser = new \Twig_Parser($env);
|
$parser = new \Twig_Parser($env);
|
||||||
|
|
||||||
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
|
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
|
||||||
|
@ -85,7 +85,7 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface
|
|||||||
$visitor = $this->twig->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->getTranslationNodeVisitor();
|
$visitor = $this->twig->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->getTranslationNodeVisitor();
|
||||||
$visitor->enable();
|
$visitor->enable();
|
||||||
|
|
||||||
$this->twig->parse($this->twig->tokenize(new \Twig_Source($template)));
|
$this->twig->parse($this->twig->tokenize(new \Twig_Source($template, '')));
|
||||||
|
|
||||||
foreach ($visitor->getMessages() as $message) {
|
foreach ($visitor->getMessages() as $message) {
|
||||||
$catalogue->set(trim($message[0]), $this->prefix.trim($message[0]), $message[1] ?: $this->defaultDomain);
|
$catalogue->set(trim($message[0]), $this->prefix.trim($message[0]), $message[1] ?: $this->defaultDomain);
|
||||||
|
@ -17,7 +17,7 @@ use Symfony\Bundle\TwigBundle\Tests\TestCase;
|
|||||||
|
|
||||||
class FilesystemLoaderTest extends TestCase
|
class FilesystemLoaderTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testGetSource()
|
public function testGetSourceContext()
|
||||||
{
|
{
|
||||||
$parser = $this->getMock('Symfony\Component\Templating\TemplateNameParserInterface');
|
$parser = $this->getMock('Symfony\Component\Templating\TemplateNameParserInterface');
|
||||||
$locator = $this->getMock('Symfony\Component\Config\FileLocatorInterface');
|
$locator = $this->getMock('Symfony\Component\Config\FileLocatorInterface');
|
||||||
@ -30,10 +30,10 @@ class FilesystemLoaderTest extends TestCase
|
|||||||
$loader->addPath(__DIR__.'/../DependencyInjection/Fixtures/Resources/views', 'namespace');
|
$loader->addPath(__DIR__.'/../DependencyInjection/Fixtures/Resources/views', 'namespace');
|
||||||
|
|
||||||
// Twig-style
|
// Twig-style
|
||||||
$this->assertEquals("This is a layout\n", $loader->getSource('@namespace/layout.html.twig'));
|
$this->assertEquals("This is a layout\n", $loader->getSourceContext('@namespace/layout.html.twig')->getCode());
|
||||||
|
|
||||||
// Symfony-style
|
// Symfony-style
|
||||||
$this->assertEquals("This is a layout\n", $loader->getSource('TwigBundle::layout.html.twig'));
|
$this->assertEquals("This is a layout\n", $loader->getSourceContext('TwigBundle::layout.html.twig')->getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExists()
|
public function testExists()
|
||||||
|
@ -27,7 +27,7 @@ class LegacyRenderTokenParserTest extends TestCase
|
|||||||
{
|
{
|
||||||
$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
|
$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
|
||||||
$env->addTokenParser(new RenderTokenParser());
|
$env->addTokenParser(new RenderTokenParser());
|
||||||
$stream = $env->tokenize(new \Twig_Source($source));
|
$stream = $env->tokenize(new \Twig_Source($source, ''));
|
||||||
$parser = new \Twig_Parser($env);
|
$parser = new \Twig_Parser($env);
|
||||||
|
|
||||||
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
|
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
|
||||||
|
@ -126,7 +126,11 @@ class TemplateManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$loader->getSource($template);
|
if ($loader instanceof \Twig_SourceContextLoaderInterface) {
|
||||||
|
$loader->getSourceContext($template);
|
||||||
|
} else {
|
||||||
|
$loader->getSource($template);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (\Twig_Error_Loader $e) {
|
} catch (\Twig_Error_Loader $e) {
|
||||||
|
@ -31,11 +31,6 @@ class TemplateManagerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
protected $profiler;
|
protected $profiler;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
|
||||||
*/
|
|
||||||
protected $profile;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager
|
* @var \Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager
|
||||||
*/
|
*/
|
||||||
@ -129,11 +124,7 @@ class TemplateManagerTest extends TestCase
|
|||||||
|
|
||||||
protected function mockProfile()
|
protected function mockProfile()
|
||||||
{
|
{
|
||||||
$this->profile = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profile')
|
return $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profile')->disableOriginalConstructor()->getMock();
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
return $this->profile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function mockTwigEnvironment()
|
protected function mockTwigEnvironment()
|
||||||
@ -144,9 +135,12 @@ class TemplateManagerTest extends TestCase
|
|||||||
->method('loadTemplate')
|
->method('loadTemplate')
|
||||||
->will($this->returnValue('loadedTemplate'));
|
->will($this->returnValue('loadedTemplate'));
|
||||||
|
|
||||||
$this->twigEnvironment->expects($this->any())
|
if (interface_exists('\Twig_SourceContextLoaderInterface')) {
|
||||||
->method('getLoader')
|
$loader = $this->getMock('\Twig_SourceContextLoaderInterface');
|
||||||
->will($this->returnValue($this->getMock('\Twig_LoaderInterface')));
|
} else {
|
||||||
|
$loader = $this->getMock('\Twig_LoaderInterface');
|
||||||
|
}
|
||||||
|
$this->twigEnvironment->expects($this->any())->method('getLoader')->will($this->returnValue($loader));
|
||||||
|
|
||||||
return $this->twigEnvironment;
|
return $this->twigEnvironment;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user