[TASK] Functional test for tt_content rendering
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Functional / Rendering / LocalizedContentRenderingTest.php
1 <?php
2
3 namespace TYPO3\CMS\Frontend\Tests\Functional\Rendering;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Core\Tests\Functional\Framework\Frontend\Response;
20
21 /**
22 * Test case checking if localized tt_content is rendered correctly with different language settings
23 *
24 * The following values are relevant:
25 *
26 * -- TypoScript --
27 * config.sys_language_uid = [0,1,2,3,4...] (set via the language parameter &L=1 from the FrontendRequest in the tests)
28 * Fetch the page overlay of the current page if the value is > 0 and if not available, then
29 * "config.sys_language_mode" is evaluated.
30 * If this setting is set to "0" or empty, then no page overlay is evaluated, and no further parameters are
31 * relevant or evaluated.
32 *
33 * config.sys_language_mode = [strict, content_fallback;2,3, ignore]
34 * Only evaluated when sys_language_uid > 0, and the requested page translation is NOT available.
35 * Decides if "pageNotFound" (strict), "content_fallback" with a fallback chain ($TSFE->sys_language_content is set
36 * to that value) or "ignore" (just render the page and the content as this translation would exist).
37 * When set to "0" or not set "", this means that the page request is using the default language for content
38 * and page properties.
39 * Content fallback is evaluated on page level, not on the CE level. So it only makes a difference when the pages_language_overlay
40 * for the requested language does not exist.
41 *
42 * config.sys_language_overlay = [0, 1, hideNonTranslated]
43 * Only relevant if $TSFE->sys_language_content is > 0.
44 * Sets the property $TSFE->sys_language_contentOL at a request. Further calls via $TSFE->sys_page->getRecordOverlay
45 * receive this value to see if an overlay should happen.
46 * 0:
47 * Just fetch records from selected ($TSFE->sys_language_content) language, no overlay will happen,
48 * no fetching of the records from the default language. This boils down to "free mode" language handling.
49 *
50 * 1:
51 * Fetch records from the default language and overlay them with translations. If some record is not translated
52 * default language version will be shown.
53 *
54 * hideNotTranslated:
55 * Fetch records from the default language and overlay them with translations. If some record is not translated
56 * it will not be shown.
57 *
58 * -- Frontend / TypoScriptFrontendController --
59 *
60 * $TSFE->sys_language_uid
61 * Defines in which language the current page was requested, this is relevant when building menus or links to other
62 * pages.
63 * $TSFE->sys_language_content
64 * Contains the language UID of the content records that should be overlaid to would be fetched.
65 * This is especially useful when a page requested with language=4 should fall back to showing content of language=2 (see config.sys_language_mode=content_fallback)
66 * $TSFE->sys_language_contentOL
67 * Contains the info if and how record overlays (when fetching content) should be handled, either "0" (no overlays done)
68 * or "1" (do overlays with possible mixed content, or "hideNonTranslated". see "config.sys_language_overlay"
69 * This is used in conjunction with $TSFE->sys_language_content.
70 * $TSFE->sys_language_mode
71 * Contains the config.sys_language_mode parameter, which is either "", "strict", "content_fallback" or "ignore"
72 * Only used within $TSFE->settingLanguage() and in Extbase.
73 */
74 class LocalizedContentRenderingTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase
75 {
76 const VALUE_PageId = 89;
77 const TABLE_Content = 'tt_content';
78 const TABLE_Pages = 'pages';
79
80 /**
81 * @var string
82 */
83 protected $scenarioDataSetDirectory = 'typo3/sysext/frontend/Tests/Functional/Rendering/DataSet/';
84
85 /**
86 * Custom 404 handler returning valid json is registered so the $this->getFrontendResponse()
87 * does not fail on 404 pages
88 *
89 * @var array
90 */
91 protected $configurationToUseInTestInstance = [
92 'FE' => [
93 'pageNotFound_handling' => 'READFILE:typo3/sysext/frontend/Tests/Functional/Rendering/DataSet/404Template.html'
94 ]
95 ];
96
97 protected function setUp()
98 {
99 parent::setUp();
100 $this->importScenarioDataSet('LiveDefaultPages');
101 $this->importScenarioDataSet('LiveDefaultElements');
102
103 $this->backendUser->workspace = 0;
104 }
105
106 public function defaultLanguageConfigurationDataProvider()
107 {
108 return [
109 [
110 'typoScript' => 'config.sys_language_overlay = 0
111 config.sys_language_mode =',
112 'sys_language_mode' => '',
113 'sys_language_contentOL' => 0
114 ],
115 [
116 'typoScript' => 'config.sys_language_overlay = 0
117 config.sys_language_mode = content_fallback',
118 'sys_language_mode' => 'content_fallback',
119 'sys_language_contentOL' => 0
120 ],
121 [
122 'typoScript' => 'config.sys_language_overlay = 0
123 config.sys_language_mode = content_fallback;1,0',
124 'sys_language_mode' => 'content_fallback',
125 'sys_language_contentOL' => 0
126 ],
127 [
128 'typoScript' => 'config.sys_language_overlay = 0
129 config.sys_language_mode = strict',
130 'sys_language_mode' => 'strict',
131 'sys_language_contentOL' => 0
132 ],
133 [
134 'typoScript' => 'config.sys_language_overlay = 0
135 config.sys_language_mode = ignore',
136 'sys_language_mode' => 'ignore',
137 'sys_language_contentOL' => 0
138 ],
139 [
140 'typoScript' => 'config.sys_language_overlay = 1
141 config.sys_language_mode =',
142 'sys_language_mode' => '',
143 'sys_language_contentOL' => 1
144 ],
145 [
146 'typoScript' => 'config.sys_language_overlay = 1
147 config.sys_language_mode = content_fallback',
148 'sys_language_mode' => 'content_fallback',
149 'sys_language_contentOL' => 1
150 ],
151 [
152 'typoScript' => 'config.sys_language_overlay = 1
153 config.sys_language_mode = content_fallback;1,0',
154 'sys_language_mode' => 'content_fallback',
155 'sys_language_contentOL' => 1
156 ],
157 [
158 'typoScript' => 'config.sys_language_overlay = 1
159 config.sys_language_mode = strict',
160 'sys_language_mode' => 'strict',
161 'sys_language_contentOL' => 1
162 ],
163 [
164 'typoScript' => 'config.sys_language_overlay = 1
165 config.sys_language_mode = ignore',
166 'sys_language_mode' => 'ignore',
167 'sys_language_contentOL' => 1
168 ],
169 [
170 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
171 config.sys_language_mode =',
172 'sys_language_mode' => '',
173 'sys_language_contentOL' => 'hideNonTranslated'
174 ],
175 [
176 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
177 config.sys_language_mode = content_fallback',
178 'sys_language_mode' => 'content_fallback',
179 'sys_language_contentOL' => 'hideNonTranslated'
180 ],
181 [
182 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
183 config.sys_language_mode = content_fallback;1,0',
184 'sys_language_mode' => 'content_fallback',
185 'sys_language_contentOL' => 'hideNonTranslated'
186 ],
187 [
188 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
189 config.sys_language_mode = strict',
190 'sys_language_mode' => 'strict',
191 'sys_language_contentOL' => 'hideNonTranslated'
192 ],
193 [
194 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
195 config.sys_language_mode = ignore',
196 'sys_language_mode' => 'ignore',
197 'sys_language_contentOL' => 'hideNonTranslated'
198 ],
199 ];
200 }
201
202 /**
203 * For the default language all combination of language settings should give the same result,
204 * regardless of TypoScript settings, if the requested language is "0" then no TypoScript settings apply.
205 *
206 * @test
207 * @dataProvider defaultLanguageConfigurationDataProvider
208 *
209 * @param string $typoScript
210 * @param string $sysLanguageMode
211 * @param string $sysLanguageContentOL
212 */
213 public function onlyEnglishContentIsRenderedForDefaultLanguage($typoScript, $sysLanguageMode, $sysLanguageContentOL)
214 {
215 $this->setUpFrontendRootPage(1, [
216 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.ts',
217 ]);
218 $this->addTypoScriptToTemplateRecord(1, $typoScript);
219
220 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 0);
221 $responseSections = $frontendResponse->getResponseSections();
222 $visibleHeaders = ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'];
223 $constraint = $this->getRequestSectionHasRecordConstraint()
224 ->setTable(self::TABLE_Content)
225 ->setField('header');
226 call_user_func_array([$constraint, 'setValues'], $visibleHeaders);
227 $this->assertThat($responseSections, $constraint);
228
229 $constraint = $this->getRequestSectionDoesNotHaveRecordConstraint()
230 ->setTable(self::TABLE_Content)
231 ->setField('header');
232 call_user_func_array([$constraint, 'setValues'], $this->getNonVisibleHeaders($visibleHeaders));
233 $this->assertThat($responseSections, $constraint);
234
235 $content = json_decode($frontendResponse->getContent());
236 $this->assertEquals('Default language Page', $content->Scope->page->title);
237 $this->assertEquals(0, $content->Scope->tsfe->sys_language_uid, 'sys_language_uid doesn\'t match');
238 $this->assertEquals(0, $content->Scope->tsfe->sys_language_content, 'sys_language_content doesn\'t match');
239 $this->assertEquals($sysLanguageMode, $content->Scope->tsfe->sys_language_mode, 'sys_language_mode doesn\t match');
240 $this->assertEquals($sysLanguageContentOL, $content->Scope->tsfe->sys_language_contentOL, 'sys_language_contentOL doesn\t match');
241 }
242
243 /**
244 * Dutch language has pages_language_overlay record and some content elements are translated
245 *
246 * @return array
247 */
248 public function dutchDataProvider()
249 {
250 //Expected behaviour:
251 //Page is translated to Dutch, so changing sys_language_mode does NOT change the results
252 //Page title is always [DK]Page, and both sys_language_content and sys_language_uid are always 1
253 return [
254 [
255 'typoScript' => 'config.sys_language_overlay = 0
256 config.sys_language_mode =',
257 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language'],
258 'sys_language_mode' => '',
259 'sys_language_contentOL' => 0
260 ],
261 [
262 'typoScript' => 'config.sys_language_overlay = 0
263 config.sys_language_mode = content_fallback',
264 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language'],
265 'sys_language_mode' => 'content_fallback',
266 'sys_language_contentOL' => 0
267 ],
268 [
269 'typoScript' => 'config.sys_language_overlay = 0
270 config.sys_language_mode = content_fallback;1,0',
271 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language'],
272 'sys_language_mode' => 'content_fallback',
273 'sys_language_contentOL' => 0
274 ],
275 [
276 'typoScript' => 'config.sys_language_overlay = 0
277 config.sys_language_mode = strict',
278 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language'],
279 'sys_language_mode' => 'strict',
280 'sys_language_contentOL' => 0
281 ],
282 [
283 'typoScript' => 'config.sys_language_overlay = 0
284 config.sys_language_mode = ignore',
285 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language'],
286 'sys_language_mode' => 'ignore',
287 'sys_language_contentOL' => 0
288 ],
289 [
290 'typoScript' => 'config.sys_language_overlay = 1
291 config.sys_language_mode =',
292 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3'],
293 'sys_language_mode' => '',
294 'sys_language_contentOL' => 1
295 ],
296 // Expected behaviour:
297 // Not translated element #2 is shown because sys_language_overlay = 1 (with sys_language_overlay = hideNonTranslated, it would be hidden)
298 [
299 'typoScript' => 'config.sys_language_overlay = 1
300 config.sys_language_mode = content_fallback',
301 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3'],
302 'sys_language_mode' => 'content_fallback',
303 'sys_language_contentOL' => 1
304 ],
305 // Expected behaviour:
306 // Same as config.sys_language_mode = content_fallback because we're requesting language 1, so no additional fallback possible
307 //
308 [
309 'typoScript' => 'config.sys_language_overlay = 1
310 config.sys_language_mode = content_fallback;1,0',
311 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3'],
312 'sys_language_mode' => 'content_fallback',
313 'sys_language_contentOL' => 1
314 ],
315 [
316 'typoScript' => 'config.sys_language_overlay = 1
317 config.sys_language_mode = strict',
318 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3'],
319 'sys_language_mode' => 'strict',
320 'sys_language_contentOL' => 1
321 ],
322 [
323 'typoScript' => 'config.sys_language_overlay = 1
324 config.sys_language_mode = ignore',
325 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3'],
326 'sys_language_mode' => 'ignore',
327 'sys_language_contentOL' => 1
328 ],
329 // Expected behaviour:
330 // Non translated default language elements are not shown, because of hideNonTranslated
331 [
332 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
333 config.sys_language_mode =',
334 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3'],
335 'sys_language_mode' => '',
336 'sys_language_contentOL' => 'hideNonTranslated'
337 ],
338 [
339 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
340 config.sys_language_mode = content_fallback',
341 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3'],
342 'sys_language_mode' => 'content_fallback',
343 'sys_language_contentOL' => 'hideNonTranslated'
344 ],
345 [
346 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
347 config.sys_language_mode = content_fallback;1,0',
348 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3'],
349 'sys_language_mode' => 'content_fallback',
350 'sys_language_contentOL' => 'hideNonTranslated'
351 ],
352 //Setting sys_language_mode = strict has the same effect as previous data sets, because the translation of the page exists
353 [
354 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
355 config.sys_language_mode = strict',
356 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3'],
357 'sys_language_mode' => 'strict',
358 'sys_language_contentOL' => 'hideNonTranslated'
359 ],
360 [
361 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
362 config.sys_language_mode = ignore',
363 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3'],
364 'sys_language_mode' => 'ignore',
365 'sys_language_contentOL' => 'hideNonTranslated'
366 ],
367 ];
368 }
369
370 /**
371 * @test
372 * @dataProvider dutchDataProvider
373 *
374 * @param string $typoScript
375 * @param array $visibleHeaders
376 * @param string $sysLanguageMode
377 * @param string $sysLanguageContentOL
378 */
379 public function renderingOfDutchLanguage($typoScript, array $visibleHeaders, $sysLanguageMode, $sysLanguageContentOL)
380 {
381 $this->setUpFrontendRootPage(1, [
382 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.ts',
383 ]);
384 $this->addTypoScriptToTemplateRecord(1, $typoScript);
385 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 1);
386 $responseSections = $frontendResponse->getResponseSections();
387 $constraint = $this->getRequestSectionHasRecordConstraint()
388 ->setTable(self::TABLE_Content)
389 ->setField('header');
390 call_user_func_array([$constraint, 'setValues'], $visibleHeaders);
391 $this->assertThat($responseSections, $constraint);
392
393 $constraint = $this->getRequestSectionDoesNotHaveRecordConstraint()
394 ->setTable(self::TABLE_Content)
395 ->setField('header');
396 call_user_func_array([$constraint, 'setValues'], $this->getNonVisibleHeaders($visibleHeaders));
397 $this->assertThat($responseSections, $constraint);
398
399 $content = json_decode($frontendResponse->getContent());
400 $this->assertEquals('[DK]Page', $content->Scope->page->title);
401 $this->assertEquals(1, $content->Scope->tsfe->sys_language_uid, 'sys_language_uid doesn\'t match');
402 $this->assertEquals(1, $content->Scope->tsfe->sys_language_content, 'sys_language_content doesn\'t match');
403 $this->assertEquals($sysLanguageMode, $content->Scope->tsfe->sys_language_mode, 'sys_language_mode doesn\t match');
404 $this->assertEquals($sysLanguageContentOL, $content->Scope->tsfe->sys_language_contentOL, 'sys_language_contentOL doesn\t match');
405 }
406
407 public function contentOnNonTranslatedPageDataProvider()
408 {
409 //Expected behaviour:
410 //the page is NOT translated so setting sys_language_mode to different values changes the results
411 //- setting sys_language_mode to empty value makes TYPO3 return default language records
412 //- setting it to strict throws 404, independently from other settings
413 //Setting config.sys_language_overlay = 0
414 return [
415 [
416 'typoScript' => 'config.sys_language_overlay = 0
417 config.sys_language_mode =',
418 'visibleRecordHeaders' => ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
419 'pageTitle' => 'Default language Page',
420 'sys_language_uid' => 0,
421 'sys_language_content' => 0,
422 'sys_language_mode' => '',
423 'sys_language_contentOL' => 0,
424 ],
425 [
426 'typoScript' => 'config.sys_language_overlay = 0
427 config.sys_language_mode = content_fallback',
428 'visibleRecordHeaders' => ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
429 'pageTitle' => 'Default language Page',
430 'sys_language_uid' => 2,
431 'sys_language_content' => 0,
432 'sys_language_mode' => 'content_fallback',
433 'sys_language_contentOL' => 0,
434 ],
435 [
436 'typoScript' => 'config.sys_language_overlay = 0
437 config.sys_language_mode = content_fallback;1,0',
438 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language'],
439 'pageTitle' => 'Default language Page', //TODO: change it to "[DK]Page" once #81657 is fixed
440 'sys_language_uid' => 2,
441 'sys_language_content' => 1,
442 'sys_language_mode' => 'content_fallback',
443 'sys_language_contentOL' => 0,
444 ],
445 [
446 'typoScript' => 'config.sys_language_overlay = 0
447 config.sys_language_mode = strict',
448 'visibleRecordHeaders' => [],
449 'pageTitle' => '',
450 'sys_language_uid' => 2,
451 'sys_language_content' => 2,
452 'sys_language_mode' => 'strict',
453 'sys_language_contentOL' => 0,
454 'status' => 404,
455 ],
456 [
457 'typoScript' => 'config.sys_language_overlay = 0
458 config.sys_language_mode = ignore',
459 'visibleRecordHeaders' => ['[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1', '[DE] Without default language'],
460 'pageTitle' => 'Default language Page',
461 'sys_language_uid' => 2,
462 'sys_language_content' => 2,
463 'sys_language_mode' => 'ignore',
464 'sys_language_contentOL' => 0,
465 ],
466 5 => [
467 'typoScript' => 'config.sys_language_overlay = 1
468 config.sys_language_mode =',
469 'visibleRecordHeaders' => ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
470 'pageTitle' => 'Default language Page',
471 'sys_language_uid' => 0,
472 'sys_language_content' => 0,
473 'sys_language_mode' => '',
474 'sys_language_contentOL' => 1,
475 ],
476 //falling back to default language
477 [
478 'typoScript' => 'config.sys_language_overlay = 1
479 config.sys_language_mode = content_fallback',
480 'visibleRecordHeaders' => ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
481 'pageTitle' => 'Default language Page',
482 'sys_language_uid' => 2,
483 'sys_language_content' => 0,
484 'sys_language_mode' => 'content_fallback',
485 'sys_language_contentOL' => 1,
486 ],
487 //Dutch elements are shown because of the content fallback 1,0 - first Dutch, then default language
488 //note that '[DK] Without default language' is NOT shown - due to overlays (fetch default language and overlay it with translations)
489 [
490 'typoScript' => 'config.sys_language_overlay = 1
491 config.sys_language_mode = content_fallback;1,0',
492 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3'],
493 'pageTitle' => 'Default language Page', //TODO: change it to "[DK]Page" once #81657 is fixed
494 'sys_language_uid' => 2,
495 'sys_language_content' => 1,
496 'sys_language_mode' => 'content_fallback',
497 'sys_language_contentOL' => 1,
498 ],
499 [
500 'typoScript' => 'config.sys_language_overlay = 1
501 config.sys_language_mode = strict',
502 'visibleRecordHeaders' => [],
503 'pageTitle' => '',
504 'sys_language_uid' => 2,
505 'sys_language_content' => 2,
506 'sys_language_mode' => 'strict',
507 'sys_language_contentOL' => 1,
508 'status' => 404
509 ],
510 [
511 'typoScript' => 'config.sys_language_overlay = 1
512 config.sys_language_mode = ignore',
513 'visibleRecordHeaders' => ['[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
514 'pageTitle' => 'Default language Page',
515 'sys_language_uid' => 2,
516 'sys_language_content' => 2,
517 'sys_language_mode' => 'ignore',
518 'sys_language_contentOL' => 1,
519 ],
520 10 => [
521 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
522 config.sys_language_mode =',
523 'visibleRecordHeaders' => ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
524 'pageTitle' => 'Default language Page',
525 'sys_language_uid' => 0,
526 'sys_language_content' => 0,
527 'sys_language_mode' => '',
528 'sys_language_contentOL' => 'hideNonTranslated',
529 ],
530 [
531 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
532 config.sys_language_mode = content_fallback',
533 'visibleRecordHeaders' => ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
534 'pageTitle' => 'Default language Page',
535 'sys_language_uid' => 2,
536 'sys_language_content' => 0,
537 'sys_language_mode' => 'content_fallback',
538 'sys_language_contentOL' => 'hideNonTranslated',
539 ],
540 [
541 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
542 config.sys_language_mode = content_fallback;1,0',
543 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3'],
544 'pageTitle' => 'Default language Page', //TODO: change it to "[DK]Page" once #81657 is fixed
545 'sys_language_uid' => 2,
546 'sys_language_content' => 1,
547 'sys_language_mode' => 'content_fallback',
548 'sys_language_contentOL' => 'hideNonTranslated',
549 ],
550 [
551 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
552 config.sys_language_mode = strict',
553 'visibleRecordHeaders' => [],
554 'pageTitle' => '',
555 'sys_language_uid' => 2,
556 'sys_language_content' => 2,
557 'sys_language_mode' => 'strict',
558 'sys_language_contentOL' => 'hideNonTranslated',
559 'status' => 404,
560 ],
561 [
562 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
563 config.sys_language_mode = ignore',
564 'visibleRecordHeaders' => ['[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1'],
565 'pageTitle' => 'Default language Page',
566 'sys_language_uid' => 2,
567 'sys_language_content' => 2,
568 'sys_language_mode' => 'ignore',
569 'sys_language_contentOL' => 'hideNonTranslated',
570 ],
571 ];
572 }
573
574 /**
575 * Page uid 89 is NOT translated to german
576 *
577 * @test
578 * @dataProvider contentOnNonTranslatedPageDataProvider
579 *
580 * @param string $typoScript
581 * @param array $visibleHeaders
582 * @param string $pageTitle
583 * @param int $sysLanguageUid
584 * @param int $sysLanguageContent
585 * @param string $sysLanguageMode
586 * @param string $sysLanguageContentOL
587 * @param string $status 'success' or 404
588 */
589 public function contentOnNonTranslatedPageGerman($typoScript, array $visibleHeaders, $pageTitle, $sysLanguageUid, $sysLanguageContent, $sysLanguageMode, $sysLanguageContentOL, $status='success')
590 {
591 $this->setUpFrontendRootPage(1, [
592 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.ts',
593 ]);
594 $this->addTypoScriptToTemplateRecord(1, $typoScript);
595
596 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 2);
597 if ($status === Response::STATUS_Success) {
598 $responseSections = $frontendResponse->getResponseSections();
599 $constraint = $this->getRequestSectionHasRecordConstraint()
600 ->setTable(self::TABLE_Content)
601 ->setField('header');
602 call_user_func_array([$constraint, 'setValues'], $visibleHeaders);
603 $this->assertThat($responseSections, $constraint);
604
605 $constraint = $this->getRequestSectionDoesNotHaveRecordConstraint()
606 ->setTable(self::TABLE_Content)
607 ->setField('header');
608 call_user_func_array([$constraint, 'setValues'], $this->getNonVisibleHeaders($visibleHeaders));
609 $this->assertThat($responseSections, $constraint);
610
611 $content = json_decode($frontendResponse->getContent());
612 $this->assertEquals($pageTitle, $content->Scope->page->title);
613 $this->assertEquals($sysLanguageUid, $content->Scope->tsfe->sys_language_uid, 'sys_language_uid doesn\'t match');
614 $this->assertEquals($sysLanguageContent, $content->Scope->tsfe->sys_language_content, 'sys_language_content doesn\'t match');
615 $this->assertEquals($sysLanguageMode, $content->Scope->tsfe->sys_language_mode, 'sys_language_mode doesn\t match');
616 $this->assertEquals($sysLanguageContentOL, $content->Scope->tsfe->sys_language_contentOL, 'sys_language_contentOL doesn\t match');
617 }
618 //some configuration combinations results in 404, in that case status will be set to 404
619 $this->assertEquals($status, $frontendResponse->getStatus());
620 }
621
622 public function contentOnPartiallyTranslatedPageDataProvider()
623 {
624
625 //Expected behaviour:
626 //Setting sys_language_mode to different values doesn't influence the result as the requested page is translated to Polish,
627 //Page title is always [PL]Page, and both sys_language_content and sys_language_uid are always 3
628 return [
629 [
630 'typoScript' => 'config.sys_language_overlay = 0
631 config.sys_language_mode =',
632 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
633 'sys_language_mode' => '',
634 'sys_language_contentOL' => 0
635 ],
636 [
637 'typoScript' => 'config.sys_language_overlay = 0
638 config.sys_language_mode = content_fallback',
639 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
640 'sys_language_mode' => 'content_fallback',
641 'sys_language_contentOL' => 0
642 ],
643 [
644 'typoScript' => 'config.sys_language_overlay = 0
645 config.sys_language_mode = content_fallback;1,0',
646 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
647 'sys_language_mode' => 'content_fallback',
648 'sys_language_contentOL' => 0
649 ],
650 [
651 'typoScript' => 'config.sys_language_overlay = 0
652 config.sys_language_mode = strict',
653 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
654 'sys_language_mode' => 'strict',
655 'sys_language_contentOL' => 0
656 ],
657 [
658 'typoScript' => 'config.sys_language_overlay = 0
659 config.sys_language_mode = ignore',
660 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
661 'sys_language_mode' => 'ignore',
662 'sys_language_contentOL' => 0
663 ],
664 5 => [
665 'typoScript' => 'config.sys_language_overlay = 1
666 config.sys_language_mode =',
667 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
668 'sys_language_mode' => '',
669 'sys_language_contentOL' => 1
670 ],
671 // Expected behaviour:
672 // Not translated element #2 is shown because sys_language_overlay = 1 (with sys_language_overlay = hideNonTranslated, it would be hidden)
673 [
674 'typoScript' => 'config.sys_language_overlay = 1
675 config.sys_language_mode = content_fallback',
676 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
677 'sys_language_mode' => 'content_fallback',
678 'sys_language_contentOL' => 1
679 ],
680 // Expected behaviour:
681 // Element #3 is not translated in PL and it is translated in DK. It's not shown as content_fallback is not related to single CE level
682 // but on page level - and this page is translated to Polish, so no fallback is happening
683 [
684 'typoScript' => 'config.sys_language_overlay = 1
685 config.sys_language_mode = content_fallback;1,0',
686 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
687 'sys_language_mode' => 'content_fallback',
688 'sys_language_contentOL' => 1
689 ],
690 [
691 'typoScript' => 'config.sys_language_overlay = 1
692 config.sys_language_mode = strict',
693 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
694 'sys_language_mode' => 'strict',
695 'sys_language_contentOL' => 1
696 ],
697 [
698 'typoScript' => 'config.sys_language_overlay = 1
699 config.sys_language_mode = ignore',
700 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
701 'sys_language_mode' => 'ignore',
702 'sys_language_contentOL' => 1
703 ],
704 // Expected behaviour:
705 // Non translated default language elements are not shown, because of hideNonTranslated
706 10 => [
707 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
708 config.sys_language_mode =',
709 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1'],
710 'sys_language_mode' => '',
711 'sys_language_contentOL' => 'hideNonTranslated'
712 ],
713 [
714 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
715 config.sys_language_mode = content_fallback',
716 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1'],
717 'sys_language_mode' => 'content_fallback',
718 'sys_language_contentOL' => 'hideNonTranslated'
719 ],
720 [
721 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
722 config.sys_language_mode = content_fallback;1,0',
723 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1'],
724 'sys_language_mode' => 'content_fallback',
725 'sys_language_contentOL' => 'hideNonTranslated'
726 ],
727 [
728 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
729 config.sys_language_mode = strict',
730 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1'],
731 'sys_language_mode' => 'strict',
732 'sys_language_contentOL' => 'hideNonTranslated'
733 ],
734 [
735 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
736 config.sys_language_mode = ignore',
737 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1'],
738 'sys_language_mode' => 'ignore',
739 'sys_language_contentOL' => 'hideNonTranslated'
740 ]
741 ];
742 }
743
744 /**
745 * Page uid 89 is translated to to Polish, but not all CE are translated
746 *
747 * @test
748 * @dataProvider contentOnPartiallyTranslatedPageDataProvider
749 *
750 * @param string $typoScript
751 * @param array $visibleHeaders
752 * @param string $sysLanguageMode
753 * @param string $sysLanguageContentOL
754 */
755 public function contentOnPartiallyTranslatedPage($typoScript, array $visibleHeaders, $sysLanguageMode, $sysLanguageContentOL)
756 {
757 $this->setUpFrontendRootPage(1, [
758 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.ts',
759 ]);
760 $this->addTypoScriptToTemplateRecord(1, $typoScript);
761
762 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 3);
763 $this->assertEquals('success', $frontendResponse->getStatus());
764 $responseSections = $frontendResponse->getResponseSections();
765
766 $constraint = $this->getRequestSectionHasRecordConstraint()
767 ->setTable(self::TABLE_Content)
768 ->setField('header');
769 call_user_func_array([$constraint, 'setValues'], $visibleHeaders);
770 $this->assertThat($responseSections, $constraint);
771
772 $constraint = $this->getRequestSectionDoesNotHaveRecordConstraint()
773 ->setTable(self::TABLE_Content)
774 ->setField('header');
775 call_user_func_array([$constraint, 'setValues'], $this->getNonVisibleHeaders($visibleHeaders));
776 $this->assertThat($responseSections, $constraint);
777
778 $content = json_decode($frontendResponse->getContent());
779 $this->assertEquals('[PL]Page', $content->Scope->page->title);
780 $this->assertEquals(3, $content->Scope->tsfe->sys_language_uid, 'sys_language_uid doesn\'t match');
781 $this->assertEquals(3, $content->Scope->tsfe->sys_language_content, 'sys_language_content doesn\'t match');
782 $this->assertEquals($sysLanguageMode, $content->Scope->tsfe->sys_language_mode, 'sys_language_mode doesn\t match');
783 $this->assertEquals($sysLanguageContentOL, $content->Scope->tsfe->sys_language_contentOL, 'sys_language_contentOL doesn\t match');
784 }
785
786 /**
787 * Helper function to ease asserting that rest of the data set is not visible
788 *
789 * @param array $visibleHeaders
790 * @return array
791 */
792 protected function getNonVisibleHeaders(array $visibleHeaders)
793 {
794 $allElements = [
795 'Regular Element #1',
796 'Regular Element #2',
797 'Regular Element #3',
798 '[Translate to Dansk:] Regular Element #1',
799 '[Translate to Dansk:] Regular Element #3',
800 '[DK] Without default language',
801 '[DE] Without default language',
802 '[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1',
803 '[Translate to Polski:] Regular Element #1',
804 '[PL] Without default language'
805 ];
806 return array_diff($allElements, $visibleHeaders);
807 }
808
809 /**
810 * Adds TypoScript setup snippet to the existing template record
811 *
812 * @param int $pageId
813 * @param string $typoScript
814 */
815 protected function addTypoScriptToTemplateRecord($pageId, $typoScript)
816 {
817 $connection = $this->getDatabaseConnection();
818
819 $template = $connection->exec_SELECTgetSingleRow('*', 'sys_template', 'pid = '. $pageId . ' AND root = 1');
820 if (empty($template)) {
821 $this->fail('Cannot find root template on page with id: "' . $pageId . '"');
822 }
823 $updateFields['config'] = $template['config'] . LF . $typoScript;
824 $connection->exec_UPDATEquery(
825 'sys_template',
826 'uid = ' . $template['uid'],
827 $updateFields
828 );
829 }
830 }