[TASK] Add functional tests for rendering translated tt_content with FAL
[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 /**
100 * @var array
101 */
102 protected $pathsToLinkInTestInstance = [
103 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/AdditionalConfiguration.php' => 'typo3conf/AdditionalConfiguration.php',
104 'typo3/sysext/frontend/Tests/Functional/Fixtures/Images' => 'fileadmin/user_upload'
105 ];
106
107 protected function setUp()
108 {
109 parent::setUp();
110 $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/sys_file_storage.xml');
111 $this->importScenarioDataSet('LiveDefaultPages');
112 $this->importScenarioDataSet('LiveDefaultElements');
113 $this->setUpFrontendRootPage(1, [
114 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.ts',
115 ]);
116 $this->backendUser->workspace = 0;
117 }
118
119 public function defaultLanguageConfigurationDataProvider(): array
120 {
121 return [
122 [
123 'typoScript' => 'config.sys_language_overlay = 0
124 config.sys_language_mode =',
125 'sys_language_mode' => '',
126 'sys_language_contentOL' => 0
127 ],
128 [
129 'typoScript' => 'config.sys_language_overlay = 0
130 config.sys_language_mode = content_fallback',
131 'sys_language_mode' => 'content_fallback',
132 'sys_language_contentOL' => 0
133 ],
134 [
135 'typoScript' => 'config.sys_language_overlay = 0
136 config.sys_language_mode = content_fallback;1,0',
137 'sys_language_mode' => 'content_fallback',
138 'sys_language_contentOL' => 0
139 ],
140 [
141 'typoScript' => 'config.sys_language_overlay = 0
142 config.sys_language_mode = strict',
143 'sys_language_mode' => 'strict',
144 'sys_language_contentOL' => 0
145 ],
146 [
147 'typoScript' => 'config.sys_language_overlay = 0
148 config.sys_language_mode = ignore',
149 'sys_language_mode' => 'ignore',
150 'sys_language_contentOL' => 0
151 ],
152 [
153 'typoScript' => 'config.sys_language_overlay = 1
154 config.sys_language_mode =',
155 'sys_language_mode' => '',
156 'sys_language_contentOL' => 1
157 ],
158 [
159 'typoScript' => 'config.sys_language_overlay = 1
160 config.sys_language_mode = content_fallback',
161 'sys_language_mode' => 'content_fallback',
162 'sys_language_contentOL' => 1
163 ],
164 [
165 'typoScript' => 'config.sys_language_overlay = 1
166 config.sys_language_mode = content_fallback;1,0',
167 'sys_language_mode' => 'content_fallback',
168 'sys_language_contentOL' => 1
169 ],
170 [
171 'typoScript' => 'config.sys_language_overlay = 1
172 config.sys_language_mode = strict',
173 'sys_language_mode' => 'strict',
174 'sys_language_contentOL' => 1
175 ],
176 [
177 'typoScript' => 'config.sys_language_overlay = 1
178 config.sys_language_mode = ignore',
179 'sys_language_mode' => 'ignore',
180 'sys_language_contentOL' => 1
181 ],
182 [
183 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
184 config.sys_language_mode =',
185 'sys_language_mode' => '',
186 'sys_language_contentOL' => 'hideNonTranslated'
187 ],
188 [
189 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
190 config.sys_language_mode = content_fallback',
191 'sys_language_mode' => 'content_fallback',
192 'sys_language_contentOL' => 'hideNonTranslated'
193 ],
194 [
195 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
196 config.sys_language_mode = content_fallback;1,0',
197 'sys_language_mode' => 'content_fallback',
198 'sys_language_contentOL' => 'hideNonTranslated'
199 ],
200 [
201 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
202 config.sys_language_mode = strict',
203 'sys_language_mode' => 'strict',
204 'sys_language_contentOL' => 'hideNonTranslated'
205 ],
206 [
207 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
208 config.sys_language_mode = ignore',
209 'sys_language_mode' => 'ignore',
210 'sys_language_contentOL' => 'hideNonTranslated'
211 ],
212 ];
213 }
214
215 /**
216 * For the default language all combination of language settings should give the same result,
217 * regardless of TypoScript settings, if the requested language is "0" then no TypoScript settings apply.
218 *
219 * @test
220 * @dataProvider defaultLanguageConfigurationDataProvider
221 *
222 * @param string $typoScript
223 * @param string $sysLanguageMode
224 * @param string $sysLanguageContentOL
225 */
226 public function onlyEnglishContentIsRenderedForDefaultLanguage(string $typoScript, string $sysLanguageMode, string $sysLanguageContentOL)
227 {
228 $this->addTypoScriptToTemplateRecord(1, $typoScript);
229
230 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 0);
231 $responseSections = $frontendResponse->getResponseSections();
232 $visibleHeaders = ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'];
233 $this->assertThat(
234 $responseSections,
235 $this->getRequestSectionHasRecordConstraint()
236 ->setTable(self::TABLE_Content)
237 ->setField('header')
238 ->setValues(...$visibleHeaders)
239 );
240 $this->assertThat(
241 $responseSections,
242 $this->getRequestSectionDoesNotHaveRecordConstraint()
243 ->setTable(self::TABLE_Content)
244 ->setField('header')
245 ->setValues(...$this->getNonVisibleHeaders($visibleHeaders))
246 );
247
248 //assert FAL relations
249 $visibleFiles = ['T3BOARD'];
250 $this->assertThat($responseSections, $this->getRequestSectionStructureHasRecordConstraint()
251 ->setRecordIdentifier(self::TABLE_Content . ':297')->setRecordField('image')
252 ->setTable('sys_file_reference')->setField('title')->setValues(...$visibleFiles));
253
254 $this->assertThat($responseSections, $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
255 ->setRecordIdentifier(self::TABLE_Content . ':297')->setRecordField('image')
256 ->setTable('sys_file_reference')->setField('title')->setValues(...$this->getNonVisibleFileTitles($visibleFiles)));
257
258 $visibleFiles = ['Kasper'];
259 $this->assertThat($responseSections, $this->getRequestSectionStructureHasRecordConstraint()
260 ->setRecordIdentifier(self::TABLE_Content . ':298')->setRecordField('image')
261 ->setTable('sys_file_reference')->setField('title')->setValues(...$visibleFiles));
262
263 $this->assertThat($responseSections, $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
264 ->setRecordIdentifier(self::TABLE_Content . ':298')->setRecordField('image')
265 ->setTable('sys_file_reference')->setField('title')->setValues(...$this->getNonVisibleFileTitles($visibleFiles)));
266
267 //Assert TSFE and page record title
268 $content = json_decode($frontendResponse->getContent());
269 $this->assertEquals('Default language Page', $content->Scope->page->title);
270 $this->assertEquals(0, $content->Scope->tsfe->sys_language_uid, 'sys_language_uid doesn\'t match');
271 $this->assertEquals(0, $content->Scope->tsfe->sys_language_content, 'sys_language_content doesn\'t match');
272 $this->assertEquals($sysLanguageMode, $content->Scope->tsfe->sys_language_mode, 'sys_language_mode doesn\t match');
273 $this->assertEquals($sysLanguageContentOL, $content->Scope->tsfe->sys_language_contentOL, 'sys_language_contentOL doesn\t match');
274 }
275
276 /**
277 * Dutch language has pages_language_overlay record and some content elements are translated
278 *
279 * @return array
280 */
281 public function dutchDataProvider(): array
282 {
283 //Expected behaviour:
284 //Page is translated to Dutch, so changing sys_language_mode does NOT change the results
285 //Page title is always [DK]Page, and both sys_language_content and sys_language_uid are always 1
286 return [
287 [
288 'typoScript' => 'config.sys_language_overlay = 0
289 config.sys_language_mode =',
290 'visibleRecords' => [
291 300 => [
292 'header' => '[Translate to Dansk:] Regular Element #3',
293 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
294 ],
295 301 => [
296 'header' => '[Translate to Dansk:] Regular Element #1',
297 'image' => [],
298 ],
299 303 => [
300 'header' => '[DK] Without default language',
301 'image' => ['[T3BOARD] Image added to DK elemet without default language']
302 ],
303 308 => [
304 'header' => '[DK] UnHidden Element #4',
305 'image' => []
306 ],
307 ],
308 'sys_language_mode' => '',
309 'sys_language_contentOL' => 0
310 ],
311 [
312 'typoScript' => 'config.sys_language_overlay = 0
313 config.sys_language_mode = content_fallback',
314 'visibleRecords' => [
315 300 => [
316 'header' => '[Translate to Dansk:] Regular Element #3',
317 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
318 ],
319 301 => [
320 'header' => '[Translate to Dansk:] Regular Element #1',
321 'image' => [],
322 ],
323 303 => [
324 'header' => '[DK] Without default language',
325 'image' => ['[T3BOARD] Image added to DK elemet without default language']
326 ],
327 308 => [
328 'header' => '[DK] UnHidden Element #4',
329 'image' => []
330 ],
331 ],
332 'sys_language_mode' => 'content_fallback',
333 'sys_language_contentOL' => 0
334 ],
335 [
336 'typoScript' => 'config.sys_language_overlay = 0
337 config.sys_language_mode = content_fallback;1,0',
338 'visibleRecords' => [
339 300 => [
340 'header' => '[Translate to Dansk:] Regular Element #3',
341 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
342 ],
343 301 => [
344 'header' => '[Translate to Dansk:] Regular Element #1',
345 'image' => [],
346 ],
347 303 => [
348 'header' => '[DK] Without default language',
349 'image' => ['[T3BOARD] Image added to DK elemet without default language']
350 ],
351 308 => [
352 'header' => '[DK] UnHidden Element #4',
353 'image' => []
354 ],
355 ],
356 'sys_language_mode' => 'content_fallback',
357 'sys_language_contentOL' => 0
358 ],
359 [
360 'typoScript' => 'config.sys_language_overlay = 0
361 config.sys_language_mode = strict',
362 'visibleRecords' => [
363 300 => [
364 'header' => '[Translate to Dansk:] Regular Element #3',
365 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
366 ],
367 301 => [
368 'header' => '[Translate to Dansk:] Regular Element #1',
369 'image' => [],
370 ],
371 303 => [
372 'header' => '[DK] Without default language',
373 'image' => ['[T3BOARD] Image added to DK elemet without default language']
374 ],
375 308 => [
376 'header' => '[DK] UnHidden Element #4',
377 'image' => []
378 ],
379 ],
380 'sys_language_mode' => 'strict',
381 'sys_language_contentOL' => 0
382 ],
383 [
384 'typoScript' => 'config.sys_language_overlay = 0
385 config.sys_language_mode = ignore',
386 'visibleRecords' => [
387 300 => [
388 'header' => '[Translate to Dansk:] Regular Element #3',
389 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
390 ],
391 301 => [
392 'header' => '[Translate to Dansk:] Regular Element #1',
393 'image' => [],
394 ],
395 303 => [
396 'header' => '[DK] Without default language',
397 'image' => ['[T3BOARD] Image added to DK elemet without default language']
398 ],
399 308 => [
400 'header' => '[DK] UnHidden Element #4',
401 'image' => []
402 ],
403 ],
404 'sys_language_mode' => 'ignore',
405 'sys_language_contentOL' => 0
406 ],
407 [
408 'typoScript' => 'config.sys_language_overlay = 1
409 config.sys_language_mode =',
410 'visibleRecords' => [
411 297 => [
412 'header' => '[Translate to Dansk:] Regular Element #1',
413 'image' => [],
414 ],
415 298 => [
416 'header' => 'Regular Element #2',
417 'image' => ['Kasper'],
418 ],
419 299 => [
420 'header' => '[Translate to Dansk:] Regular Element #3',
421 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
422 ],
423 ],
424 'sys_language_mode' => '',
425 'sys_language_contentOL' => 1
426 ],
427 // Expected behaviour:
428 // Not translated element #2 is shown because sys_language_overlay = 1 (with sys_language_overlay = hideNonTranslated, it would be hidden)
429 [
430 'typoScript' => 'config.sys_language_overlay = 1
431 config.sys_language_mode = content_fallback',
432 'visibleRecords' => [
433 297 => [
434 'header' => '[Translate to Dansk:] Regular Element #1',
435 'image' => [],
436 ],
437 298 => [
438 'header' => 'Regular Element #2',
439 'image' => ['Kasper'],
440 ],
441 299 => [
442 'header' => '[Translate to Dansk:] Regular Element #3',
443 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
444 ],
445 ],
446 'sys_language_mode' => 'content_fallback',
447 'sys_language_contentOL' => 1
448 ],
449 // Expected behaviour:
450 // Same as config.sys_language_mode = content_fallback because we're requesting language 1, so no additional fallback possible
451 //
452 [
453 'typoScript' => 'config.sys_language_overlay = 1
454 config.sys_language_mode = content_fallback;1,0',
455 'visibleRecords' => [
456 297 => [
457 'header' => '[Translate to Dansk:] Regular Element #1',
458 'image' => [],
459 ],
460 298 => [
461 'header' => 'Regular Element #2',
462 'image' => ['Kasper'],
463 ],
464 299 => [
465 'header' => '[Translate to Dansk:] Regular Element #3',
466 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
467 ],
468 ],
469 'sys_language_mode' => 'content_fallback',
470 'sys_language_contentOL' => 1
471 ],
472 [
473 'typoScript' => 'config.sys_language_overlay = 1
474 config.sys_language_mode = strict',
475 'visibleRecords' => [
476 297 => [
477 'header' => '[Translate to Dansk:] Regular Element #1',
478 'image' => [],
479 ],
480 298 => [
481 'header' => 'Regular Element #2',
482 'image' => ['Kasper'],
483 ],
484 299 => [
485 'header' => '[Translate to Dansk:] Regular Element #3',
486 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
487 ],
488 ],
489 'sys_language_mode' => 'strict',
490 'sys_language_contentOL' => 1
491 ],
492 [
493 'typoScript' => 'config.sys_language_overlay = 1
494 config.sys_language_mode = ignore',
495 'visibleRecords' => [
496 297 => [
497 'header' => '[Translate to Dansk:] Regular Element #1',
498 'image' => [],
499 ],
500 298 => [
501 'header' => 'Regular Element #2',
502 'image' => ['Kasper'],
503 ],
504 299 => [
505 'header' => '[Translate to Dansk:] Regular Element #3',
506 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
507 ],
508 ],
509 'sys_language_mode' => 'ignore',
510 'sys_language_contentOL' => 1
511 ],
512 // Expected behaviour:
513 // Non translated default language elements are not shown, because of hideNonTranslated
514 [
515 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
516 config.sys_language_mode =',
517 'visibleRecords' => [
518 297 => [
519 'header' => '[Translate to Dansk:] Regular Element #1',
520 'image' => [],
521 ],
522 299 => [
523 'header' => '[Translate to Dansk:] Regular Element #3',
524 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
525 ],
526 ],
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 'visibleRecords' => [
534 297 => [
535 'header' => '[Translate to Dansk:] Regular Element #1',
536 'image' => [],
537 ],
538 299 => [
539 'header' => '[Translate to Dansk:] Regular Element #3',
540 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
541 ],
542 ],
543 'sys_language_mode' => 'content_fallback',
544 'sys_language_contentOL' => 'hideNonTranslated'
545 ],
546 [
547 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
548 config.sys_language_mode = content_fallback;1,0',
549 'visibleRecords' => [
550 297 => [
551 'header' => '[Translate to Dansk:] Regular Element #1',
552 'image' => [],
553 ],
554 299 => [
555 'header' => '[Translate to Dansk:] Regular Element #3',
556 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
557 ],
558 ],
559 'sys_language_mode' => 'content_fallback',
560 'sys_language_contentOL' => 'hideNonTranslated'
561 ],
562 //Setting sys_language_mode = strict has the same effect as previous data sets, because the translation of the page exists
563 [
564 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
565 config.sys_language_mode = strict',
566 'visibleRecords' => [
567 297 => [
568 'header' => '[Translate to Dansk:] Regular Element #1',
569 'image' => [],
570 ],
571 299 => [
572 'header' => '[Translate to Dansk:] Regular Element #3',
573 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
574 ],
575 ],
576 'sys_language_mode' => 'strict',
577 'sys_language_contentOL' => 'hideNonTranslated'
578 ],
579 [
580 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
581 config.sys_language_mode = ignore',
582 'visibleRecords' => [
583 297 => [
584 'header' => '[Translate to Dansk:] Regular Element #1',
585 'image' => [],
586 ],
587 299 => [
588 'header' => '[Translate to Dansk:] Regular Element #3',
589 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
590 ],
591 ],
592 'sys_language_mode' => 'ignore',
593 'sys_language_contentOL' => 'hideNonTranslated'
594 ],
595 ];
596 }
597
598 /**
599 * @test
600 * @dataProvider dutchDataProvider
601 *
602 * @param string $typoScript
603 * @param array $visibleRecords
604 * @param string $sysLanguageMode
605 * @param string $sysLanguageContentOL
606 */
607 public function renderingOfDutchLanguage(string $typoScript, array $visibleRecords, string $sysLanguageMode, string $sysLanguageContentOL)
608 {
609 $this->addTypoScriptToTemplateRecord(1, $typoScript);
610 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 1);
611 $responseSections = $frontendResponse->getResponseSections();
612 $visibleHeaders = array_map(function ($element) {
613 return $element['header'];
614 }, $visibleRecords);
615
616 $this->assertThat(
617 $responseSections,
618 $this->getRequestSectionHasRecordConstraint()
619 ->setTable(self::TABLE_Content)
620 ->setField('header')
621 ->setValues(...$visibleHeaders)
622 );
623 $this->assertThat(
624 $responseSections,
625 $this->getRequestSectionDoesNotHaveRecordConstraint()
626 ->setTable(self::TABLE_Content)
627 ->setField('header')
628 ->setValues(...$this->getNonVisibleHeaders($visibleHeaders))
629 );
630
631 foreach ($visibleRecords as $ttContentUid => $properties) {
632 $visibleFileTitles = $properties['image'];
633 if (!empty($visibleFileTitles)) {
634 $this->assertThat($responseSections, $this->getRequestSectionStructureHasRecordConstraint()
635 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('image')
636 ->setTable('sys_file_reference')->setField('title')->setValues(...$visibleFileTitles));
637 }
638 $this->assertThat($responseSections, $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
639 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('image')
640 ->setTable('sys_file_reference')->setField('title')->setValues(...$this->getNonVisibleFileTitles($visibleFileTitles)));
641 }
642
643 $content = json_decode($frontendResponse->getContent());
644 $this->assertEquals('[DK]Page', $content->Scope->page->title);
645 $this->assertEquals(1, $content->Scope->tsfe->sys_language_uid, 'sys_language_uid doesn\'t match');
646 $this->assertEquals(1, $content->Scope->tsfe->sys_language_content, 'sys_language_content doesn\'t match');
647 $this->assertEquals($sysLanguageMode, $content->Scope->tsfe->sys_language_mode, 'sys_language_mode doesn\t match');
648 $this->assertEquals($sysLanguageContentOL, $content->Scope->tsfe->sys_language_contentOL, 'sys_language_contentOL doesn\t match');
649 }
650
651 public function contentOnNonTranslatedPageDataProvider(): array
652 {
653 //Expected behaviour:
654 //the page is NOT translated so setting sys_language_mode to different values changes the results
655 //- setting sys_language_mode to empty value makes TYPO3 return default language records
656 //- setting it to strict throws 404, independently from other settings
657 //Setting config.sys_language_overlay = 0
658 return [
659 [
660 'typoScript' => 'config.sys_language_overlay = 0
661 config.sys_language_mode =',
662 'visibleRecords' => [
663 297 => [
664 'header' => 'Regular Element #1',
665 'image' => ['T3BOARD'],
666 ],
667 298 => [
668 'header' => 'Regular Element #2',
669 'image' => ['Kasper'],
670 ],
671 299 => [
672 'header' => 'Regular Element #3',
673 'image' => [],
674 ],
675 ],
676 'pageTitle' => 'Default language Page',
677 'sys_language_uid' => 0,
678 'sys_language_content' => 0,
679 'sys_language_mode' => '',
680 'sys_language_contentOL' => 0,
681 ],
682 [
683 'typoScript' => 'config.sys_language_overlay = 0
684 config.sys_language_mode = content_fallback',
685 'visibleRecords' => [
686 297 => [
687 'header' => 'Regular Element #1',
688 'image' => ['T3BOARD'],
689 ],
690 298 => [
691 'header' => 'Regular Element #2',
692 'image' => ['Kasper'],
693 ],
694 299 => [
695 'header' => 'Regular Element #3',
696 'image' => [],
697 ],
698 ],
699 'pageTitle' => 'Default language Page',
700 'sys_language_uid' => 2,
701 'sys_language_content' => 0,
702 'sys_language_mode' => 'content_fallback',
703 'sys_language_contentOL' => 0,
704 ],
705 [
706 'typoScript' => 'config.sys_language_overlay = 0
707 config.sys_language_mode = content_fallback;1,0',
708 'visibleRecords' => [
709 300 => [
710 'header' => '[Translate to Dansk:] Regular Element #3',
711 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
712 ],
713 301 => [
714 'header' => '[Translate to Dansk:] Regular Element #1',
715 'image' => [],
716 ],
717 303 => [
718 'header' => '[DK] Without default language',
719 'image' => ['[T3BOARD] Image added to DK elemet without default language'],
720 ],
721 308 => [
722 'header' => '[DK] UnHidden Element #4',
723 'image' => [],
724 ],
725 ],
726 'pageTitle' => 'Default language Page', //TODO: change it to "[DK]Page" once #81657 is fixed
727 'sys_language_uid' => 2,
728 'sys_language_content' => 1,
729 'sys_language_mode' => 'content_fallback',
730 'sys_language_contentOL' => 0,
731 ],
732 [
733 'typoScript' => 'config.sys_language_overlay = 0
734 config.sys_language_mode = strict',
735 'visibleRecords' => [],
736 'pageTitle' => '',
737 'sys_language_uid' => 2,
738 'sys_language_content' => 2,
739 'sys_language_mode' => 'strict',
740 'sys_language_contentOL' => 0,
741 'status' => 404,
742 ],
743 [
744 'typoScript' => 'config.sys_language_overlay = 0
745 config.sys_language_mode = ignore',
746 'visibleRecords' => [
747 302 => [
748 'header' => '[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1',
749 'image' => ['[T3BOARD] image translated to DE from DK'],
750 ],
751 304 => [
752 'header' => '[DE] Without default language',
753 'image' => [],
754 ],
755 ],
756 'pageTitle' => 'Default language Page',
757 'sys_language_uid' => 2,
758 'sys_language_content' => 2,
759 'sys_language_mode' => 'ignore',
760 'sys_language_contentOL' => 0,
761 ],
762 5 => [
763 'typoScript' => 'config.sys_language_overlay = 1
764 config.sys_language_mode =',
765 'visibleRecords' => [
766 297 => [
767 'header' => 'Regular Element #1',
768 'image' => ['T3BOARD'],
769 ],
770 298 => [
771 'header' => 'Regular Element #2',
772 'image' => ['Kasper'],
773 ],
774 299 => [
775 'header' => 'Regular Element #3',
776 'image' => [],
777 ],
778 ],
779 'pageTitle' => 'Default language Page',
780 'sys_language_uid' => 0,
781 'sys_language_content' => 0,
782 'sys_language_mode' => '',
783 'sys_language_contentOL' => 1,
784 ],
785 //falling back to default language
786 [
787 'typoScript' => 'config.sys_language_overlay = 1
788 config.sys_language_mode = content_fallback',
789 'visibleRecords' => [
790 297 => [
791 'header' => 'Regular Element #1',
792 'image' => ['T3BOARD'],
793 ],
794 298 => [
795 'header' => 'Regular Element #2',
796 'image' => ['Kasper'],
797 ],
798 299 => [
799 'header' => 'Regular Element #3',
800 'image' => [],
801 ],
802 ],
803 'pageTitle' => 'Default language Page',
804 'sys_language_uid' => 2,
805 'sys_language_content' => 0,
806 'sys_language_mode' => 'content_fallback',
807 'sys_language_contentOL' => 1,
808 ],
809 //Dutch elements are shown because of the content fallback 1,0 - first Dutch, then default language
810 //note that '[DK] Without default language' is NOT shown - due to overlays (fetch default language and overlay it with translations)
811 [
812 'typoScript' => 'config.sys_language_overlay = 1
813 config.sys_language_mode = content_fallback;1,0',
814 'visibleRecords' => [
815 297 => [
816 'header' => '[Translate to Dansk:] Regular Element #1',
817 'image' => [],
818 ],
819 298 => [
820 'header' => 'Regular Element #2',
821 'image' => ['Kasper'],
822 ],
823 299 => [
824 'header' => '[Translate to Dansk:] Regular Element #3',
825 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
826 ],
827 ],
828 'pageTitle' => 'Default language Page', //TODO: change it to "[DK]Page" once #81657 is fixed
829 'sys_language_uid' => 2,
830 'sys_language_content' => 1,
831 'sys_language_mode' => 'content_fallback',
832 'sys_language_contentOL' => 1,
833 ],
834 [
835 'typoScript' => 'config.sys_language_overlay = 1
836 config.sys_language_mode = strict',
837 'visibleRecords' => [],
838 'pageTitle' => '',
839 'sys_language_uid' => 2,
840 'sys_language_content' => 2,
841 'sys_language_mode' => 'strict',
842 'sys_language_contentOL' => 1,
843 'status' => 404
844 ],
845 [
846 'typoScript' => 'config.sys_language_overlay = 1
847 config.sys_language_mode = ignore',
848 'visibleRecords' => [
849 297 => [
850 'header' => '[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1',
851 'image' => ['[T3BOARD] image translated to DE from DK'],
852 ],
853 298 => [
854 'header' => 'Regular Element #2',
855 'image' => ['Kasper'],
856 ],
857 299 => [
858 'header' => 'Regular Element #3',
859 'image' => [],
860 ],
861 ],
862 'pageTitle' => 'Default language Page',
863 'sys_language_uid' => 2,
864 'sys_language_content' => 2,
865 'sys_language_mode' => 'ignore',
866 'sys_language_contentOL' => 1,
867 ],
868 10 => [
869 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
870 config.sys_language_mode =',
871 'visibleRecords' => [
872 297 => [
873 'header' => 'Regular Element #1',
874 'image' => ['T3BOARD'],
875 ],
876 298 => [
877 'header' => 'Regular Element #2',
878 'image' => ['Kasper'],
879 ],
880 299 => [
881 'header' => 'Regular Element #3',
882 'image' => [],
883 ],
884 ],
885 'pageTitle' => 'Default language Page',
886 'sys_language_uid' => 0,
887 'sys_language_content' => 0,
888 'sys_language_mode' => '',
889 'sys_language_contentOL' => 'hideNonTranslated',
890 ],
891 [
892 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
893 config.sys_language_mode = content_fallback',
894 'visibleRecords' => [
895 297 => [
896 'header' => 'Regular Element #1',
897 'image' => ['T3BOARD'],
898 ],
899 298 => [
900 'header' => 'Regular Element #2',
901 'image' => ['Kasper'],
902 ],
903 299 => [
904 'header' => 'Regular Element #3',
905 'image' => [],
906 ],
907 ],
908 'pageTitle' => 'Default language Page',
909 'sys_language_uid' => 2,
910 'sys_language_content' => 0,
911 'sys_language_mode' => 'content_fallback',
912 'sys_language_contentOL' => 'hideNonTranslated',
913 ],
914 [
915 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
916 config.sys_language_mode = content_fallback;1,0',
917 'visibleRecords' => [
918 297 => [
919 'header' => '[Translate to Dansk:] Regular Element #1',
920 'image' => [],
921 ],
922 299 => [
923 'header' => '[Translate to Dansk:] Regular Element #3',
924 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
925 ],
926 ],
927 'pageTitle' => 'Default language Page', //TODO: change it to "[DK]Page" once #81657 is fixed
928 'sys_language_uid' => 2,
929 'sys_language_content' => 1,
930 'sys_language_mode' => 'content_fallback',
931 'sys_language_contentOL' => 'hideNonTranslated',
932 ],
933 [
934 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
935 config.sys_language_mode = strict',
936 'visibleRecords' => [],
937 'pageTitle' => '',
938 'sys_language_uid' => 2,
939 'sys_language_content' => 2,
940 'sys_language_mode' => 'strict',
941 'sys_language_contentOL' => 'hideNonTranslated',
942 'status' => 404,
943 ],
944 [
945 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
946 config.sys_language_mode = ignore',
947 'visibleRecords' => [
948 297 => [
949 'header' => '[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1',
950 'image' => ['[T3BOARD] image translated to DE from DK'],
951 ],
952 ],
953 'pageTitle' => 'Default language Page',
954 'sys_language_uid' => 2,
955 'sys_language_content' => 2,
956 'sys_language_mode' => 'ignore',
957 'sys_language_contentOL' => 'hideNonTranslated',
958 ],
959 ];
960 }
961
962 /**
963 * Page uid 89 is NOT translated to german
964 *
965 * @test
966 * @dataProvider contentOnNonTranslatedPageDataProvider
967 *
968 * @param string $typoScript
969 * @param array $visibleRecords
970 * @param string $pageTitle
971 * @param int $sysLanguageUid
972 * @param int $sysLanguageContent
973 * @param string $sysLanguageMode
974 * @param string $sysLanguageContentOL
975 * @param string $status 'success' or 404
976 */
977 public function contentOnNonTranslatedPageGerman(string $typoScript, array $visibleRecords, string $pageTitle, int $sysLanguageUid, int $sysLanguageContent, string $sysLanguageMode, string $sysLanguageContentOL, string $status='success')
978 {
979 $this->addTypoScriptToTemplateRecord(1, $typoScript);
980 $visibleHeaders = array_map(function ($element) {
981 return $element['header'];
982 }, $visibleRecords);
983
984 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 2);
985 if ($status === Response::STATUS_Success) {
986 $responseSections = $frontendResponse->getResponseSections();
987 $this->assertThat(
988 $responseSections,
989 $this->getRequestSectionHasRecordConstraint()
990 ->setTable(self::TABLE_Content)
991 ->setField('header')
992 ->setValues(...$visibleHeaders)
993 );
994 $this->assertThat(
995 $responseSections,
996 $this->getRequestSectionDoesNotHaveRecordConstraint()
997 ->setTable(self::TABLE_Content)
998 ->setField('header')
999 ->setValues(...$this->getNonVisibleHeaders($visibleHeaders))
1000 );
1001
1002 foreach ($visibleRecords as $ttContentUid => $properties) {
1003 $visibleFileTitles = $properties['image'];
1004 if (!empty($visibleFileTitles)) {
1005 $this->assertThat($responseSections, $this->getRequestSectionStructureHasRecordConstraint()
1006 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('image')
1007 ->setTable('sys_file_reference')->setField('title')->setValues(...$visibleFileTitles));
1008 }
1009 $this->assertThat($responseSections, $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
1010 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('image')
1011 ->setTable('sys_file_reference')->setField('title')->setValues(...$this->getNonVisibleFileTitles($visibleFileTitles)));
1012 }
1013
1014 $content = json_decode($frontendResponse->getContent());
1015 $this->assertEquals($pageTitle, $content->Scope->page->title);
1016 $this->assertEquals($sysLanguageUid, $content->Scope->tsfe->sys_language_uid, 'sys_language_uid doesn\'t match');
1017 $this->assertEquals($sysLanguageContent, $content->Scope->tsfe->sys_language_content, 'sys_language_content doesn\'t match');
1018 $this->assertEquals($sysLanguageMode, $content->Scope->tsfe->sys_language_mode, 'sys_language_mode doesn\t match');
1019 $this->assertEquals($sysLanguageContentOL, $content->Scope->tsfe->sys_language_contentOL, 'sys_language_contentOL doesn\t match');
1020 }
1021 //some configuration combinations results in 404, in that case status will be set to 404
1022 $this->assertEquals($status, $frontendResponse->getStatus());
1023 }
1024
1025 public function contentOnPartiallyTranslatedPageDataProvider(): array
1026 {
1027
1028 //Expected behaviour:
1029 //Setting sys_language_mode to different values doesn't influence the result as the requested page is translated to Polish,
1030 //Page title is always [PL]Page, and both sys_language_content and sys_language_uid are always 3
1031 return [
1032 [
1033 'typoScript' => 'config.sys_language_overlay = 0
1034 config.sys_language_mode =',
1035 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
1036 'sys_language_mode' => '',
1037 'sys_language_contentOL' => 0
1038 ],
1039 [
1040 'typoScript' => 'config.sys_language_overlay = 0
1041 config.sys_language_mode = content_fallback',
1042 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
1043 'sys_language_mode' => 'content_fallback',
1044 'sys_language_contentOL' => 0
1045 ],
1046 [
1047 'typoScript' => 'config.sys_language_overlay = 0
1048 config.sys_language_mode = content_fallback;1,0',
1049 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
1050 'sys_language_mode' => 'content_fallback',
1051 'sys_language_contentOL' => 0
1052 ],
1053 [
1054 'typoScript' => 'config.sys_language_overlay = 0
1055 config.sys_language_mode = strict',
1056 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
1057 'sys_language_mode' => 'strict',
1058 'sys_language_contentOL' => 0
1059 ],
1060 [
1061 'typoScript' => 'config.sys_language_overlay = 0
1062 config.sys_language_mode = ignore',
1063 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
1064 'sys_language_mode' => 'ignore',
1065 'sys_language_contentOL' => 0
1066 ],
1067 5 => [
1068 'typoScript' => 'config.sys_language_overlay = 1
1069 config.sys_language_mode =',
1070 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
1071 'sys_language_mode' => '',
1072 'sys_language_contentOL' => 1
1073 ],
1074 // Expected behaviour:
1075 // Not translated element #2 is shown because sys_language_overlay = 1 (with sys_language_overlay = hideNonTranslated, it would be hidden)
1076 [
1077 'typoScript' => 'config.sys_language_overlay = 1
1078 config.sys_language_mode = content_fallback',
1079 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
1080 'sys_language_mode' => 'content_fallback',
1081 'sys_language_contentOL' => 1
1082 ],
1083 // Expected behaviour:
1084 // 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
1085 // but on page level - and this page is translated to Polish, so no fallback is happening
1086 [
1087 'typoScript' => 'config.sys_language_overlay = 1
1088 config.sys_language_mode = content_fallback;1,0',
1089 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
1090 'sys_language_mode' => 'content_fallback',
1091 'sys_language_contentOL' => 1
1092 ],
1093 [
1094 'typoScript' => 'config.sys_language_overlay = 1
1095 config.sys_language_mode = strict',
1096 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
1097 'sys_language_mode' => 'strict',
1098 'sys_language_contentOL' => 1
1099 ],
1100 [
1101 'typoScript' => 'config.sys_language_overlay = 1
1102 config.sys_language_mode = ignore',
1103 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
1104 'sys_language_mode' => 'ignore',
1105 'sys_language_contentOL' => 1
1106 ],
1107 // Expected behaviour:
1108 // Non translated default language elements are not shown, because of hideNonTranslated
1109 10 => [
1110 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
1111 config.sys_language_mode =',
1112 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1'],
1113 'sys_language_mode' => '',
1114 'sys_language_contentOL' => 'hideNonTranslated'
1115 ],
1116 [
1117 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
1118 config.sys_language_mode = content_fallback',
1119 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1'],
1120 'sys_language_mode' => 'content_fallback',
1121 'sys_language_contentOL' => 'hideNonTranslated'
1122 ],
1123 [
1124 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
1125 config.sys_language_mode = content_fallback;1,0',
1126 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1'],
1127 'sys_language_mode' => 'content_fallback',
1128 'sys_language_contentOL' => 'hideNonTranslated'
1129 ],
1130 [
1131 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
1132 config.sys_language_mode = strict',
1133 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1'],
1134 'sys_language_mode' => 'strict',
1135 'sys_language_contentOL' => 'hideNonTranslated'
1136 ],
1137 [
1138 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
1139 config.sys_language_mode = ignore',
1140 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1'],
1141 'sys_language_mode' => 'ignore',
1142 'sys_language_contentOL' => 'hideNonTranslated'
1143 ]
1144 ];
1145 }
1146
1147 /**
1148 * Page uid 89 is translated to to Polish, but not all CE are translated
1149 *
1150 * @test
1151 * @dataProvider contentOnPartiallyTranslatedPageDataProvider
1152 *
1153 * @param string $typoScript
1154 * @param array $visibleHeaders
1155 * @param string $sysLanguageMode
1156 * @param string $sysLanguageContentOL
1157 */
1158 public function contentOnPartiallyTranslatedPage(string $typoScript, array $visibleHeaders, string $sysLanguageMode, string $sysLanguageContentOL)
1159 {
1160 $this->addTypoScriptToTemplateRecord(1, $typoScript);
1161
1162 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 3);
1163 $this->assertEquals('success', $frontendResponse->getStatus());
1164 $responseSections = $frontendResponse->getResponseSections();
1165
1166 $this->assertThat(
1167 $responseSections,
1168 $this->getRequestSectionHasRecordConstraint()
1169 ->setTable(self::TABLE_Content)
1170 ->setField('header')
1171 ->setValues(...$visibleHeaders)
1172 );
1173 $this->assertThat(
1174 $responseSections,
1175 $this->getRequestSectionDoesNotHaveRecordConstraint()
1176 ->setTable(self::TABLE_Content)
1177 ->setField('header')
1178 ->setValues(...$this->getNonVisibleHeaders($visibleHeaders))
1179 );
1180
1181 $content = json_decode($frontendResponse->getContent());
1182 $this->assertEquals('[PL]Page', $content->Scope->page->title);
1183 $this->assertEquals(3, $content->Scope->tsfe->sys_language_uid, 'sys_language_uid doesn\'t match');
1184 $this->assertEquals(3, $content->Scope->tsfe->sys_language_content, 'sys_language_content doesn\'t match');
1185 $this->assertEquals($sysLanguageMode, $content->Scope->tsfe->sys_language_mode, 'sys_language_mode doesn\t match');
1186 $this->assertEquals($sysLanguageContentOL, $content->Scope->tsfe->sys_language_contentOL, 'sys_language_contentOL doesn\t match');
1187 }
1188
1189 /**
1190 * Helper function to ease asserting that rest of the data set is not visible
1191 *
1192 * @param array $visibleHeaders
1193 * @return array
1194 */
1195 protected function getNonVisibleHeaders(array $visibleHeaders): array
1196 {
1197 $allElements = [
1198 'Regular Element #1',
1199 'Regular Element #2',
1200 'Regular Element #3',
1201 'Hidden Element #4',
1202 '[Translate to Dansk:] Regular Element #1',
1203 '[Translate to Dansk:] Regular Element #3',
1204 '[DK] Without default language',
1205 '[DK] UnHidden Element #4',
1206 '[DE] Without default language',
1207 '[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1',
1208 '[Translate to Polski:] Regular Element #1',
1209 '[PL] Without default language',
1210 '[PL] Hidden Regular Element #2'
1211 ];
1212 return array_diff($allElements, $visibleHeaders);
1213 }
1214
1215 /**
1216 * Helper function to ease asserting that rest of the files are not present
1217 *
1218 * @param array $visibleTitles
1219 * @return array
1220 */
1221 protected function getNonVisibleFileTitles(array $visibleTitles): array
1222 {
1223 $allElements = [
1224 'T3BOARDD',
1225 'Kasper',
1226 '[Kasper] Image translated to Dansk',
1227 '[T3BOARD] Image added in Dansk (without parent)',
1228 '[T3BOARD] Image added to DK elemet without default language',
1229 '[T3BOARD] image translated to DE from DK',
1230 ];
1231 return array_diff($allElements, $visibleTitles);
1232 }
1233
1234 /**
1235 * Adds TypoScript setup snippet to the existing template record
1236 *
1237 * @param int $pageId
1238 * @param string $typoScript
1239 */
1240 protected function addTypoScriptToTemplateRecord(int $pageId, string $typoScript)
1241 {
1242 $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_template');
1243
1244 $template = $connection->select(['*'], 'sys_template', ['pid' => $pageId, 'root' => 1])->fetch();
1245 if (empty($template)) {
1246 $this->fail('Cannot find root template on page with id: "' . $pageId . '"');
1247 }
1248 $updateFields['config'] = $template['config'] . LF . $typoScript;
1249 $connection->update(
1250 'sys_template',
1251 $updateFields,
1252 ['uid' => $template['uid']]
1253 );
1254 }
1255 }