[TASK] Tests for rendering tt_content with FAL in Extbase
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Functional / Persistence / TranslatedContentTest.php
1 <?php
2
3 namespace TYPO3\CMS\Extbase\Tests\Functional\Persistence;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Core\Database\ConnectionPool;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Response;
21
22 /**
23 * This test is an Extbase version of the \TYPO3\CMS\Frontend\Tests\Functional\Rendering\LocalizedContentRenderingTest
24 * scenarios are the same, just a way of fetching content is different
25 *
26 * This test documents current behaviour of extbase which is inconsistent with TypoScript rendering of tt_content.
27 */
28 class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase
29 {
30 const VALUE_PageId = 89;
31 const TABLE_Content = 'tt_content';
32 const TABLE_Pages = 'pages';
33
34 /**
35 * @var string
36 */
37 protected $scenarioDataSetDirectory = 'typo3/sysext/frontend/Tests/Functional/Rendering/DataSet/';
38
39 /**
40 * @var array
41 */
42 protected $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
43
44 /**
45 * @var array
46 */
47 protected $coreExtensionsToLoad = ['extbase', 'fluid'];
48
49 /**
50 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface The object manager
51 */
52 protected $objectManager;
53
54 /**
55 * @var \ExtbaseTeam\BlogExample\Domain\Repository\TtContentRepository
56 */
57 protected $contentRepository;
58
59 /**
60 * Custom 404 handler returning valid json is registered so the $this->getFrontendResponse()
61 * does not fail on 404 pages
62 *
63 * @var array
64 */
65 protected $configurationToUseInTestInstance = [
66 'FE' => [
67 'pageNotFound_handling' => 'READFILE:typo3/sysext/frontend/Tests/Functional/Rendering/DataSet/404Template.html'
68 ]
69 ];
70
71 /**
72 * @var array
73 */
74 protected $pathsToLinkInTestInstance = [
75 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/AdditionalConfiguration.php' => 'typo3conf/AdditionalConfiguration.php',
76 'typo3/sysext/frontend/Tests/Functional/Fixtures/Images' => 'fileadmin/user_upload'
77 ];
78
79 protected function setUp()
80 {
81 parent::setUp();
82 $this->importScenarioDataSet('LiveDefaultPages');
83 $this->importScenarioDataSet('LiveDefaultElements');
84
85 $this->backendUser->workspace = 0;
86 $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
87 $this->contentRepository = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Repository\TtContentRepository::class);
88 $this->setUpFrontendRootPage(1, [
89 'typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TypoScript/setup.txt',
90 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/Frontend/ContentJsonRenderer.ts'
91 ]);
92 }
93
94 public function defaultLanguageConfigurationDataProvider()
95 {
96 return [
97 [
98 'typoScript' => 'config.sys_language_overlay = 0
99 config.sys_language_mode =',
100 ],
101 [
102 'typoScript' => 'config.sys_language_overlay = 0
103 config.sys_language_mode = content_fallback',
104 ],
105 [
106 'typoScript' => 'config.sys_language_overlay = 0
107 config.sys_language_mode = content_fallback;1,0',
108 ],
109 [
110 'typoScript' => 'config.sys_language_overlay = 0
111 config.sys_language_mode = strict',
112 ],
113 [
114 'typoScript' => 'config.sys_language_overlay = 0
115 config.sys_language_mode = ignore',
116 ],
117 [
118 'typoScript' => 'config.sys_language_overlay = 1
119 config.sys_language_mode =',
120 ],
121 [
122 'typoScript' => 'config.sys_language_overlay = 1
123 config.sys_language_mode = content_fallback',
124 ],
125 [
126 'typoScript' => 'config.sys_language_overlay = 1
127 config.sys_language_mode = content_fallback;1,0',
128 ],
129 [
130 'typoScript' => 'config.sys_language_overlay = 1
131 config.sys_language_mode = strict',
132 ],
133 [
134 'typoScript' => 'config.sys_language_overlay = 1
135 config.sys_language_mode = ignore',
136 ],
137 [
138 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
139 config.sys_language_mode =',
140 ],
141 [
142 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
143 config.sys_language_mode = content_fallback',
144 ],
145 [
146 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
147 config.sys_language_mode = content_fallback;1,0',
148 ],
149 [
150 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
151 config.sys_language_mode = strict',
152 ],
153 [
154 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
155 config.sys_language_mode = ignore',
156 ],
157 ];
158 }
159
160 /**
161 * For the default language all combination of language settings should give the same result,
162 * regardless of TypoScript settings, if the requested language is "0" then no TypoScript settings apply.
163 *
164 * @test
165 * @dataProvider defaultLanguageConfigurationDataProvider
166 *
167 * @param string $typoScript
168 */
169 public function onlyEnglishContentIsRenderedForDefaultLanguage($typoScript)
170 {
171 $this->addTypoScriptToTemplateRecord(1, $typoScript);
172
173 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 0);
174 $responseSections = $frontendResponse->getResponseSections('Extbase:list()');
175 $visibleHeaders = ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'];
176
177 $constraint = $this->getRequestSectionHasRecordConstraint()
178 ->setTable(self::TABLE_Content)
179 ->setField('header');
180 call_user_func_array([$constraint, 'setValues'],$visibleHeaders);
181
182 $this->assertThat($responseSections, $constraint);
183 $constraint = $this->getRequestSectionDoesNotHaveRecordConstraint()
184 ->setTable(self::TABLE_Content)
185 ->setField('header');
186 call_user_func_array([$constraint, 'setValues'],$this->getNonVisibleHeaders($visibleHeaders));
187 $this->assertThat($responseSections, $constraint);
188
189 //assert FAL relations
190 $visibleRecords = [
191 297 => ['T3BOARD'],
192 298 => ['Kasper'],
193 ];
194 foreach ($visibleRecords as $ttContentUid => $visibleFileTitles) {
195 $constraint = $this->getRequestSectionStructureHasRecordConstraint()
196 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('image')
197 ->setTable('sys_file_reference')->setField('title');
198 call_user_func_array([$constraint, 'setValues'], $visibleFileTitles);
199 $this->assertThat($responseSections, $constraint);
200
201 $constraint = $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
202 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('image')
203 ->setTable('sys_file_reference')->setField('title');
204 call_user_func_array([$constraint, 'setValues'], $this->getNonVisibleFileTitles($visibleFileTitles));
205 $this->assertThat($responseSections, $constraint);
206 }
207 }
208
209 /**
210 * Dutch language has pages_language_overlay record and some content elements are translated
211 *
212 * @return array
213 */
214 public function dutchDataProvider()
215 {
216 //Expected behaviour:
217 //Page is translated to Dutch, so changing sys_language_mode does NOT change the results
218 //Page title is always [DK]Page, and both sys_language_content and sys_language_uid are always 1
219 return [
220 [
221 'typoScript' => 'config.sys_language_overlay = 0
222 config.sys_language_mode =',
223 'visibleRecords' => [
224 297 => [
225 'header' => '[Translate to Dansk:] Regular Element #1',
226 'image' => ['T3BOARD'],
227
228 ],
229 298 => [
230 'header' => 'Regular Element #2',
231 'image' => ['Kasper'],
232 ],
233 299 => [
234 'header' => '[Translate to Dansk:] Regular Element #3',
235 'image' => []
236 ],
237 303 => [
238 'header' => '[DK] Without default language',
239 'image' => ['[T3BOARD] Image added to DK element without default language'],
240 ],
241 307 => [
242 'header' => '[DK] UnHidden Element #4',
243 'image' => [],
244 ],
245 ],
246 ],
247 [
248 'typoScript' => 'config.sys_language_overlay = 0
249 config.sys_language_mode = content_fallback',
250 'visibleRecords' => [
251 297 => [
252 'header' => '[Translate to Dansk:] Regular Element #1',
253 'image' => ['T3BOARD'],
254
255 ],
256 298 => [
257 'header' => 'Regular Element #2',
258 'image' => ['Kasper'],
259 ],
260 299 => [
261 'header' => '[Translate to Dansk:] Regular Element #3',
262 'image' => []
263 ],
264 303 => [
265 'header' => '[DK] Without default language',
266 'image' => ['[T3BOARD] Image added to DK element without default language'],
267 ],
268 307 => [
269 'header' => '[DK] UnHidden Element #4',
270 'image' => [],
271 ],
272 ],
273 ],
274 [
275 'typoScript' => 'config.sys_language_overlay = 0
276 config.sys_language_mode = content_fallback;1,0',
277 'visibleRecords' => [
278 297 => [
279 'header' => '[Translate to Dansk:] Regular Element #1',
280 'image' => ['T3BOARD'],
281
282 ],
283 298 => [
284 'header' => 'Regular Element #2',
285 'image' => ['Kasper'],
286 ],
287 299 => [
288 'header' => '[Translate to Dansk:] Regular Element #3',
289 'image' => []
290 ],
291 303 => [
292 'header' => '[DK] Without default language',
293 'image' => ['[T3BOARD] Image added to DK element without default language'],
294 ],
295 307 => [
296 'header' => '[DK] UnHidden Element #4',
297 'image' => [],
298 ],
299 ],
300 ],
301 [
302 'typoScript' => 'config.sys_language_overlay = 0
303 config.sys_language_mode = strict',
304 'visibleRecords' => [
305 297 => [
306 'header' => '[Translate to Dansk:] Regular Element #1',
307 'image' => [],
308 ],
309 299 => [
310 'header' => '[Translate to Dansk:] Regular Element #3',
311 'image' => []
312 ],
313 303 => [
314 'header' => '[DK] Without default language',
315 'image' => ['[T3BOARD] Image added to DK element without default language'],
316 ],
317 ],
318 ],
319 [
320 'typoScript' => 'config.sys_language_overlay = 0
321 config.sys_language_mode = ignore',
322 'visibleRecords' => [
323 297 => [
324 'header' => '[Translate to Dansk:] Regular Element #1',
325 'image' => ['T3BOARD'],
326
327 ],
328 298 => [
329 'header' => 'Regular Element #2',
330 'image' => ['Kasper'],
331 ],
332 299 => [
333 'header' => '[Translate to Dansk:] Regular Element #3',
334 'image' => []
335 ],
336 303 => [
337 'header' => '[DK] Without default language',
338 'image' => ['[T3BOARD] Image added to DK element without default language'],
339 ],
340 307 => [
341 'header' => '[DK] UnHidden Element #4',
342 'image' => [],
343 ],
344 ],
345 ],
346 5 => [
347 'typoScript' => 'config.sys_language_overlay = 1
348 config.sys_language_mode =',
349 'visibleRecords' => [
350 297 => [
351 'header' => '[Translate to Dansk:] Regular Element #1',
352 'image' => ['T3BOARD'],
353
354 ],
355 298 => [
356 'header' => 'Regular Element #2',
357 'image' => ['Kasper'],
358 ],
359 299 => [
360 'header' => '[Translate to Dansk:] Regular Element #3',
361 'image' => []
362 ],
363 303 => [
364 'header' => '[DK] Without default language',
365 'image' => ['[T3BOARD] Image added to DK element without default language'],
366 ],
367 307 => [
368 'header' => '[DK] UnHidden Element #4',
369 'image' => [],
370 ],
371 ],
372 ],
373 // Expected behaviour:
374 // Not translated element #2 is shown because sys_language_overlay = 1 (with sys_language_overlay = hideNonTranslated, it would be hidden)
375 [
376 'typoScript' => 'config.sys_language_overlay = 1
377 config.sys_language_mode = content_fallback',
378 'visibleRecords' => [
379 297 => [
380 'header' => '[Translate to Dansk:] Regular Element #1',
381 'image' => ['T3BOARD'],
382
383 ],
384 298 => [
385 'header' => 'Regular Element #2',
386 'image' => ['Kasper'],
387 ],
388 299 => [
389 'header' => '[Translate to Dansk:] Regular Element #3',
390 'image' => []
391 ],
392 303 => [
393 'header' => '[DK] Without default language',
394 'image' => ['[T3BOARD] Image added to DK element without default language'],
395 ],
396 307 => [
397 'header' => '[DK] UnHidden Element #4',
398 'image' => [],
399 ],
400 ],
401 ],
402 // Expected behaviour:
403 // Same as config.sys_language_mode = content_fallback because we're requesting language 1, so no additional fallback possible
404
405 [
406 'typoScript' => 'config.sys_language_overlay = 1
407 config.sys_language_mode = content_fallback;1,0',
408 'visibleRecords' => [
409 297 => [
410 'header' => '[Translate to Dansk:] Regular Element #1',
411 'image' => ['T3BOARD'],
412 ],
413 298 => [
414 'header' => 'Regular Element #2',
415 'image' => ['Kasper'],
416 ],
417 299 => [
418 'header' => '[Translate to Dansk:] Regular Element #3',
419 'image' => []
420 ],
421 303 => [
422 'header' => '[DK] Without default language',
423 'image' => ['[T3BOARD] Image added to DK element without default language'],
424 ],
425 307 => [
426 'header' => '[DK] UnHidden Element #4',
427 'image' => [],
428 ],
429 ],
430 ],
431 [
432 'typoScript' => 'config.sys_language_overlay = 1
433 config.sys_language_mode = strict',
434 'visibleRecords' => [
435 297 => [
436 'header' => '[Translate to Dansk:] Regular Element #1',
437 'image' => [],
438 ],
439 299 => [
440 'header' => '[Translate to Dansk:] Regular Element #3',
441 'image' => []
442 ],
443 303 => [
444 'header' => '[DK] Without default language',
445 'image' => ['[T3BOARD] Image added to DK element without default language'],
446 ],
447 ],
448 ],
449 [
450 'typoScript' => 'config.sys_language_overlay = 1
451 config.sys_language_mode = ignore',
452 'visibleRecords' => [
453 297 => [
454 'header' => '[Translate to Dansk:] Regular Element #1',
455 'image' => ['T3BOARD'],
456
457 ],
458 298 => [
459 'header' => 'Regular Element #2',
460 'image' => ['Kasper'],
461 ],
462 299 => [
463 'header' => '[Translate to Dansk:] Regular Element #3',
464 'image' => []
465 ],
466 303 => [
467 'header' => '[DK] Without default language',
468 'image' => ['[T3BOARD] Image added to DK element without default language'],
469 ],
470 307 => [
471 'header' => '[DK] UnHidden Element #4',
472 'image' => [],
473 ],
474 ],
475 ],
476 // Expected behaviour:
477 // Non translated default language elements are not shown, because of hideNonTranslated
478 10 => [
479 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
480 config.sys_language_mode =',
481 'visibleRecords' => [
482 297 => [
483 'header' => '[Translate to Dansk:] Regular Element #1',
484 'image' => ['T3BOARD'],
485
486 ],
487 298 => [
488 'header' => 'Regular Element #2',
489 'image' => ['Kasper'],
490 ],
491 299 => [
492 'header' => '[Translate to Dansk:] Regular Element #3',
493 'image' => []
494 ],
495 303 => [
496 'header' => '[DK] Without default language',
497 'image' => ['[T3BOARD] Image added to DK element without default language'],
498 ],
499 307 => [
500 'header' => '[DK] UnHidden Element #4',
501 'image' => [],
502 ],
503 ],
504 ],
505 [
506 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
507 config.sys_language_mode = content_fallback',
508 'visibleRecords' => [
509 297 => [
510 'header' => '[Translate to Dansk:] Regular Element #1',
511 'image' => ['T3BOARD'],
512
513 ],
514 298 => [
515 'header' => 'Regular Element #2',
516 'image' => ['Kasper'],
517 ],
518 299 => [
519 'header' => '[Translate to Dansk:] Regular Element #3',
520 'image' => []
521 ],
522 303 => [
523 'header' => '[DK] Without default language',
524 'image' => ['[T3BOARD] Image added to DK element without default language'],
525 ],
526 307 => [
527 'header' => '[DK] UnHidden Element #4',
528 'image' => [],
529 ],
530 ],
531 ],
532 [
533 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
534 config.sys_language_mode = content_fallback;1,0',
535 'visibleRecords' => [
536 297 => [
537 'header' => '[Translate to Dansk:] Regular Element #1',
538 'image' => ['T3BOARD'],
539
540 ],
541 298 => [
542 'header' => 'Regular Element #2',
543 'image' => ['Kasper'],
544 ],
545 299 => [
546 'header' => '[Translate to Dansk:] Regular Element #3',
547 'image' => []
548 ],
549 303 => [
550 'header' => '[DK] Without default language',
551 'image' => ['[T3BOARD] Image added to DK element without default language'],
552 ],
553 307 => [
554 'header' => '[DK] UnHidden Element #4',
555 'image' => [],
556 ],
557 ],
558 ],
559 // Setting sys_language_mode = strict has the same effect as previous data sets, because the translation of the page exists
560 [
561 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
562 config.sys_language_mode = strict',
563 'visibleRecords' => [
564 297 => [
565 'header' => '[Translate to Dansk:] Regular Element #1',
566 'image' => [],
567 ],
568 299 => [
569 'header' => '[Translate to Dansk:] Regular Element #3',
570 'image' => []
571 ],
572 303 => [
573 'header' => '[DK] Without default language',
574 'image' => ['[T3BOARD] Image added to DK element without default language'],
575 ],
576 ],
577 ],
578 [
579 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
580 config.sys_language_mode = ignore',
581 'visibleRecords' => [
582 297 => [
583 'header' => '[Translate to Dansk:] Regular Element #1',
584 'image' => ['T3BOARD'],
585 ],
586 298 => [
587 'header' => 'Regular Element #2',
588 'image' => ['Kasper'],
589 ],
590 299 => [
591 'header' => '[Translate to Dansk:] Regular Element #3',
592 'image' => []
593 ],
594 303 => [
595 'header' => '[DK] Without default language',
596 'image' => ['[T3BOARD] Image added to DK element without default language'],
597 ],
598 307 => [
599 'header' => '[DK] UnHidden Element #4',
600 'image' => [],
601 ],
602 ],
603 ],
604 ];
605 }
606
607 /**
608 * @test
609 * @dataProvider dutchDataProvider
610 *
611 * @param string $typoScript
612 * @param array $visibleRecords
613 */
614 public function renderingOfDutchLanguage($typoScript, array $visibleRecords)
615 {
616 $this->addTypoScriptToTemplateRecord(1, $typoScript);
617 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 1);
618 $responseSections = $frontendResponse->getResponseSections('Extbase:list()');
619 $visibleHeaders = array_map(function ($element) {
620 return $element['header'];
621 }, $visibleRecords);
622 $constraint = $this->getRequestSectionHasRecordConstraint()
623 ->setTable(self::TABLE_Content)
624 ->setField('header');
625 call_user_func_array([$constraint, 'setValues'], $visibleHeaders);
626 $this->assertThat($responseSections, $constraint);
627
628 $constraint = $this->getRequestSectionDoesNotHaveRecordConstraint()
629 ->setTable(self::TABLE_Content)
630 ->setField('header');
631 call_user_func_array([$constraint, 'setValues'], $this->getNonVisibleHeaders($visibleHeaders));
632 $this->assertThat($responseSections, $constraint);
633
634 foreach ($visibleRecords as $ttContentUid => $properties) {
635 $visibleFileTitles = $properties['image'];
636 if (!empty($visibleFileTitles)) {
637 $constraint = $this->getRequestSectionStructureHasRecordConstraint()
638 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('image')
639 ->setTable('sys_file_reference')->setField('title');
640 call_user_func_array([$constraint, 'setValues'], $visibleFileTitles);
641 $this->assertThat($responseSections, $constraint);
642 }
643 $constraint = $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
644 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('image')
645 ->setTable('sys_file_reference')->setField('title');
646 call_user_func_array([$constraint, 'setValues'], $this->getNonVisibleFileTitles($visibleFileTitles));
647 $this->assertThat($responseSections, $constraint);
648 }
649 }
650
651 public function contentOnNonTranslatedPageDataProvider()
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 ],
677 [
678 'typoScript' => 'config.sys_language_overlay = 0
679 config.sys_language_mode = content_fallback',
680 'visibleRecords' => [
681 297 => [
682 'header' => 'Regular Element #1',
683 'image' => ['T3BOARD'],
684 ],
685 298 => [
686 'header' => 'Regular Element #2',
687 'image' => ['Kasper'],
688 ],
689 299 => [
690 'header' => 'Regular Element #3',
691 'image' => [],
692 ],
693 ],
694 ],
695 [
696 'typoScript' => 'config.sys_language_overlay = 0
697 config.sys_language_mode = content_fallback;1,0',
698 'visibleRecords' => [
699 297 => [
700 'header' => '[Translate to Dansk:] Regular Element #1',
701 'image' => ['T3BOARD'],
702 ],
703 298 => [
704 'header' => 'Regular Element #2',
705 'image' => ['Kasper'],
706 ],
707 299 => [
708 'header' => '[Translate to Dansk:] Regular Element #3',
709 'image' => []
710 ],
711 303 => [
712 'header' => '[DK] Without default language',
713 'image' => ['[T3BOARD] Image added to DK element without default language'],
714 ],
715 307 => [
716 'header' => '[DK] UnHidden Element #4',
717 'image' => [],
718 ],
719 ],
720 ],
721 [
722 'typoScript' => 'config.sys_language_overlay = 0
723 config.sys_language_mode = strict',
724 'visibleRecords' => [],
725 'status' => 404,
726 ],
727 [
728 'typoScript' => 'config.sys_language_overlay = 0
729 config.sys_language_mode = ignore',
730 'visibleRecords' => [
731 297 => [
732 'header' => '[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1',
733 'image' => ['T3BOARD'],
734 ],
735 298 => [
736 'header' => 'Regular Element #2',
737 'image' => ['Kasper'],
738 ],
739 299 => [
740 'header' => 'Regular Element #3',
741 'image' => []
742 ],
743 304 => [
744 'header' => '[DE] Without default language',
745 'image' => [],
746 ],
747 ],
748 ],
749 5 => [
750 'typoScript' => 'config.sys_language_overlay = 1
751 config.sys_language_mode =',
752 'visibleRecords' => [
753 297 => [
754 'header' => 'Regular Element #1',
755 'image' => ['T3BOARD'],
756 ],
757 298 => [
758 'header' => 'Regular Element #2',
759 'image' => ['Kasper'],
760 ],
761 299 => [
762 'header' => 'Regular Element #3',
763 'image' => [],
764 ],
765 ],
766 ],
767 //falling back to default language
768 [
769 'typoScript' => 'config.sys_language_overlay = 1
770 config.sys_language_mode = content_fallback',
771 'visibleRecords' => [
772 297 => [
773 'header' => 'Regular Element #1',
774 'image' => ['T3BOARD'],
775 ],
776 298 => [
777 'header' => 'Regular Element #2',
778 'image' => ['Kasper'],
779 ],
780 299 => [
781 'header' => 'Regular Element #3',
782 'image' => [],
783 ],
784 ],
785 ],
786 //Dutch elements are shown because of the content fallback 1,0 - first Dutch, then default language
787 //note that '[DK] Without default language' is NOT shown - due to overlays (fetch default language and overlay it with translations)
788 [
789 'typoScript' => 'config.sys_language_overlay = 1
790 config.sys_language_mode = content_fallback;1,0',
791 'visibleRecords' => [
792 297 => [
793 'header' => '[Translate to Dansk:] Regular Element #1',
794 'image' => ['T3BOARD'],
795 ],
796 298 => [
797 'header' => 'Regular Element #2',
798 'image' => ['Kasper'],
799 ],
800 299 => [
801 'header' => '[Translate to Dansk:] Regular Element #3',
802 'image' => []
803 ],
804 303 => [
805 'header' => '[DK] Without default language',
806 'image' => ['[T3BOARD] Image added to DK element without default language'],
807 ],
808 307 => [
809 'header' => '[DK] UnHidden Element #4',
810 'image' => [],
811 ],
812 ],
813 ],
814 [
815 'typoScript' => 'config.sys_language_overlay = 1
816 config.sys_language_mode = strict',
817 'visibleRecords' => [],
818 'status' => 404
819 ],
820 [
821 'typoScript' => 'config.sys_language_overlay = 1
822 config.sys_language_mode = ignore',
823 'visibleRecords' => [
824 297 => [
825 'header' => '[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1',
826 'image' => ['T3BOARD'],
827 ],
828 298 => [
829 'header' => 'Regular Element #2',
830 'image' => ['Kasper'],
831 ],
832 299 => [
833 'header' => 'Regular Element #3',
834 'image' => []
835 ],
836 304 => [
837 'header' => '[DE] Without default language',
838 'image' => [],
839 ],
840 ],
841 ],
842 10 => [
843 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
844 config.sys_language_mode =',
845 'visibleRecords' => [
846 297 => [
847 'header' => 'Regular Element #1',
848 'image' => ['T3BOARD'],
849 ],
850 298 => [
851 'header' => 'Regular Element #2',
852 'image' => ['Kasper'],
853 ],
854 299 => [
855 'header' => 'Regular Element #3',
856 'image' => [],
857 ],
858 ],
859 ],
860 [
861 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
862 config.sys_language_mode = content_fallback',
863 'visibleRecords' => [
864 297 => [
865 'header' => 'Regular Element #1',
866 'image' => ['T3BOARD'],
867 ],
868 298 => [
869 'header' => 'Regular Element #2',
870 'image' => ['Kasper'],
871 ],
872 299 => [
873 'header' => 'Regular Element #3',
874 'image' => [],
875 ],
876 ],
877 ],
878 [
879 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
880 config.sys_language_mode = content_fallback;1,0',
881 // 'visibleRecordHeaders' => ['[Translate to Dansk:] Regular Element #1', '[Translate to Dansk:] Regular Element #3', 'Regular Element #2', '[DK] Without default language', '[DK] UnHidden Element #4'],
882 'visibleRecords' => [
883 297 => [
884 'header' => '[Translate to Dansk:] Regular Element #1',
885 'image' => ['T3BOARD'],
886 ],
887 298 => [
888 'header' => 'Regular Element #2',
889 'image' => ['Kasper'],
890 ],
891 299 => [
892 'header' => '[Translate to Dansk:] Regular Element #3',
893 'image' => []
894 ],
895 303 => [
896 'header' => '[DK] Without default language',
897 'image' => ['[T3BOARD] Image added to DK element without default language'],
898 ],
899 307 => [
900 'header' => '[DK] UnHidden Element #4',
901 'image' => [],
902 ],
903 ],
904 ],
905 [
906 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
907 config.sys_language_mode = strict',
908 'visibleRecords' => [],
909 'status' => 404,
910 ],
911 [
912 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
913 config.sys_language_mode = ignore',
914 'visibleRecords' => [
915 297 => [
916 'header' => '[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1',
917 'image' => ['T3BOARD'],
918 ],
919 298 => [
920 'header' => 'Regular Element #2',
921 'image' => ['Kasper'],
922 ],
923 299 => [
924 'header' => 'Regular Element #3',
925 'image' => []
926 ],
927 304 => [
928 'header' => '[DE] Without default language',
929 'image' => [],
930 ],
931 ],
932 ],
933 ];
934 }
935
936 /**
937 * Page uid 89 is NOT translated to german
938 *
939 * @test
940 * @dataProvider contentOnNonTranslatedPageDataProvider
941 *
942 * @param string $typoScript
943 * @param array $visibleRecords
944 * @param string $status 'success' or 404
945 */
946 public function contentOnNonTranslatedPageGerman($typoScript, array $visibleRecords, $status='success')
947 {
948 $this->addTypoScriptToTemplateRecord(1, $typoScript);
949 $visibleHeaders = array_map(function ($element) {
950 return $element['header'];
951 }, $visibleRecords);
952
953 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 2);
954 if ($status === 'success') {
955 $responseSections = $frontendResponse->getResponseSections('Extbase:list()');
956 $constraint =
957 $this->getRequestSectionHasRecordConstraint()
958 ->setTable(self::TABLE_Content)
959 ->setField('header');
960 call_user_func_array([$constraint, 'setValues'],$visibleHeaders);
961
962 $this->assertThat(
963 $responseSections,$constraint);
964 $constraint = $this->getRequestSectionDoesNotHaveRecordConstraint()
965 ->setTable(self::TABLE_Content)
966 ->setField('header');
967 call_user_func_array([$constraint, 'setValues'],$this->getNonVisibleHeaders($visibleHeaders));
968 $this->assertThat($responseSections, $constraint);
969
970 foreach ($visibleRecords as $ttContentUid => $properties) {
971 $visibleFileTitles = $properties['image'];
972 if (!empty($visibleFileTitles)) {
973 $constraint = $this->getRequestSectionStructureHasRecordConstraint()
974 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('image')
975 ->setTable('sys_file_reference')->setField('title');
976 call_user_func_array([$constraint, 'setValues'], $visibleFileTitles);
977 $this->assertThat($responseSections, $constraint);
978 }
979 $constraint = $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
980 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('image')
981 ->setTable('sys_file_reference')->setField('title');
982 call_user_func_array([$constraint, 'setValues'], $this->getNonVisibleFileTitles($visibleFileTitles));
983 $this->assertThat($responseSections, $constraint);
984 }
985 }
986 //some configuration combinations results in 404, in that case status will be set to 404
987 $this->assertEquals($status, $frontendResponse->getStatus());
988 }
989
990 public function contentOnPartiallyTranslatedPageDataProvider()
991 {
992
993 //Expected behaviour:
994 //Setting sys_language_mode to different values doesn't influence the result as the requested page is translated to Polish,
995 //Page title is always [PL]Page, and both sys_language_content and sys_language_uid are always 3
996 return [
997 [
998 'typoScript' => 'config.sys_language_overlay = 0
999 config.sys_language_mode =',
1000 'visibleRecordHeaders' => ['Regular Element #3', '[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
1001 ],
1002 [
1003 'typoScript' => 'config.sys_language_overlay = 0
1004 config.sys_language_mode = content_fallback',
1005 'visibleRecordHeaders' => ['Regular Element #3', '[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
1006 ],
1007 [
1008 'typoScript' => 'config.sys_language_overlay = 0
1009 config.sys_language_mode = content_fallback;1,0',
1010 'visibleRecordHeaders' => ['Regular Element #3', '[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
1011 ],
1012 [
1013 'typoScript' => 'config.sys_language_overlay = 0
1014 config.sys_language_mode = strict',
1015 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
1016 ],
1017 [
1018 'typoScript' => 'config.sys_language_overlay = 0
1019 config.sys_language_mode = ignore',
1020 'visibleRecordHeaders' => ['Regular Element #3', '[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
1021 ],
1022 5 => [
1023 'typoScript' => 'config.sys_language_overlay = 1
1024 config.sys_language_mode =',
1025 'visibleRecordHeaders' => ['[PL] Without default language', '[Translate to Polski:] Regular Element #1', 'Regular Element #3'],
1026 ],
1027 // Expected behaviour:
1028 // Not translated element #2 is shown because sys_language_overlay = 1 (with sys_language_overlay = hideNonTranslated, it would be hidden)
1029 [
1030 'typoScript' => 'config.sys_language_overlay = 1
1031 config.sys_language_mode = content_fallback',
1032 'visibleRecordHeaders' => ['[PL] Without default language', '[Translate to Polski:] Regular Element #1', 'Regular Element #3'],
1033 ],
1034 // Expected behaviour:
1035 // 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
1036 // but on page level - and this page is translated to Polish, so no fallback is happening
1037 [
1038 'typoScript' => 'config.sys_language_overlay = 1
1039 config.sys_language_mode = content_fallback;1,0',
1040 'visibleRecordHeaders' => ['[PL] Without default language', '[Translate to Polski:] Regular Element #1', 'Regular Element #3'],
1041 ],
1042 [
1043 'typoScript' => 'config.sys_language_overlay = 1
1044 config.sys_language_mode = strict',
1045 'visibleRecordHeaders' => ['[PL] Without default language', '[Translate to Polski:] Regular Element #1'],
1046 ],
1047 [
1048 'typoScript' => 'config.sys_language_overlay = 1
1049 config.sys_language_mode = ignore',
1050 'visibleRecordHeaders' => ['[PL] Without default language', '[Translate to Polski:] Regular Element #1', 'Regular Element #3'],
1051 ],
1052 // Expected behaviour:
1053 // Non translated default language elements are not shown, because of hideNonTranslated
1054 10 => [
1055 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
1056 config.sys_language_mode =',
1057 'visibleRecordHeaders' => ['[PL] Without default language', 'Regular Element #3', '[Translate to Polski:] Regular Element #1'],
1058 ],
1059 [
1060 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
1061 config.sys_language_mode = content_fallback',
1062 'visibleRecordHeaders' => ['[PL] Without default language', 'Regular Element #3', '[Translate to Polski:] Regular Element #1'],
1063 ],
1064 [
1065 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
1066 config.sys_language_mode = content_fallback;1,0',
1067 'visibleRecordHeaders' => ['[PL] Without default language', 'Regular Element #3', '[Translate to Polski:] Regular Element #1'],
1068 ],
1069 [
1070 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
1071 config.sys_language_mode = strict',
1072 'visibleRecordHeaders' => ['[PL] Without default language', '[Translate to Polski:] Regular Element #1'],
1073 ],
1074 [
1075 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
1076 config.sys_language_mode = ignore',
1077 'visibleRecordHeaders' => ['[PL] Without default language', 'Regular Element #3', '[Translate to Polski:] Regular Element #1'],
1078 ]
1079 ];
1080 }
1081
1082 /**
1083 * Page uid 89 is translated to to Polish, but not all CE are translated
1084 *
1085 * @test
1086 * @dataProvider contentOnPartiallyTranslatedPageDataProvider
1087 *
1088 * @param string $typoScript
1089 * @param array $visibleHeaders
1090 */
1091 public function contentOnPartiallyTranslatedPage($typoScript, array $visibleHeaders)
1092 {
1093 $this->addTypoScriptToTemplateRecord(1, $typoScript);
1094
1095 $frontendResponse = $this->getFrontendResponse(self::VALUE_PageId, 3);
1096 $this->assertEquals('success', $frontendResponse->getStatus());
1097 $responseSections = $frontendResponse->getResponseSections('Extbase:list()');
1098
1099 $constraint =
1100 $this->getRequestSectionHasRecordConstraint()
1101 ->setTable(self::TABLE_Content)
1102 ->setField('header');
1103 call_user_func_array([$constraint, 'setValues'],$visibleHeaders);
1104
1105 $this->assertThat(
1106 $responseSections,$constraint);
1107 $constraint = $this->getRequestSectionDoesNotHaveRecordConstraint()
1108 ->setTable(self::TABLE_Content)
1109 ->setField('header');
1110 call_user_func_array([$constraint, 'setValues'],$this->getNonVisibleHeaders($visibleHeaders));
1111 $this->assertThat($responseSections, $constraint);
1112 }
1113
1114 /**
1115 * Helper function to ease asserting that rest of the data set is not visible
1116 *
1117 * @param array $visibleHeaders
1118 * @return array
1119 */
1120 protected function getNonVisibleHeaders(array $visibleHeaders)
1121 {
1122 $allElements = [
1123 'Regular Element #1',
1124 'Regular Element #2',
1125 'Regular Element #3',
1126 'Hidden Element #4',
1127 '[Translate to Dansk:] Regular Element #1',
1128 '[Translate to Dansk:] Regular Element #3',
1129 '[DK] Without default language',
1130 '[DK] UnHidden Element #4',
1131 '[DE] Without default language',
1132 '[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1',
1133 '[Translate to Polski:] Regular Element #1',
1134 '[PL] Without default language',
1135 '[PL] Hidden Regular Element #2'
1136 ];
1137 return array_diff($allElements, $visibleHeaders);
1138 }
1139
1140 /**
1141 * Helper function to ease asserting that rest of the data set is not visible
1142 *
1143 * @param array $visibleTitles
1144 * @return array
1145 */
1146 protected function getNonVisibleFileTitles(array $visibleTitles)
1147 {
1148 $allElements = [
1149 'T3BOARD',
1150 'Kasper',
1151 '[Kasper] Image translated to Dansk',
1152 '[T3BOARD] Image added in Dansk (without parent)',
1153 '[T3BOARD] Image added to DK element without default language',
1154 '[T3BOARD] image translated to DE from DK',
1155 ];
1156 return array_diff($allElements, $visibleTitles);
1157 }
1158
1159 /**
1160 * Adds TypoScript setup snippet to the existing template record
1161 *
1162 * @param int $pageId
1163 * @param string $typoScript
1164 */
1165 protected function addTypoScriptToTemplateRecord($pageId, $typoScript)
1166 {
1167 $connection = $this->getDatabaseConnection();
1168
1169 $template = $connection->exec_SELECTgetSingleRow('*', 'sys_template', 'pid = '. $pageId . ' AND root = 1');
1170 if (empty($template)) {
1171 $this->fail('Cannot find root template on page with id: "' . $pageId . '"');
1172 }
1173 $updateFields['config'] = $template['config'] . LF . $typoScript;
1174 $connection->exec_UPDATEquery(
1175 'sys_template',
1176 'uid = ' . $template['uid'],
1177 $updateFields
1178 );
1179 }
1180 }