12
12
namespace Symfony \Bridge \Twig \Tests \Extension ;
13
13
14
14
use Symfony \Bridge \Twig \Extension \FormExtension ;
15
+ use Symfony \Bridge \Twig \Extension \FormExtensionRuntime ;
15
16
use Symfony \Bridge \Twig \Form \TwigRenderer ;
16
17
use Symfony \Bridge \Twig \Form \TwigRendererEngine ;
17
18
use Symfony \Bridge \Twig \Extension \TranslationExtension ;
22
23
23
24
class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
24
25
{
25
- /**
26
- * @var FormExtension
27
- */
28
- protected $ extension ;
29
-
30
26
protected $ testableFeatures = array (
31
27
'choice_attr ' ,
32
28
);
33
29
30
+ private $ environment ;
31
+
34
32
protected function setUp ()
35
33
{
36
34
parent ::setUp ();
@@ -40,27 +38,23 @@ protected function setUp()
40
38
__DIR__ .'/Fixtures/templates/form ' ,
41
39
));
42
40
43
- $ environment = new \Twig_Environment ($ loader , array ('strict_variables ' => true ));
44
- $ environment ->addExtension (new TranslationExtension (new StubTranslator ()));
41
+ $ this ->environment = new \Twig_Environment ($ loader , array ('strict_variables ' => true ));
42
+ $ this ->environment ->addExtension (new TranslationExtension (new StubTranslator ()));
43
+ $ this ->environment ->addExtension (new FormExtension ());
45
44
46
45
$ rendererEngine = new TwigRendererEngine (array (
47
46
'bootstrap_3_layout.html.twig ' ,
48
47
'custom_widgets.html.twig ' ,
49
- ), $ environment );
48
+ ), $ this -> environment );
50
49
$ renderer = new TwigRenderer ($ rendererEngine , $ this ->getMock ('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface ' ));
51
50
52
- $ this ->extension = new FormExtension ($ renderer );
53
-
54
- $ environment ->addExtension ($ this ->extension );
55
-
56
- $ this ->extension ->initRuntime ($ environment );
57
- }
58
-
59
- protected function tearDown ()
60
- {
61
- parent ::tearDown ();
51
+ $ loader = $ this ->getMock ('Twig_RuntimeExtensionLoaderInterface ' );
52
+ $ loader ->expects ($ this ->any ())->method ('load ' )->will ($ this ->returnValueMap (array (
53
+ array ('form ' , new FormExtensionRuntime ($ renderer )),
54
+ array ('translator ' , null ),
2358
div>
55
+ )));
62
56
63
- $ this ->extension = null ;
57
+ $ this ->environment -> registerExtensionRuntimeLoader ( $ loader ) ;
64
58
}
65
59
66
60
public function testStartTagHasNoActionAttributeWhenActionIsEmpty ()
@@ -89,12 +83,12 @@ public function testStartTagHasActionAttributeWhenActionIsZero()
89
83
90
84
protected function renderForm (FormView $ view , array $ vars = array ())
91
85
{
92
- return (string ) $ this ->extension ->renderer ->renderBlock ($ view , 'form ' , $ vars );
86
+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->renderBlock ($ view , 'form ' , $ vars );
93
87
}
94
88
95
89
protected function renderEnctype (FormView $ view )
96
90
{
97
- return (string ) $ this ->extension ->renderer ->searchAndRenderBlock ($ view , 'enctype ' );
91
+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->searchAndRenderBlock ($ view , 'enctype ' );
98
92
}
99
93
100
94
protected function renderLabel (FormView $ view , $ label = null , array $ vars = array ())
@@ -103,41 +97,41 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra
103
97
$ vars += array ('label ' => $ label );
104
98
}
105
99
106
- return (string ) $ this ->extension ->renderer ->searchAndRenderBlock ($ view , 'label ' , $ vars );
100
+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->searchAndRenderBlock ($ view , 'label ' , $ vars );
107
101
}
108
102
109
103
protected function renderErrors (FormView $ view )
110
104
{
111
- return (string ) $ this ->extension ->renderer ->searchAndRenderBlock ($ view , 'errors ' );
105
+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->searchAndRenderBlock ($ view , 'errors ' );
112
106
}
113
107
114
108
protected function renderWidget (FormView $ view , array $ vars = array ())
115
109
{
116
- return (string ) $ this ->extension ->renderer ->searchAndRenderBlock ($ view , 'widget ' , $ vars );
110
+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->searchAndRenderBlock ($ view , 'widget ' , $ vars );
117
111
}
118
112
119
113
protected function renderRow (FormView $ view , array $ vars = array ())
120
114
{
121
- return (string ) $ this ->extension ->renderer ->searchAndRenderBlock ($ view , 'row ' , $ vars );
115
+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->searchAndRenderBlock ($ view , 'row ' , $ vars );
122
116
}
123
117
124
118
protected function renderRest (FormView $ view , array $ vars = array ())
125
119
{
126
- return (string ) $ this ->extension ->renderer ->searchAndRenderBlock ($ view , 'rest ' , $ vars );
120
+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->searchAndRenderBlock ($ view , 'rest ' , $ vars );
127
121
}
128
122
129
123
protected function renderStart (FormView $ view , array $ vars = array ())
130
124
{
131
- return (string ) $ this ->extension ->renderer ->renderBlock ($ view , 'form_start ' , $ vars );
125
+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->renderBlock ($ view , 'form_start ' , $ vars );
132
126
}
133
127
134
128
protected function renderEnd (FormView $ view , array $ vars = array ())
135
129
{
136
- return (string ) $ this ->extension ->renderer ->renderBlock ($ view , 'form_end ' , $ vars );
130
+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->renderBlock ($ view , 'form_end ' , $ vars );
137
131
}
138
132
139
133
protected function setTheme (FormView $ view , array $ themes )
140
134
{
141
- $ this ->extension ->renderer ->setTheme ($ view , $ themes );
135
+ $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->setTheme ($ view , $ themes );
142
136
}
143
137
}
0 commit comments