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