]>
Commit | Line | Data |
---|---|---|
4f5b44bd NL |
1 | <?php |
2 | ||
3 | /* | |
4 | * This file is part of the Symfony package. | |
5 | * | |
6 | * (c) Fabien Potencier <fabien@symfony.com> | |
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 | namespace Symfony\Bridge\Twig\Tests\Node; | |
13 | ||
14 | use Symfony\Bridge\Twig\Tests\TestCase; | |
15 | use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser; | |
16 | use Symfony\Bridge\Twig\Node\FormThemeNode; | |
17 | ||
18 | class FormThemeTokenParserTest extends TestCase | |
19 | { | |
20 | protected function setUp() | |
21 | { | |
22 | parent::setUp(); | |
23 | ||
24 | if (version_compare(\Twig_Environment::VERSION, '1.5.0', '<')) { | |
25 | $this->markTestSkipped('Requires Twig version to be at least 1.5.0.'); | |
26 | } | |
27 | } | |
28 | ||
29 | /** | |
30 | * @dataProvider getTestsForFormTheme | |
31 | */ | |
32 | public function testCompile($source, $expected) | |
33 | { | |
34 | $env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); | |
35 | $env->addTokenParser(new FormThemeTokenParser()); | |
36 | $stream = $env->tokenize($source); | |
37 | $parser = new \Twig_Parser($env); | |
38 | ||
39 | $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)); | |
40 | } | |
41 | ||
42 | public function getTestsForFormTheme() | |
43 | { | |
44 | return array( | |
45 | array( | |
46 | '{% form_theme form "tpl1" %}', | |
47 | new FormThemeNode( | |
48 | new \Twig_Node_Expression_Name('form', 1), | |
49 | new \Twig_Node_Expression_Array(array( | |
50 | new \Twig_Node_Expression_Constant(0, 1), | |
51 | new \Twig_Node_Expression_Constant('tpl1', 1), | |
52 | ), 1), | |
53 | 1, | |
54 | 'form_theme' | |
55 | ) | |
56 | ), | |
57 | array( | |
58 | '{% form_theme form "tpl1" "tpl2" %}', | |
59 | new FormThemeNode( | |
60 | new \Twig_Node_Expression_Name('form', 1), | |
61 | new \Twig_Node_Expression_Array(array( | |
62 | new \Twig_Node_Expression_Constant(0, 1), | |
63 | new \Twig_Node_Expression_Constant('tpl1', 1), | |
64 | new \Twig_Node_Expression_Constant(1, 1), | |
65 | new \Twig_Node_Expression_Constant('tpl2', 1) | |
66 | ), 1), | |
67 | 1, | |
68 | 'form_theme' | |
69 | ) | |
70 | ), | |
71 | array( | |
72 | '{% form_theme form with "tpl1" %}', | |
73 | new FormThemeNode( | |
74 | new \Twig_Node_Expression_Name('form', 1), | |
75 | new \Twig_Node_Expression_Constant('tpl1', 1), | |
76 | 1, | |
77 | 'form_theme' | |
78 | ) | |
79 | ), | |
80 | array( | |
81 | '{% form_theme form with ["tpl1"] %}', | |
82 | new FormThemeNode( | |
83 | new \Twig_Node_Expression_Name('form', 1), | |
84 | new \Twig_Node_Expression_Array(array( | |
85 | new \Twig_Node_Expression_Constant(0, 1), | |
86 | new \Twig_Node_Expression_Constant('tpl1', 1), | |
87 | ), 1), | |
88 | 1, | |
89 | 'form_theme' | |
90 | ) | |
91 | ), | |
92 | array( | |
93 | '{% form_theme form with ["tpl1", "tpl2"] %}', | |
94 | new FormThemeNode( | |
95 | new \Twig_Node_Expression_Name('form', 1), | |
96 | new \Twig_Node_Expression_Array(array( | |
97 | new \Twig_Node_Expression_Constant(0, 1), | |
98 | new \Twig_Node_Expression_Constant('tpl1', 1), | |
99 | new \Twig_Node_Expression_Constant(1, 1), | |
100 | new \Twig_Node_Expression_Constant('tpl2', 1) | |
101 | ), 1), | |
102 | 1, | |
103 | 'form_theme' | |
104 | ) | |
105 | ), | |
106 | ); | |
107 | } | |
108 | } |