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