Пример #1
0
 public function testCompile()
 {
     $form = new \Twig_Node_Expression_Name('form', 0);
     $resources = new \Twig_Node_Expression_Array(array(new \Twig_Node_Expression_Constant(0, 0), new \Twig_Node_Expression_Constant('tpl1', 0), new \Twig_Node_Expression_Constant(1, 0), new \Twig_Node_Expression_Constant('tpl2', 0)), 0);
     $node = new FormThemeNode($form, $resources, 0);
     $compiler = new \Twig_Compiler(new \Twig_Environment());
     $this->assertEquals(sprintf('$this->env->getExtension(\'form\')->renderer->setTheme(%s, array(0 => "tpl1", 1 => "tpl2"));', $this->getVariableGetter('form')), trim($compiler->compile($node)->getSource()));
     $resources = new \Twig_Node_Expression_Constant('tpl1', 0);
     $node = new FormThemeNode($form, $resources, 0);
     $this->assertEquals(sprintf('$this->env->getExtension(\'form\')->renderer->setTheme(%s, "tpl1");', $this->getVariableGetter('form')), trim($compiler->compile($node)->getSource()));
 }
Пример #2
0
 public function testCompile()
 {
     $form = new \Twig_Node_Expression_Name('form', 0);
     $resources = new \Twig_Node_Expression_Array(array(new \Twig_Node_Expression_Constant(0, 0), new \Twig_Node_Expression_Constant('tpl1', 0), new \Twig_Node_Expression_Constant(1, 0), new \Twig_Node_Expression_Constant('tpl2', 0)), 0);
     $node = new FormThemeNode($form, $resources, 0);
     $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
     $this->assertEquals(sprintf('$this->env->getRuntime(\'Symfony\\Bridge\\Twig\\Form\\TwigRenderer\')->setTheme(%s, array(0 => "tpl1", 1 => "tpl2"));', $this->getVariableGetter('form')), trim($compiler->compile($node)->getSource()));
     $resources = new \Twig_Node_Expression_Constant('tpl1', 0);
     $node = new FormThemeNode($form, $resources, 0);
     $this->assertEquals(sprintf('$this->env->getRuntime(\'Symfony\\Bridge\\Twig\\Form\\TwigRenderer\')->setTheme(%s, "tpl1");', $this->getVariableGetter('form')), trim($compiler->compile($node)->getSource()));
 }
 public function testCompile()
 {
     $datagrid = new \Twig_Node_Expression_Name('view', 0);
     $resources = new \Twig_Node_Expression_Array([new \Twig_Node_Expression_Constant(0, 0), new \Twig_Node_Expression_Constant('tpl1', 0), new \Twig_Node_Expression_Constant(1, 0), new \Twig_Node_Expression_Constant('tpl2', 0)], 0);
     $node = new DatagridThemeNode($datagrid, $resources, 0);
     $compiler = new \Twig_Compiler(new \Twig_Environment($this->createMock('Twig_LoaderInterface')));
     self::assertEquals(sprintf('$this->env->getRuntime(\'' . TwigRenderer::class . '\')->setTheme(%s, array(0 => "tpl1", 1 => "tpl2"));', $this->getVariableGetter('view')), trim($compiler->compile($node)->getSource()));
     $resources = new \Twig_Node_Expression_Constant('tpl1', 0);
     $node = new DatagridThemeNode($datagrid, $resources, 0);
     self::assertEquals(sprintf('$this->env->getRuntime(\'' . TwigRenderer::class . '\')->setTheme(%s, "tpl1");', $this->getVariableGetter('view')), trim($compiler->compile($node)->getSource()));
 }
Пример #4
0
 public function testCompile()
 {
     $block = new \Twig_Node([new \Twig_Node_Expression_Name('layout', 0)]);
     $resources = new \Twig_Node([new \Twig_Node_Expression_Constant('SomeBundle:Layout:blocks.html.twig', 0)]);
     $node = new BlockThemeNode($block, $resources, 0);
     $compiler = new \Twig_Compiler(new \Twig_Environment());
     $this->assertEquals(sprintf(self::SET_THEME_CALL . '(%s, "SomeBundle:Layout:blocks.html.twig");', $this->getVariableGetter('layout')), trim($compiler->compile($node)->getSource()));
 }
