[TASK] Add functional tests for rendering translated tt_content with FAL
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Functional / Persistence / TranslatedContentTest.php
1 <?php
2 declare(strict_types=1);
3
4 namespace TYPO3\CMS\Extbase\Tests\Functional\Persistence;
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 * This test is an Extbase version of the \TYPO3\CMS\Frontend\Tests\Functional\Rendering\LocalizedContentRenderingTest
25 * scenarios are the same, just a way of fetching content is different
26 *
27 * This test documents current behaviour of extbase which is inconsistent with TypoScript rendering of tt_content.
28 */
29 class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase
30 {
31 const VALUE_PageId = 89;
32 const TABLE_Content = 'tt_content';
33 const TABLE_Pages = 'pages';
34
35 /**
36 * @var string
37 */
38 protected $scenarioDataSetDirectory = 'typo3/sysext/frontend/Tests/Functional/Rendering/DataSet/';
39
40 /**
41 * @var array
42 */
43 protected $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
44
45 /**
46 * @var array
47 */
48 protected $coreExtensionsToLoad = ['extbase', 'fluid'];
49
50 /**
51 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface The object manager
52 */
53 protected $objectManager;
54
55 /**
56 * @var \ExtbaseTeam\BlogExample\Domain\Repository\TtContentRepository
57 */
58 protected $contentRepository;
59
60 /**
61 * Custom 404 handler returning valid json is registered so the $this->getFrontendResponse()
62 * does not fail on 404 pages
63 *
64 * @var array
65 */
66 protected $configurationToUseInTestInstance = [
67 'FE' => [
68 'pageNotFound_handling' => 'READFILE:typo3/sysext/frontend/Tests/Functional/Rendering/DataSet/404Template.html'
69 ]
70 ];
71
72 /**
73 * @var array
74 */
75 protected $pathsToLinkInTestInstance = [
76 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/AdditionalConfiguration.php' => 'typo3conf/AdditionalConfiguration.php',
77 'typo3/sysext/frontend/Tests/Functional/Fixtures/Images' => 'fileadmin/user_upload'
78 ];
79
80 protected function setUp()
81 {
82 parent::setUp();
83 $this->importScenarioDataSet('LiveDefaultPages');
84 $this->importScenarioDataSet('LiveDefaultElements');
85
86 $this->backendUser->workspace = 0;
87 $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
88 $this->contentRepository = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Repository\TtContentRepository::class);
89 $this->setUpFrontendRootPage(1, [
90 'typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TypoScript/setup.txt',
91 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/Frontend/ContentJsonRenderer.ts'
92
93 ]);
94 }
95
96 public function defaultLanguageConfigurationDataProvider(): array
97 {
98 return [
99 [
100 'typoScript' => 'config.sys_language_overlay = 0
101 config.sys_language_mode =',
102 ],
103 [
104 'typoScript' => 'config.sys_language_overlay = 0
105 config.sys_language_mode = content_fallback',
106 ],
107 [
108 'typoScript' => 'config.sys_language_overlay = 0
109 config.sys_language_mode = content_fallback;1,0',
110 ],
111 [
112 'typoScript' => 'config.sys_language_overlay = 0
113 config.sys_language_mode = strict',
114 ],
115 [
116 'typoScript' => 'config.sys_language_overlay = 0
117 config.sys_language_mode = ignore',
118 ],
119 [
120 'typoScript' => 'config.sys_language_overlay = 1
121 config.sys_language_mode =',
122 ],
123 [
124 'typoScript' => 'config.sys_language_overlay = 1
125 config.sys_language_mode = content_fallback',
126 ],
127 [
128 'typoScript' => 'config.sys_language_overlay = 1
129 config.sys_language_mode = content_fallback;1,0',
130 ],
131 [
132 'typoScript' => 'config.sys_language_overlay = 1
133 config.sys_language_mode = strict',
134 ],
135 [
136 'typoScript' => 'config.sys_language_overlay = 1
137 config.sys_language_mode = ignore',
138 ],
139 [
140 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
141 config.sys_language_mode =',
142 ],
143 [
144 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
145 config.sys_language_mode = content_fallback',
146 ],
147 [
148 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
149 config.sys_language_mode = content_fallback;1,0',
150 ],
151 [
152 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
153 config.sys_language_mode = strict',
154 ],
155 [
156 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
157 config.sys_language_mode = ignore',
158 ],
159 ];
160 }
161
162 /**
163 * For the default language all combination of language settings should give the same result,
164 * regardless of TypoScript settings, if the requested language is "0" then no TypoScript settings apply.
165 *
166 * @test
167 * @dataProvider defaultLanguageConfigurationDataProvider
168 *
169 * @param string $typoScript
170 */
171 public function onlyEnglishContentIsRenderedForDefaultLanguage(string $typoScript)
172 {
173 $this->addTypoScriptToTemplateRecord(1, $typoScript);
174
175 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 0);
176 $responseSections = $frontendResponse->getResponseSections('Extbase:list()');
177 $visibleHeaders = ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'];
178 $this->assertThat(
179 $responseSections,
180 $this->getRequestSectionHasRecordConstraint()
181 ->setTable(self::TABLE_Content)
182 ->setField('header')
183 ->setValues(...$visibleHeaders)
184 );
185 $this->assertThat(
186 $responseSections,
187 $this->getRequestSectionDoesNotHaveRecordConstraint()
188 ->setTable(self::TABLE_Content)
189 ->setField('header')
190 ->setValues(...$this->getNonVisibleHeaders($visibleHeaders))
191 );
192 }
193
194 /**
195 * Dutch language has pages_language_overlay record and some content elements are translated
196 *
197 * @return array
198 */
199 public function dutchDataProvider(): array
200 {
201 //Expected behaviour:
202 //Page is translated to Dutch, so changing sys_language_mode does NOT change the results
203 //Page title is always [DK]Page, and both sys_language_content and sys_language_uid are always 1
204 return [
205 [
206 'typoScript' => 'config.sys_language_overlay = 0
207 config.sys_language_mode =',
208 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language', 'Regular Element #2', '[DK] UnHidden Element #4'],
209 ],
210 [
211 'typoScript' => 'config.sys_language_overlay = 0
212 config.sys_language_mode = content_fallback',
213 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language', 'Regular Element #2', '[DK] UnHidden Element #4'],
214 ],
215 [
216 'typoScript' => 'config.sys_language_overlay = 0
217 config.sys_language_mode = content_fallback;1,0',
218 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language', 'Regular Element #2', '[DK] UnHidden Element #4'],
219 ],
220 [
221 'typoScript' => 'config.sys_language_overlay = 0
222 config.sys_language_mode = strict',
223 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language'],
224 ],
225 [
226 'typoScript' => 'config.sys_language_overlay = 0
227 config.sys_language_mode = ignore',
228 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language', 'Regular Element #2', '[DK] UnHidden Element #4'],
229 ],
230 5 => [
231 'typoScript' => 'config.sys_language_overlay = 1
232 config.sys_language_mode =',
233 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language', '[DK] UnHidden Element #4'],
234 ],
235 // Expected behaviour:
236 // Not translated element #2 is shown because sys_language_overlay = 1 (with sys_language_overlay = hideNonTranslated, it would be hidden)
237 [
238 'typoScript' => 'config.sys_language_overlay = 1
239 config.sys_language_mode = content_fallback',
240 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language', '[DK] UnHidden Element #4'],
241 ],
242 // Expected behaviour:
243 // Same as config.sys_language_mode = content_fallback because we're requesting language 1, so no additional fallback possible
244
245 [
246 'typoScript' => 'config.sys_language_overlay = 1
247 config.sys_language_mode = content_fallback;1,0',
248 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language', '[DK] UnHidden Element #4'],
249 ],
250 [
251 'typoScript' => 'config.sys_language_overlay = 1
252 config.sys_language_mode = strict',
253 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language'],
254 ],
255 [
256 'typoScript' => 'config.sys_language_overlay = 1
257 config.sys_language_mode = ignore',
258 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language', '[DK] UnHidden Element #4'],
259 ],
260 // Expected behaviour:
261 // Non translated default language elements are not shown, because of hideNonTranslated
262 10 => [
263 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
264 config.sys_language_mode =',
265 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language', '[DK] UnHidden Element #4'],
266 ],
267 [
268 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
269 config.sys_language_mode = content_fallback',
270 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language', '[DK] UnHidden Element #4'],
271 ],
272 [
273 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
274 config.sys_language_mode = content_fallback;1,0',
275 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language', '[DK] UnHidden Element #4'],
276 ],
277 // Setting sys_language_mode = strict has the same effect as previous data sets, because the translation of the page exists
278 [
279 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
280 config.sys_language_mode = strict',
281 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language'],
282 ],
283 [
284 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
285 config.sys_language_mode = ignore',
286 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language', '[DK] UnHidden Element #4'],
287 ],
288 ];
289 }
290
291 /**
292 * @test
293 * @dataProvider dutchDataProvider
294 *
295 * @param string $typoScript
296 * @param array $visibleHeaders
297 */
298 public function renderingOfDutchLanguage(string $typoScript, array $visibleHeaders)
299 {
300 $this->addTypoScriptToTemplateRecord(1, $typoScript);
301 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 1);
302 $responseSections = $frontendResponse->getResponseSections('Extbase:list()');
303 $this->assertThat(
304 $responseSections,
305 $this->getRequestSectionHasRecordConstraint()
306 ->setTable(self::TABLE_Content)
307 ->setField('header')
308 ->setValues(...$visibleHeaders)
309 );
310 $this->assertThat(
311 $responseSections,
312 $this->getRequestSectionDoesNotHaveRecordConstraint()
313 ->setTable(self::TABLE_Content)
314 ->setField('header')
315 ->setValues(...$this->getNonVisibleHeaders($visibleHeaders))
316 );
317 }
318
319 public function contentOnNonTranslatedPageDataProvider(): array
320 {
321 //Expected behaviour:
322 //the page is NOT translated so setting sys_language_mode to different values changes the results
323 //- setting sys_language_mode to empty value makes TYPO3 return default language records
324 //- setting it to strict throws 404, independently from other settings
325 //Setting config.sys_language_overlay = 0
326 return [
327 [
328 'typoScript' => 'config.sys_language_overlay = 0
329 config.sys_language_mode =',
330 'visibleRecordHeaders' => ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
331 ],
332 [
333 'typoScript' => 'config.sys_language_overlay = 0
334 config.sys_language_mode = content_fallback',
335 'visibleRecordHeaders' => ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
336 ],
337 [
338 'typoScript' => 'config.sys_language_overlay = 0
339 config.sys_language_mode = content_fallback;1,0',
340 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3', '[DK] UnHidden Element #4', '[DK] Without default language'],
341 ],
342 [
343 'typoScript' => 'config.sys_language_overlay = 0
344 config.sys_language_mode = strict',
345 'visibleRecordHeaders' => [],
346 'status' => 404,
347 ],
348 [
349 'typoScript' => 'config.sys_language_overlay = 0
350 config.sys_language_mode = ignore',
351 'visibleRecordHeaders' => ['[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1', 'Regular Element #2', 'Regular Element #3', '[DE] Without default language'],
352 ],
353 5 => [
354 'typoScript' => 'config.sys_language_overlay = 1
355 config.sys_language_mode =',
356 'visibleRecordHeaders' => ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
357 ],
358 //falling back to default language
359 [
360 'typoScript' => 'config.sys_language_overlay = 1
361 config.sys_language_mode = content_fallback',
362 'visibleRecordHeaders' => ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
363 ],
364 //Dutch elements are shown because of the content fallback 1,0 - first Dutch, then default language
365 //note that '[DK] Without default language' is NOT shown - due to overlays (fetch default language and overlay it with translations)
366 [
367 'typoScript' => 'config.sys_language_overlay = 1
368 config.sys_language_mode = content_fallback;1,0',
369 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', 'Regular Element #2', '[Translate to Dansk:] Regular Element #3', '[DK] Without default language', '[DK] UnHidden Element #4'],
370 ],
371 [
372 'typoScript' => 'config.sys_language_overlay = 1
373 config.sys_language_mode = strict',
374 'visibleRecordHeaders' => [],
375 'status' => 404
376 ],
377 [
378 'typoScript' => 'config.sys_language_overlay = 1
379 config.sys_language_mode = ignore',
380 'visibleRecordHeaders' => ['[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1', 'Regular Element #2', 'Regular Element #3', '[DE] Without default language'],
381 ],
382 10 => [
383 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
384 config.sys_language_mode =',
385 'visibleRecordHeaders' => ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
386 ],
387 [
388 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
389 config.sys_language_mode = content_fallback',
390 'visibleRecordHeaders' => ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
391 ],
392 [
393 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
394 config.sys_language_mode = content_fallback;1,0',
395 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3', 'Regular Element #2', '[DK] Without default language', '[DK] UnHidden Element #4'],
396 ],
397 [
398 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
399 config.sys_language_mode = strict',
400 'visibleRecordHeaders' => [],
401 'status' => 404,
402 ],
403 [
404 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
405 config.sys_language_mode = ignore',
406 'visibleRecordHeaders' => ['[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1', 'Regular Element #2', 'Regular Element #3', '[DE] Without default language'],
407 ],
408 ];
409 }
410
411 /**
412 * Page uid 89 is NOT translated to german
413 *
414 * @test
415 * @dataProvider contentOnNonTranslatedPageDataProvider
416 *
417 * @param string $typoScript
418 * @param array $visibleHeaders
419 * @param string $status 'success' or 404
420 */
421 public function contentOnNonTranslatedPageGerman(string $typoScript, array $visibleHeaders, string $status='success')
422 {
423 $this->addTypoScriptToTemplateRecord(1, $typoScript);
424
425 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 2);
426 if ($status === Response::STATUS_Success) {
427 $responseSections = $frontendResponse->getResponseSections('Extbase:list()');
428 $this->assertThat(
429 $responseSections,
430 $this->getRequestSectionHasRecordConstraint()
431 ->setTable(self::TABLE_Content)
432 ->setField('header')
433 ->setValues(...$visibleHeaders)
434 );
435 $this->assertThat(
436 $responseSections,
437 $this->getRequestSectionDoesNotHaveRecordConstraint()
438 ->setTable(self::TABLE_Content)
439 ->setField('header')
440 ->setValues(...$this->getNonVisibleHeaders($visibleHeaders))
441 );
442 }
443 //some configuration combinations results in 404, in that case status will be set to 404
444 $this->assertEquals($status, $frontendResponse->getStatus());
445 }
446
447 public function contentOnPartiallyTranslatedPageDataProvider(): array
448 {
449
450 //Expected behaviour:
451 //Setting sys_language_mode to different values doesn't influence the result as the requested page is translated to Polish,
452 //Page title is always [PL]Page, and both sys_language_content and sys_language_uid are always 3
453 return [
454 [
455 'typoScript' => 'config.sys_language_overlay = 0
456 config.sys_language_mode =',
457 'visibleRecordHeaders' => ['Regular Element #3', '[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
458 ],
459 [
460 'typoScript' => 'config.sys_language_overlay = 0
461 config.sys_language_mode = content_fallback',
462 'visibleRecordHeaders' => ['Regular Element #3', '[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
463 ],
464 [
465 'typoScript' => 'config.sys_language_overlay = 0
466 config.sys_language_mode = content_fallback;1,0',
467 'visibleRecordHeaders' => ['Regular Element #3', '[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
468 ],
469 [
470 'typoScript' => 'config.sys_language_overlay = 0
471 config.sys_language_mode = strict',
472 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
473 ],
474 [
475 'typoScript' => 'config.sys_language_overlay = 0
476 config.sys_language_mode = ignore',
477 'visibleRecordHeaders' => ['Regular Element #3', '[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
478 ],
479 5 => [
480 'typoScript' => 'config.sys_language_overlay = 1
481 config.sys_language_mode =',
482 'visibleRecordHeaders' => ['[PL] Without default language', '[Translate to Polski:] Regular Element #1', 'Regular Element #3'],
483 ],
484 // Expected behaviour:
485 // Not translated element #2 is shown because sys_language_overlay = 1 (with sys_language_overlay = hideNonTranslated, it would be hidden)
486 [
487 'typoScript' => 'config.sys_language_overlay = 1
488 config.sys_language_mode = content_fallback',
489 'visibleRecordHeaders' => ['[PL] Without default language', '[Translate to Polski:] Regular Element #1', 'Regular Element #3'],
490 ],
491 // Expected behaviour:
492 // 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
493 // but on page level - and this page is translated to Polish, so no fallback is happening
494 [
495 'typoScript' => 'config.sys_language_overlay = 1
496 config.sys_language_mode = content_fallback;1,0',
497 'visibleRecordHeaders' => ['[PL] Without default language', '[Translate to Polski:] Regular Element #1', 'Regular Element #3'],
498 ],
499 [
500 'typoScript' => 'config.sys_language_overlay = 1
501 config.sys_language_mode = strict',
502 'visibleRecordHeaders' => ['[PL] Without default language', '[Translate to Polski:] Regular Element #1'],
503 ],
504 [
505 'typoScript' => 'config.sys_language_overlay = 1
506 config.sys_language_mode = ignore',
507 'visibleRecordHeaders' => ['[PL] Without default language', '[Translate to Polski:] Regular Element #1', 'Regular Element #3'],
508 ],
509 // Expected behaviour:
510 // Non translated default language elements are not shown, because of hideNonTranslated
511 10 => [
512 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
513 config.sys_language_mode =',
514 'visibleRecordHeaders' => ['[PL] Without default language', 'Regular Element #3', '[Translate to Polski:] Regular Element #1'],
515 ],
516 [
517 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
518 config.sys_language_mode = content_fallback',
519 'visibleRecordHeaders' => ['[PL] Without default language', 'Regular Element #3', '[Translate to Polski:] Regular Element #1'],
520 ],
521 [
522 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
523 config.sys_language_mode = content_fallback;1,0',
524 'visibleRecordHeaders' => ['[PL] Without default language', 'Regular Element #3', '[Translate to Polski:] Regular Element #1'],
525 ],
526 [
527 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
528 config.sys_language_mode = strict',
529 'visibleRecordHeaders' => ['[PL] Without default language', '[Translate to Polski:] Regular Element #1'],
530 ],
531 [
532 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
533 config.sys_language_mode = ignore',
534 'visibleRecordHeaders' => ['[PL] Without default language', 'Regular Element #3', '[Translate to Polski:] Regular Element #1'],
535 ]
536 ];
537 }
538
539 /**
540 * Page uid 89 is translated to to Polish, but not all CE are translated
541 *
542 * @test
543 * @dataProvider contentOnPartiallyTranslatedPageDataProvider
544 *
545 * @param string $typoScript
546 * @param array $visibleHeaders
547 */
548 public function contentOnPartiallyTranslatedPage(string $typoScript, array $visibleHeaders)
549 {
550 $this->addTypoScriptToTemplateRecord(1, $typoScript);
551
552 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 3);
553 $this->assertEquals('success', $frontendResponse->getStatus());
554 $responseSections = $frontendResponse->getResponseSections('Extbase:list()');
555
556 $this->assertThat(
557 $responseSections,
558 $this->getRequestSectionHasRecordConstraint()
559 ->setTable(self::TABLE_Content)
560 ->setField('header')
561 ->setValues(...$visibleHeaders)
562 );
563 $this->assertThat(
564 $responseSections,
565 $this->getRequestSectionDoesNotHaveRecordConstraint()
566 ->setTable(self::TABLE_Content)
567 ->setField('header')
568 ->setValues(...$this->getNonVisibleHeaders($visibleHeaders))
569 );
570 }
571
572 /**
573 * Helper function to ease asserting that rest of the data set is not visible
574 *
575 * @param array $visibleHeaders
576 * @return array
577 */
578 protected function getNonVisibleHeaders(array $visibleHeaders): array
579 {
580 $allElements = [
581 'Regular Element #1',
582 'Regular Element #2',
583 'Regular Element #3',
584 'Hidden Element #4',
585 '[Translate to Dansk:] Regular Element #1',
586 '[Translate to Dansk:] Regular Element #3',
587 '[DK] Without default language',
588 '[DK] UnHidden Element #4',
589 '[DE] Without default language',
590 '[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1',
591 '[Translate to Polski:] Regular Element #1',
592 '[PL] Without default language',
593 '[PL] Hidden Regular Element #2'
594 ];
595 return array_diff($allElements, $visibleHeaders);
596 }
597
598 /**
599 * Adds TypoScript setup snippet to the existing template record
600 *
601 * @param int $pageId
602 * @param string $typoScript
603 */
604 protected function addTypoScriptToTemplateRecord(int $pageId, string $typoScript)
605 {
606 $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_template');
607
608 $template = $connection->select(['*'], 'sys_template', ['pid' => $pageId, 'root' => 1])->fetch();
609 if (empty($template)) {
610 $this->fail('Cannot find root template on page with id: "' . $pageId . '"');
611 }
612 $updateFields['config'] = $template['config'] . LF . $typoScript;
613 $connection->update(
614 'sys_template',
615 $updateFields,
616 ['uid' => $template['uid']]
617 );
618 }
619 }