]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/twig/twig/test/Twig/Tests/Node/SetTest.php
d64d671a8ee58de9df99e8359f50a7069fd7ad75
[github/wallabag/wallabag.git] / vendor / twig / twig / test / Twig / Tests / Node / SetTest.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_SetTest extends Twig_Test_NodeTestCase
13 {
14 /**
15 * @covers Twig_Node_Set::__construct
16 */
17 public function testConstructor()
18 {
19 $names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 1)), array(), 1);
20 $values = new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 1)), array(), 1);
21 $node = new Twig_Node_Set(false, $names, $values, 1);
22
23 $this->assertEquals($names, $node->getNode('names'));
24 $this->assertEquals($values, $node->getNode('values'));
25 $this->assertEquals(false, $node->getAttribute('capture'));
26 }
27
28 /**
29 * @covers Twig_Node_Set::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 $tests = array();
40
41 $names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 1)), array(), 1);
42 $values = new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 1)), array(), 1);
43 $node = new Twig_Node_Set(false, $names, $values, 1);
44 $tests[] = array($node, <<<EOF
45 // line 1
46 \$context["foo"] = "foo";
47 EOF
48 );
49
50 $names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 1)), array(), 1);
51 $values = new Twig_Node(array(new Twig_Node_Print(new Twig_Node_Expression_Constant('foo', 1), 1)), array(), 1);
52 $node = new Twig_Node_Set(true, $names, $values, 1);
53 $tests[] = array($node, <<<EOF
54 // line 1
55 ob_start();
56 echo "foo";
57 \$context["foo"] = ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());
58 EOF
59 );
60
61 $names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 1)), array(), 1);
62 $values = new Twig_Node_Text('foo', 1);
63 $node = new Twig_Node_Set(true, $names, $values, 1);
64 $tests[] = array($node, <<<EOF
65 // line 1
66 \$context["foo"] = ('' === \$tmp = "foo") ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());
67 EOF
68 );
69
70 $names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 1), new Twig_Node_Expression_AssignName('bar', 1)), array(), 1);
71 $values = new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Name('bar', 1)), array(), 1);
72 $node = new Twig_Node_Set(false, $names, $values, 1);
73 $tests[] = array($node, <<<EOF
74 // line 1
75 list(\$context["foo"], \$context["bar"]) = array("foo", {$this->getVariableGetter('bar')});
76 EOF
77 );
78
79 return $tests;
80 }
81 }