Пример #5
0
 public function testCompileStrict()
 {
     $body = new \Twig_Node_Text('trans %var%', 0);
     $vars = new \Twig_Node_Expression_Name('foo', 0);
     $node = new TransNode($body, null, null, $vars);
     $env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('strict_variables' => true));
     $compiler = new \Twig_Compiler($env);
     $this->assertEquals(sprintf('echo $this->env->getExtension(\'translator\')->getTranslator()->trans("trans %%var%%", array_merge(array("%%var%%" => %s), %s), "messages");', $this->getVariableGetterWithoutStrictCheck('var'), $this->getVariableGetterWithStrictCheck('foo')), trim($compiler->compile($node)->getSource()));
 }
 public function testCompileStrict()
 {
     $body = new \Twig_Node_Text('Hello %name%', 0);
     $vars = new \Twig_Node_Expression_Name('foo', 0);
     $node = new SafeTransNode($body, null, null, $vars);
     $env = new \Twig_Environment(null, array('strict_variables' => true));
     $compiler = new \Twig_Compiler($env);
     $this->assertEquals(sprintf('echo $this->env->getExtension(\'translator\')->getTranslator()->trans("Hello %%name%%", array_merge(array("%%name%%" => twig_escape_filter($this->env, %s)), %s), "messages");', $this->getVariableGetter('name'), $this->getVariableGetter('foo')), trim($compiler->compile($node)->getSource()));
 }
    public function testCompile()
    {
        $body = new \Twig_Node_Text('<html><head></head><body class="body"></body></html>', 0);
        $node = new HighlightNode($body, null, null, 'html');
        $env = new \Twig_Environment(null, array('strict_variables' => true));
        $compiler = new \Twig_Compiler($env);
        $expected = <<<TEXT
echo '<div class="zero-clipboard"><span class="btn-clipboard btn-clipboard-hover">Copy</span></div>';
\$result = \\PHPygments\\PHPygments::render("". "<html><head></head><body class=\\"body\\"></body></html>"
, 'html');
echo preg_replace('#^<div class="highlighted-source default (.*)"><pre>(.*)</pre></div>\$#s', '<div class="highlight"><pre><code class="\$1">\$2</code></pre></div>', \$result["code"]);
TEXT;
        $this->assertEquals($expected, trim($compiler->compile($node)->getSource()));
    }
Пример #8
0
    public function testMultiVars()
    {
        $vars = new \Twig_Node(array(new \Twig_Node_Expression_Name('foo', 7), new \Twig_Node_Expression_Name('bar', 7)));
        $node = new DumpNode('bar', $vars, 7);
        $env = new \Twig_Environment();
        $compiler = new \Twig_Compiler($env);
        $expected = <<<'EOTXT'
if ($this->env->isDebug()) {
    // line 7
    \Symfony\Component\VarDumper\VarDumper::dump(array(
        "foo" => %foo%,
        "bar" => %bar%,
    ));
}

EOTXT;
        $expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);
        $this->assertSame($expected, $compiler->compile($node)->getSource());
    }
 public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
 {
     $arguments = new \Twig_Node(array(new \Twig_Node_Expression_Name('form', 0), new \Twig_Node_Expression_Conditional(new \Twig_Node_Expression_Constant(true, 0), new \Twig_Node_Expression_Constant(null, 0), new \Twig_Node_Expression_Constant(null, 0), 0), new \Twig_Node_Expression_Array(array(new \Twig_Node_Expression_Constant('foo', 0), new \Twig_Node_Expression_Constant('bar', 0), new \Twig_Node_Expression_Constant('label', 0), new \Twig_Node_Expression_Constant('value in attributes', 0)), 0)));
     $node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
     $compiler = new \Twig_Compiler(new \Twig_Environment());
     // "label" => null must not be included in the output!
     // Otherwise the default label is overwritten with null.
     // https://github.com/symfony/symfony/issues/5029
     $this->assertEquals(sprintf('$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("foo" => "bar", "label" => "value in attributes") + (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? array() : array("label" => $_label_)))', $this->getVariableGetter('form')), trim($compiler->compile($node)->getSource()));
 }
 public function testCompileHeaderWithLabelThatEvaluatesToNullAndAttributes()
 {
     $arguments = new \Twig_Node([new \Twig_Node_Expression_Name('header', 0), new \Twig_Node_Expression_Conditional(new \Twig_Node_Expression_Constant(true, 0), new \Twig_Node_Expression_Constant(null, 0), new \Twig_Node_Expression_Constant(null, 0), 0), new \Twig_Node_Expression_Array([new \Twig_Node_Expression_Constant('foo', 0), new \Twig_Node_Expression_Constant('bar', 0), new \Twig_Node_Expression_Constant('label', 0), new \Twig_Node_Expression_Constant('value in attributes', 0)], 0)]);
     $node = new SearchAndRenderBlockNode('rollerworks_datagrid_column_header', $arguments, 0);
     $compiler = new \Twig_Compiler(new \Twig_Environment($this->createMock('Twig_LoaderInterface')));
     // "label" => null must not be included in the output!
     // Otherwise the default label is overwritten with null.
     self::assertEquals(sprintf('$this->env->getRuntime(\'' . TwigRenderer::class . '\')->searchAndRenderBlock(%s, \'header\', array("foo" => "bar", "label" => "value in attributes") + (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))', $this->getVariableGetter('header')), trim($compiler->compile($node)->getSource()));
 }