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