forked from twigphp/Twig
/
SetTest.php
69 lines (60 loc) · 2.5 KB
/
SetTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Twig_Tests_Node_SetTest extends Twig_Test_NodeTestCase
{
public function testConstructor()
{
$names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 1)), array(), 1);
$values = new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 1)), array(), 1);
$node = new Twig_Node_Set(false, $names, $values, 1);
$this->assertEquals($names, $node->getNode('names'));
$this->assertEquals($values, $node->getNode('values'));
$this->assertFalse($node->getAttribute('capture'));
}
public function getTests()
{
$tests = array();
$names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 1)), array(), 1);
$values = new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 1)), array(), 1);
$node = new Twig_Node_Set(false, $names, $values, 1);
$tests[] = array($node, <<<EOF
// line 1
\$context["foo"] = "foo";
EOF
);
$names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 1)), array(), 1);
$values = new Twig_Node(array(new Twig_Node_Print(new Twig_Node_Expression_Constant('foo', 1), 1)), array(), 1);
$node = new Twig_Node_Set(true, $names, $values, 1);
$tests[] = array($node, <<<EOF
// line 1
ob_start();
echo "foo";
\$context["foo"] = ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());
EOF
);
$names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 1)), array(), 1);
$values = new Twig_Node_Text('foo', 1);
$node = new Twig_Node_Set(true, $names, $values, 1);
$tests[] = array($node, <<<EOF
// line 1
\$context["foo"] = ('' === \$tmp = "foo") ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());
EOF
);
$names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 1), new Twig_Node_Expression_AssignName('bar', 1)), array(), 1);
$values = new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Name('bar', 1)), array(), 1);
$node = new Twig_Node_Set(false, $names, $values, 1);
$tests[] = array($node, <<<EOF
// line 1
list(\$context["foo"], \$context["bar"]) = array("foo", {$this->getVariableGetter('bar')});
EOF
);
return $tests;
}
}