1212namespace Symfony \Bridge \Twig \Tests \Extension ;
1313
1414use Symfony \Bridge \Twig \Extension \FormExtension ;
15+ use Symfony \Bridge \Twig \Extension \FormExtensionRuntime ;
1516use Symfony \Bridge \Twig \Form \TwigRenderer ;
1617use Symfony \Bridge \Twig \Form \TwigRendererEngine ;
1718use Symfony \Bridge \Twig \Extension \TranslationExtension ;
2223
2324class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
2425{
25- /**
26- * @var FormExtension
27- */
28- protected $ extension ;
29-
3026 protected $ testableFeatures = array (
3127 'choice_attr ' ,
3228 );
3329
30+ private $ environment ;
31+
3432 protected function setUp ()
3533 {
3634 parent ::setUp ();
@@ -40,27 +38,23 @@ protected function setUp()
4038 __DIR__ .'/Fixtures/templates/form ' ,
4139 ));
4240
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 ());
4544
4645 $ rendererEngine = new TwigRendererEngine (array (
4746 'bootstrap_3_layout.html.twig ' ,
4847 'custom_widgets.html.twig ' ,
49- ), $ environment );
48+ ), $ this -> environment );
5049 $ renderer = new TwigRenderer ($ rendererEngine , $ this ->getMock ('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface ' ));
5150
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 ),
55+ )));
6256
63- $ this ->extension = null ;
57+ $ this ->environment -> registerExtensionRuntimeLoader ( $ loader ) ;
6458 }
6559
6660 public function testStartTagHasNoActionAttributeWhenActionIsEmpty ()
@@ -89,12 +83,12 @@ public function testStartTagHasActionAttributeWhenActionIsZero()
8983
9084 protected function renderForm (FormView $ view , array $ vars = array ())
9185 {
92- return (string ) $ this ->extension ->renderer ->renderBlock ($ view , 'form ' , $ vars );
86+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->renderBlock ($ view , 'form ' , $ vars );
9387 }
4E22
94 88
9589 protected function renderEnctype (FormView $ view )
9690 {
97- return (string ) $ this ->extension ->renderer ->searchAndRenderBlock ($ view , 'enctype ' );
91+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->searchAndRenderBlock ($ view , 'enctype ' );
9892 }
9993
10094 protected function renderLabel (FormView $ view , $ label = null , array $ vars = array ())
@@ -103,41 +97,41 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra
10397 $ vars += array ('label ' => $ label );
10498 }
10599
106- return (string ) $ this ->extension ->renderer ->searchAndRenderBlock ($ view , 'label ' , $ vars );
100+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->searchAndRenderBlock ($ view , 'label ' , $ vars );
107101 }
108102
109103 protected function renderErrors (FormView $ view )
110104 {
111- return (string ) $ this ->extension ->renderer ->searchAndRenderBlock ($ view , 'errors ' );
105+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->searchAndRenderBlock ($ view , 'errors ' );
112106 }
113107
D9CA
114108 protected function renderWidget (FormView $ view , array $ vars = array ())
115109 {
116- return (string ) $ this ->extension ->renderer ->searchAndRenderBlock ($ view , 'widget ' , $ vars );
110+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->searchAndRenderBlock ($ view , 'widget ' , $ vars );
117111 }
118112
119113 protected function renderRow (FormView $ view , array $ vars = array ())
120114 {
121- return (string ) $ this ->extension ->renderer ->searchAndRenderBlock ($ view , 'row ' , $ vars );
115+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->searchAndRenderBlock ($ view , 'row ' , $ vars );
122116 }
123117
124118 protected function renderRest (FormView $ view , array $ vars = array ())
125119 {
126- return (string ) $ this ->extension ->renderer ->searchAndRenderBlock ($ view , 'rest ' , $ vars );
120+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->searchAndRenderBlock ($ view , 'rest ' , $ vars );
127121 }
128122
129123 protected function renderStart (FormView $ view , array $ vars = array ())
130124 {
131- return (string ) $ this ->extension ->renderer ->renderBlock ($ view , 'form_start ' , $ vars );
125+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->renderBlock ($ view , 'form_start ' , $ vars );
132126 }
133127
134128 protected function renderEnd (FormView $ view , array $ vars = array ())
135129 {
136- return (string ) $ this ->extension ->renderer ->renderBlock ($ view , 'form_end ' , $ vars );
130+ return (string ) $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->renderBlock ($ view , 'form_end ' , $ vars );
137131 }
138132
139133 protected function setTheme (FormView $ view , array $ themes )
140134 {
141- $ this ->extension ->renderer ->setTheme ($ view , $ themes );
135+ $ this ->environment -> getRuntimeExtension ( ' form ' ) ->renderer ->setTheme ($ view , $ themes );
142136 }
143137}
0 commit comments