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