10
10
use PHPUnit \Framework \Attributes \Test ;
11
11
use SMS \FluidComponents \Utility \ComponentLoader ;
12
12
use TYPO3 \CMS \Core \Http \ServerRequest ;
13
+ use TYPO3 \CMS \Core \Information \Typo3Version ;
13
14
use TYPO3 \CMS \Core \Utility \GeneralUtility ;
14
15
use TYPO3 \CMS \Extbase \Mvc \ExtbaseRequestParameters ;
15
16
use TYPO3 \CMS \Extbase \Mvc \Request ;
@@ -120,22 +121,7 @@ public static function renderDataProvider(): Generator
120
121
#[DataProvider('renderDataProvider ' )]
121
122
public function render (string $ template , string $ expected ): void
122
123
{
123
- $ view = new TemplateView ();
124
-
125
- $ view ->setRenderingContext (
126
- GeneralUtility::makeInstance (RenderingContextFactory::class)->create (
127
- [],
128
- new Request (
129
- (new ServerRequest )->withAttribute (
130
- 'extbase ' ,
131
- new ExtbaseRequestParameters
132
- )
133
- )
134
- )
135
- );
136
-
137
- $ view ->getRenderingContext ()->getViewHelperResolver ()->addNamespace ('fc ' , 'SMS \\FluidComponents \\ViewHelpers ' );
138
- $ view ->getRenderingContext ()->getViewHelperResolver ()->addNamespace ('test ' , 'SMS \\FluidComponents \\Tests \\Fixtures \\Functional \\Components ' );
124
+ $ view = $ this ->getView ();
139
125
$ view ->getRenderingContext ()->getTemplatePaths ()->setTemplateSource ($ template );
140
126
141
127
// Test without cache
@@ -149,23 +135,7 @@ public function render(string $template, string $expected): void
149
135
public function unspecifiedRequiredSlot (): void
150
136
{
151
137
$ template = '<test:slotParameter /> ' ;
152
-
153
- $ view = new TemplateView ();
154
-
155
- $ view ->setRenderingContext (
156
- GeneralUtility::makeInstance (RenderingContextFactory::class)->create (
157
- [],
158
- new Request (
159
- (new ServerRequest )->withAttribute (
160
- 'extbase ' ,
161
- new ExtbaseRequestParameters
162
- )
163
- )
164
- )
165
- );
166
-
167
- $ view ->getRenderingContext ()->getViewHelperResolver ()->addNamespace ('fc ' , 'SMS \\FluidComponents \\ViewHelpers ' );
168
- $ view ->getRenderingContext ()->getViewHelperResolver ()->addNamespace ('test ' , 'SMS \\FluidComponents \\Tests \\Fixtures \\Functional \\Components ' );
138
+ $ view = $ this ->getView ();
169
139
$ view ->getRenderingContext ()->getTemplatePaths ()->setTemplateSource ($ template );
170
140
171
141
// Test without cache
@@ -183,23 +153,7 @@ public function unspecifiedRequiredSlot(): void
183
153
public function undefinedSlot (): void
184
154
{
185
155
$ template = '<test:slotParameter><fc:content slot="slot">content</fc:content><fc:content slot="invalidSlot">more content</fc:content></test:slotParameter> ' ;
186
-
187
- $ view = new TemplateView ();
188
-
189
- $ view ->setRenderingContext (
190
- GeneralUtility::makeInstance (RenderingContextFactory::class)->create (
191
- [],
192
- new Request (
193
- (new ServerRequest )->withAttribute (
194
- 'extbase ' ,
195
- new ExtbaseRequestParameters
196
- )
197
- )
198
- )
199
- );
200
-
201
- $ view ->getRenderingContext ()->getViewHelperResolver ()->addNamespace ('fc ' , 'SMS \\FluidComponents \\ViewHelpers ' );
202
- $ view ->getRenderingContext ()->getViewHelperResolver ()->addNamespace ('test ' , 'SMS \\FluidComponents \\Tests \\Fixtures \\Functional \\Components ' );
156
+ $ view = $ this ->getView ();
203
157
$ view ->getRenderingContext ()->getTemplatePaths ()->setTemplateSource ($ template );
204
158
205
159
// Test without cache
@@ -212,4 +166,37 @@ public function undefinedSlot(): void
212
166
self ::expectExceptionCode (1681832624 );
213
167
$ view ->render ();
214
168
}
169
+
170
+ protected function getView (): TemplateView
171
+ {
172
+ $ view = new TemplateView ();
173
+
174
+ if (GeneralUtility::makeInstance (Typo3Version::class)->getMajorVersion () < 13 ) {
175
+ $ renderingContext = GeneralUtility::makeInstance (RenderingContextFactory::class)->create ();
176
+ $ renderingContext ->setRequest (new Request (
177
+ (new ServerRequest )->withAttribute (
178
+ 'extbase ' ,
179
+ new ExtbaseRequestParameters
180
+ )
181
+ ));
182
+ $ view ->setRenderingContext ($ renderingContext );
183
+ } else {
184
+ $ view ->setRenderingContext (
185
+ GeneralUtility::makeInstance (RenderingContextFactory::class)->create (
186
+ [],
187
+ new Request (
188
+ (new ServerRequest )->withAttribute (
189
+ 'extbase ' ,
190
+ new ExtbaseRequestParameters
191
+ )
192
+ )
193
+ )
194
+ );
195
+ }
196
+
197
+ $ view ->getRenderingContext ()->getViewHelperResolver ()->addNamespace ('fc ' , 'SMS \\FluidComponents \\ViewHelpers ' );
198
+ $ view ->getRenderingContext ()->getViewHelperResolver ()->addNamespace ('test ' , 'SMS \\FluidComponents \\Tests \\Fixtures \\Functional \\Components ' );
199
+
200
+ return $ view ;
201
+ }
215
202
}
0 commit comments