]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/twig/twig/test/Twig/Tests/Node/MacroTest.php
twig implementation
[github/wallabag/wallabag.git] / vendor / twig / twig / test / Twig / Tests / Node / MacroTest.php
1 <?php
2
3 /*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 class Twig_Tests_Node_MacroTest extends Twig_Test_NodeTestCase
13 {
14 /**
15 * @covers Twig_Node_Macro::__construct
16 */
17 public function testConstructor()
18 {
19 $body = new Twig_Node_Text('foo', 1);
20 $arguments = new Twig_Node(array(new Twig_Node_Expression_Name('foo', 1)), array(), 1);
21 $node = new Twig_Node_Macro('foo', $body, $arguments, 1);
22
23 $this->assertEquals($body, $node->getNode('body'));
24 $this->assertEquals($arguments, $node->getNode('arguments'));
25 $this->assertEquals('foo', $node->getAttribute('name'));
26 }
27
28 /**
29 * @covers Twig_Node_Macro::compile
30 * @dataProvider getTests
31 */
32 public function testCompile($node, $source, $environment = null)
33 {
34 parent::testCompile($node, $source, $environment);
35 }
36
37 public function getTests()
38 {
39 $body = new Twig_Node_Text('foo', 1);
40 $arguments = new Twig_Node(array(
41 'foo' => new Twig_Node_Expression_Constant(null, 1),
42 'bar' => new Twig_Node_Expression_Constant('Foo', 1),
43 ), array(), 1);
44 $node = new Twig_Node_Macro('foo', $body, $arguments, 1);
45
46 return array(
47 array($node, <<<EOF
48 // line 1
49 public function getfoo(\$_foo = null, \$_bar = "Foo")
50 {
51 \$context = \$this->env->mergeGlobals(array(
52 "foo" => \$_foo,
53 "bar" => \$_bar,
54 ));
55
56 \$blocks = array();
57
58 ob_start();
59 try {
60 echo "foo";
61 } catch (Exception \$e) {
62 ob_end_clean();
63
64 throw \$e;
65 }
66
67 return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());
68 }
69 EOF
70 ),
71 );
72 }
73 }