forked from twigphp/Twig
/
IncludeTest.php
77 lines (65 loc) · 2.66 KB
/
IncludeTest.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
70
71
72
73
74
75
76
77
<?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.
*/
require_once dirname(__FILE__).'/TestCase.php';
class Twig_Tests_Node_IncludeTest extends Twig_Tests_Node_TestCase
{
/**
* @covers Twig_Node_Include::__construct
*/
public function testConstructor()
{
$expr = new Twig_Node_Expression_Constant('foo.twig', 0);
$node = new Twig_Node_Include($expr, null, false, 0);
$this->assertEquals(null, $node->getNode('variables'));
$this->assertEquals($expr, $node->getNode('expr'));
$this->assertFalse($node->getAttribute('only'));
$vars = new Twig_Node_Expression_Array(array('foo' => new Twig_Node_Expression_Constant(true, 0)), 0);
$node = new Twig_Node_Include($expr, $vars, true, 0);
$this->assertEquals($vars, $node->getNode('variables'));
$this->assertTrue($node->getAttribute('only'));
}
/**
* @covers Twig_Node_Include::compile
* @dataProvider getTests
*/
public function testCompile($node, $source, $environment = null)
{
parent::testCompile($node, $source, $environment);
}
public function getTests()
{
$tests = array();
$expr = new Twig_Node_Expression_Constant('foo.twig', 0);
$node = new Twig_Node_Include($expr, null, false, 0);
$tests[] = array($node, '$this->env->loadTemplate("foo.twig")->display($context);');
$expr = new Twig_Node_Expression_Conditional(
new Twig_Node_Expression_Constant(true, 0),
new Twig_Node_Expression_Constant('foo', 0),
new Twig_Node_Expression_Constant('foo', 0),
0
);
$node = new Twig_Node_Include($expr, null, false, 0);
$tests[] = array($node, <<<EOF
\$template = ((true) ? ("foo") : ("foo"));
if (!\$template instanceof Twig_Template) {
\$template = \$this->env->loadTemplate(\$template);
}
\$template->display(\$context);
EOF
);
$expr = new Twig_Node_Expression_Constant('foo.twig', 0);
$vars = new Twig_Node_Expression_Array(array('foo' => new Twig_Node_Expression_Constant(true, 0)), 0);
$node = new Twig_Node_Include($expr, $vars, false, 0);
$tests[] = array($node, '$this->env->loadTemplate("foo.twig")->display(array_merge($context, array("foo" => true)));');
$node = new Twig_Node_Include($expr, $vars, true, 0);
$tests[] = array($node, '$this->env->loadTemplate("foo.twig")->display(array("foo" => true));');
return $tests;
}
}