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