4 * This file is part of Twig.
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
11 abstract class Twig_Test_NodeTestCase
extends PHPUnit_Framework_TestCase
13 abstract public function getTests();
16 * @dataProvider getTests
18 public function testCompile($node, $source, $environment = null)
20 $this->assertNodeCompilation($source, $node, $environment);
23 public function assertNodeCompilation($source, Twig_Node
$node, Twig_Environment
$environment = null)
25 $compiler = $this->getCompiler($environment);
26 $compiler->compile($node);
28 $this->assertEquals($source, trim($compiler->getSource()));
31 protected function getCompiler(Twig_Environment
$environment = null)
33 return new Twig_Compiler(null === $environment ? $this->getEnvironment() : $environment);
36 protected function getEnvironment()
38 return new Twig_Environment();
41 protected function getVariableGetter($name)
43 if (version_compare(phpversion(), '5.4.0RC1', '>=')) {
44 return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
47 return sprintf('$this->getContext($context, "%s")', $name);
50 protected function getAttributeGetter()
52 if (function_exists('twig_template_get_attributes')) {
53 return 'twig_template_get_attributes($this, ';
56 return '$this->getAttribute(';