[TASK] Add tests for SiteBased translations in Extbase records
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Functional / Persistence / TranslatedSiteContentTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Extbase\Tests\Functional\Persistence;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use ExtbaseTeam\BlogExample\Domain\Repository\TtContentRepository;
20 use TYPO3\CMS\Core\Error\Http\PageNotFoundException;
21 use TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase;
22 use TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Extbase\Object\ObjectManager;
25 use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
26 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
27 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\ResponseContent;
28
29 /**
30 * Test case documenting an Extbase translation handling of tt_content consistent with Site Handling.
31 *
32 * This test has the same scenarios as in the TypoScript version:
33 * @see \TYPO3\CMS\Frontend\Tests\Functional\Rendering\LocalizedSiteContentRenderingTest
34 */
35 class TranslatedSiteContentTest extends AbstractDataHandlerActionTestCase
36 {
37 use SiteBasedTestTrait;
38
39 protected const VALUE_PageId = 89;
40 protected const TABLE_Content = 'tt_content';
41 protected const TABLE_Pages = 'pages';
42
43 /**
44 * @var string
45 */
46 protected $scenarioDataSetDirectory = 'typo3/sysext/frontend/Tests/Functional/Rendering/DataSet/';
47
48 /**
49 * @var array
50 */
51 protected $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
52
53 /**
54 * @var array
55 */
56 protected $coreExtensionsToLoad = ['extbase', 'fluid'];
57
58 /**
59 * @var ObjectManagerInterface The object manager
60 */
61 protected $objectManager;
62
63 /**
64 * @var TtContentRepository
65 */
66 protected $contentRepository;
67
68 /**
69 * If this value is NULL, log entries are not considered.
70 * If it's an integer value, the number of log entries is asserted.
71 *
72 * @var int|null
73 */
74 protected $expectedErrorLogEntries;
75
76 /**
77 * @var array
78 */
79 protected $pathsToLinkInTestInstance = [
80 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/AdditionalConfiguration.php' => 'typo3conf/AdditionalConfiguration.php',
81 'typo3/sysext/frontend/Tests/Functional/Fixtures/Images' => 'fileadmin/user_upload'
82 ];
83
84 /**
85 * @var array
86 */
87 protected const LANGUAGE_PRESETS = [
88 'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
89 'DK' => ['id' => 1, 'title' => 'Dansk', 'locale' => 'dk_DA.UTF8'],
90 'DE' => ['id' => 2, 'title' => 'Deutsch', 'locale' => 'de_DE.UTF8'],
91 'PL' => ['id' => 3, 'title' => 'Polski', 'locale' => 'pl_PL.UTF8'],
92 ];
93
94 protected function setUp(): void
95 {
96 parent::setUp();
97 $this->importScenarioDataSet('LiveDefaultPages');
98 $this->importScenarioDataSet('LiveDefaultElements');
99
100 $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
101 $this->contentRepository = $this->objectManager->get(TtContentRepository::class);
102 $this->setUpFrontendRootPage(1, [
103 'typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TypoScript/setup.typoscript',
104 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/Frontend/ContentJsonRenderer.typoscript'
105 ]);
106 }
107
108 protected function tearDown(): void
109 {
110 unset($this->objectManager, $this->contentRepository);
111 parent::tearDown();
112 }
113
114 /**
115 * For the default language all combination of language settings should give the same result,
116 * regardless of TypoScript settings, if the requested language is "0" then no TypoScript settings apply.
117 *
118 * @test
119 */
120 public function onlyEnglishContentIsRenderedForDefaultLanguage(): void
121 {
122 $this->writeSiteConfiguration(
123 'test',
124 $this->buildSiteConfiguration(1, 'https://website.local/'),
125 [
126 $this->buildDefaultLanguageConfiguration('EN', '/en/')
127 ],
128 [
129 $this->buildErrorHandlingConfiguration('Fluid', [404])
130 ]
131 );
132
133 $response = $this->executeFrontendRequest(
134 new InternalRequest('https://website.local/en/?id=' . static::VALUE_PageId)
135 );
136 $responseStructure = ResponseContent::fromString((string)$response->getBody());
137 $responseSections = $responseStructure->getSection('Extbase:list()');
138 $visibleHeaders = ['Regular Element #1', 'Regular Element #2', 'Regular Element #3'];
139 $this->assertThat(
140 $responseSections,
141 $this->getRequestSectionHasRecordConstraint()
142 ->setTable(self::TABLE_Content)
143 ->setField('header')
144 ->setValues(...$visibleHeaders)
145 );
146 $this->assertThat(
147 $responseSections,
148 $this->getRequestSectionDoesNotHaveRecordConstraint()
149 ->setTable(self::TABLE_Content)
150 ->setField('header')
151 ->setValues(...$this->getNonVisibleHeaders($visibleHeaders))
152 );
153
154 // assert FAL relations
155 $visibleFiles = ['T3BOARD'];
156 $this->assertThat($responseSections, $this->getRequestSectionStructureHasRecordConstraint()
157 ->setRecordIdentifier(self::TABLE_Content . ':297')->setRecordField('image')
158 ->setTable('sys_file_reference')->setField('title')->setValues(...$visibleFiles));
159
160 $this->assertThat($responseSections, $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
161 ->setRecordIdentifier(self::TABLE_Content . ':297')->setRecordField('image')
162 ->setTable('sys_file_reference')->setField('title')->setValues(...$this->getNonVisibleFileTitles($visibleFiles)));
163
164 $visibleFiles = ['Kasper2'];
165 $this->assertThat($responseSections, $this->getRequestSectionStructureHasRecordConstraint()
166 ->setRecordIdentifier(self::TABLE_Content . ':298')->setRecordField('image')
167 ->setTable('sys_file_reference')->setField('title')->setValues(...$visibleFiles));
168
169 $this->assertThat($responseSections, $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
170 ->setRecordIdentifier(self::TABLE_Content . ':298')->setRecordField('image')
171 ->setTable('sys_file_reference')->setField('title')->setValues(...$this->getNonVisibleFileTitles($visibleFiles)));
172
173 // assert Categories
174 $visibleCategories = ['Category 1', 'Category 3 - not translated'];
175 $this->assertThat($responseSections, $this->getRequestSectionStructureHasRecordConstraint()
176 ->setRecordIdentifier(self::TABLE_Content . ':297')->setRecordField('categories')
177 ->setTable('sys_category')->setField('title')->setValues(...$visibleCategories));
178
179 $this->assertThat($responseSections, $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
180 ->setRecordIdentifier(self::TABLE_Content . ':297')->setRecordField('categories')
181 ->setTable('sys_category')->setField('title')->setValues(...$this->getNonVisibleCategoryTitles($visibleCategories)));
182 }
183
184 /**
185 * Dutch language has pages record and some content elements are translated
186 *
187 * @return array
188 */
189 public function dutchDataProvider(): array
190 {
191 // Expected behaviour:
192 // Page is translated to Dutch, so changing sys_language_mode does NOT change the results
193 // Page title is always [DK]Page, and both sys_language_content and sys_language_uid are always 1
194 return [
195 [
196 'fallbackType' => 'free',
197 'visibleRecords' => [
198 300 => [
199 'header' => '[Translate to Dansk:] Regular Element #3',
200 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
201 ],
202 301 => [
203 'header' => '[Translate to Dansk:] Regular Element #1',
204 'image' => [],
205 'categories' => ['[Translate to Dansk:] Category 1', 'Category 4'],
206 ],
207 303 => [
208 'header' => '[DK] Without default language',
209 'image' => ['[T3BOARD] Image added to DK element without default language']
210 ],
211 308 => [
212 'header' => '[DK] UnHidden Element #4',
213 'image' => []
214 ],
215 ],
216 ],
217 [
218 'fallbackType' => 'fallback',
219 'visibleRecords' => [
220 297 => [
221 'header' => '[Translate to Dansk:] Regular Element #1',
222 'image' => [],
223 'categories' => ['[Translate to Dansk:] Category 1', 'Category 4'],
224 ],
225 298 => [
226 'header' => 'Regular Element #2',
227 'image' => ['Kasper2'],
228 ],
229 299 => [
230 'header' => '[Translate to Dansk:] Regular Element #3',
231 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
232 ],
233 ],
234 ],
235 [
236 'fallbackType' => 'strict',
237 'visibleRecords' => [
238 297 => [
239 'header' => '[Translate to Dansk:] Regular Element #1',
240 'image' => [],
241 'categories' => ['[Translate to Dansk:] Category 1', 'Category 4'],
242 ],
243 299 => [
244 'header' => '[Translate to Dansk:] Regular Element #3',
245 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
246 ],
247 ],
248 ],
249 ];
250 }
251
252 /**
253 * @test
254 * @dataProvider dutchDataProvider
255 *
256 * @param string $fallbackType
257 * @param array $visibleRecords
258 */
259 public function renderingOfDutchLanguage(string $fallbackType, array $visibleRecords): void
260 {
261 $this->writeSiteConfiguration(
262 'test',
263 $this->buildSiteConfiguration(1, 'https://website.local/'),
264 [
265 $this->buildDefaultLanguageConfiguration('EN', '/en/'),
266 $this->buildLanguageConfiguration('DK', '/dk/', [], $fallbackType)
267 ],
268 [
269 $this->buildErrorHandlingConfiguration('Fluid', [404])
270 ]
271 );
272
273 $response = $this->executeFrontendRequest(
274 new InternalRequest('https://website.local/dk/?id=' . static::VALUE_PageId)
275 );
276 $responseStructure = ResponseContent::fromString((string)$response->getBody());
277 $responseSections = $responseStructure->getSection('Extbase:list()');
278 $visibleHeaders = array_map(function ($element) {
279 return $element['header'];
280 }, $visibleRecords);
281
282 $this->assertThat(
283 $responseSections,
284 $this->getRequestSectionHasRecordConstraint()
285 ->setTable(self::TABLE_Content)
286 ->setField('header')
287 ->setValues(...$visibleHeaders)
288 );
289 $this->assertThat(
290 $responseSections,
291 $this->getRequestSectionDoesNotHaveRecordConstraint()
292 ->setTable(self::TABLE_Content)
293 ->setField('header')
294 ->setValues(...$this->getNonVisibleHeaders($visibleHeaders))
295 );
296
297 foreach ($visibleRecords as $ttContentUid => $properties) {
298 $visibleFileTitles = $properties['image'];
299 if (!empty($visibleFileTitles)) {
300 $this->assertThat($responseSections, $this->getRequestSectionStructureHasRecordConstraint()
301 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('image')
302 ->setTable('sys_file_reference')->setField('title')->setValues(...$visibleFileTitles));
303 }
304 $this->assertThat($responseSections, $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
305 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('image')
306 ->setTable('sys_file_reference')->setField('title')->setValues(...$this->getNonVisibleFileTitles($visibleFileTitles)));
307
308 $visibleCategoryTitles = $properties['categories'] ?? [];
309 if (!empty($visibleCategoryTitles)) {
310 $this->assertThat($responseSections, $this->getRequestSectionStructureHasRecordConstraint()
311 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('categories')
312 ->setTable('sys_category')->setField('title')->setValues(...$visibleCategoryTitles));
313 }
314 $this->assertThat($responseSections, $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
315 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('categories')
316 ->setTable('sys_category')->setField('title')->setValues(...$this->getNonVisibleCategoryTitles($visibleCategoryTitles)));
317 }
318 }
319
320 public function contentOnNonTranslatedPageDataProvider(): array
321 {
322 return [
323 [
324 'fallbackType' => 'free',
325 'fallbackChain' => ['EN'],
326 'visibleRecords' => [
327 297 => [
328 'header' => 'Regular Element #1',
329 'image' => ['T3BOARD'],
330 ],
331 298 => [
332 'header' => 'Regular Element #2',
333 'image' => ['Kasper2'],
334 ],
335 299 => [
336 'header' => 'Regular Element #3',
337 'image' => ['Kasper'],
338 ],
339 ],
340 ],
341 [
342 'fallbackType' => 'free',
343 'fallbackChain' => ['DK', 'EN'],
344 'visibleRecords' => [
345 300 => [
346 'header' => '[Translate to Dansk:] Regular Element #3',
347 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
348 ],
349 301 => [
350 'header' => '[Translate to Dansk:] Regular Element #1',
351 'image' => [],
352 ],
353 303 => [
354 'header' => '[DK] Without default language',
355 'image' => ['[T3BOARD] Image added to DK element without default language'],
356 ],
357 308 => [
358 'header' => '[DK] UnHidden Element #4',
359 'image' => [],
360 ],
361 ],
362 ],
363 [
364 'fallbackType' => 'free',
365 'fallbackChain' => [],
366 'visibleRecords' => [],
367 'statusCode' => 404,
368 ],
369 // falling back to default language
370 [
371 'fallbackType' => 'fallback',
372 'fallbackChain' => ['EN'],
373 'visibleRecords' => [
374 297 => [
375 'header' => 'Regular Element #1',
376 'image' => ['T3BOARD'],
377 ],
378 298 => [
379 'header' => 'Regular Element #2',
380 'image' => ['Kasper2'],
381 ],
382 299 => [
383 'header' => 'Regular Element #3',
384 'image' => ['Kasper'],
385 ],
386 ],
387 ],
388 // Dutch elements are shown because of the fallback chain 1,0 - first Dutch, then default language
389 // note that '[DK] Without default language' is NOT shown - due to overlays (fetch default language and overlay it with translations)
390 [
391 'fallbackType' => 'fallback',
392 'fallbackChain' => ['DK', 'EN'],
393 'visibleRecords' => [
394 297 => [
395 'header' => '[Translate to Dansk:] Regular Element #1',
396 'image' => [],
397 ],
398 298 => [
399 'header' => 'Regular Element #2',
400 'image' => ['Kasper2'],
401 ],
402 299 => [
403 'header' => '[Translate to Dansk:] Regular Element #3',
404 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
405 ],
406 ],
407 ],
408 [
409 'fallbackType' => 'fallback',
410 'fallbackChain' => [],
411 'visibleRecords' => [],
412 'statusCode' => 404
413 ],
414 [
415 'fallbackType' => 'fallback',
416 'fallbackChain' => ['DK', 'EN'],
417 'visibleRecords' => [
418 297 => [
419 'header' => '[Translate to Dansk:] Regular Element #1',
420 'image' => [],
421 ],
422 298 => [
423 'header' => 'Regular Element #2',
424 'image' => ['Kasper2'],
425 ],
426 299 => [
427 'header' => '[Translate to Dansk:] Regular Element #3',
428 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
429 ],
430 ],
431 ],
432 [
433 'fallbackType' => 'strict',
434 'fallbackChain' => ['EN'],
435 'visibleRecords' => [
436 297 => [
437 'header' => 'Regular Element #1',
438 'image' => ['T3BOARD'],
439 ],
440 298 => [
441 'header' => 'Regular Element #2',
442 'image' => ['Kasper2'],
443 ],
444 299 => [
445 'header' => 'Regular Element #3',
446 'image' => ['Kasper'],
447 ],
448 ],
449 ],
450 [
451 'fallbackType' => 'strict',
452 'fallbackChain' => ['DK', 'EN'],
453 'visibleRecords' => [
454 297 => [
455 'header' => '[Translate to Dansk:] Regular Element #1',
456 'image' => [],
457 ],
458 299 => [
459 'header' => '[Translate to Dansk:] Regular Element #3',
460 'image' => ['[Kasper] Image translated to Dansk', '[T3BOARD] Image added in Dansk (without parent)'],
461 ],
462 ],
463 ],
464 [
465 'fallbackType' => 'strict',
466 'fallbackChain' => [],
467 'visibleRecords' => [],
468 'statusCode' => 404,
469 ],
470 ];
471 }
472
473 /**
474 * Page uid 89 is NOT translated to german
475 *
476 * @test
477 * @dataProvider contentOnNonTranslatedPageDataProvider
478 *
479 * @param string $fallbackType
480 * @param array $fallbackChain
481 * @param array $visibleRecords
482 * @param int $statusCode '200' or '404'
483 */
484 public function contentOnNonTranslatedPageGerman(string $fallbackType, array $fallbackChain, array $visibleRecords, int $statusCode = 200): void
485 {
486 $this->writeSiteConfiguration(
487 'main',
488 $this->buildSiteConfiguration(1, 'https://website.local/'),
489 [
490 $this->buildDefaultLanguageConfiguration('EN', '/en/'),
491 $this->buildLanguageConfiguration('DK', '/dk/'),
492 $this->buildLanguageConfiguration('DE', '/de/', $fallbackChain, $fallbackType)
493 ],
494 [
495 $this->buildErrorHandlingConfiguration('Fluid', [404])
496 ]
497 );
498
499 if ($statusCode === 404) {
500 $this->expectExceptionCode(1518472189);
501 $this->expectException(PageNotFoundException::class);
502 }
503
504 $response = $this->executeFrontendRequest(
505 new InternalRequest('https://website.local/de/?id=' . static::VALUE_PageId)
506 );
507
508 if ($statusCode === 200) {
509 $visibleHeaders = array_column($visibleRecords, 'header');
510 $responseStructure = ResponseContent::fromString((string)$response->getBody());
511 $responseSections = $responseStructure->getSection('Extbase:list()');
512 $this->assertThat(
513 $responseSections,
514 $this->getRequestSectionHasRecordConstraint()
515 ->setTable(self::TABLE_Content)
516 ->setField('header')
517 ->setValues(...$visibleHeaders)
518 );
519 $this->assertThat(
520 $responseSections,
521 $this->getRequestSectionDoesNotHaveRecordConstraint()
522 ->setTable(self::TABLE_Content)
523 ->setField('header')
524 ->setValues(...$this->getNonVisibleHeaders($visibleHeaders))
525 );
526
527 foreach ($visibleRecords as $ttContentUid => $properties) {
528 $visibleFileTitles = $properties['image'];
529 if (!empty($visibleFileTitles)) {
530 $this->assertThat($responseSections, $this->getRequestSectionStructureHasRecordConstraint()
531 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('image')
532 ->setTable('sys_file_reference')->setField('title')->setValues(...$visibleFileTitles));
533 }
534 $this->assertThat($responseSections, $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
535 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('image')
536 ->setTable('sys_file_reference')->setField('title')->setValues(...$this->getNonVisibleFileTitles($visibleFileTitles)));
537 }
538 }
539 $this->assertEquals($statusCode, $response->getStatusCode());
540 }
541
542 public function contentOnPartiallyTranslatedPageDataProvider(): array
543 {
544 // Expected behaviour:
545 // Setting sys_language_mode to different values doesn't influence the result as the requested page is translated to Polish,
546 // Page title is always [PL]Page, and both sys_language_content and sys_language_uid are always 3
547 return [
548 [
549 'fallbackType' => 'free',
550 'fallbackChain' => [],
551 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
552 ],
553 [
554 'fallbackType' => 'free',
555 'fallbackChain' => ['EN'],
556 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
557 ],
558 [
559 'fallbackType' => 'free',
560 'fallbackChain' => ['DK', 'EN'],
561 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', '[PL] Without default language'],
562 ],
563 [
564 'fallbackType' => 'fallback',
565 'fallbackChain' => ['EN'],
566 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
567 ],
568 // Expected behaviour:
569 // Not translated element #2 is shown
570 [
571 'fallbackType' => 'fallback',
572 'fallbackChain' => ['EN'],
573 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
574 ],
575 // Expected behaviour:
576 // Element #3 is not translated in PL and it is translated in DK. It's not shown as fallback chain is not related to single CE level
577 // but on page level - and this page is translated to Polish, so no fallback is happening
578 [
579 'fallbackType' => 'fallback',
580 'fallbackChain' => ['DK', 'EN'],
581 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1', 'Regular Element #2', 'Regular Element #3'],
582 ],
583 // Expected behaviour:
584 // Non translated default language elements are not shown, because of strict mode
585 [
586 'fallbackType' => 'strict',
587 'fallbackChain' => [],
588 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1'],
589 ],
590 [
591 'fallbackType' => 'strict',
592 'fallbackChain' => ['EN'],
593 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1'],
594 ],
595 [
596 'fallbackType' => 'strict',
597 'fallbackChain' => ['DK', 'EN'],
598 'visibleRecordHeaders' => ['[Translate to Polski:] Regular Element #1'],
599 ],
600 ];
601 }
602
603 /**
604 * Page uid 89 is translated to to Polish, but not all CE are translated
605 *
606 * @test
607 * @dataProvider contentOnPartiallyTranslatedPageDataProvider
608 *
609 * @param string $fallbackType
610 * @param array $fallbackChain
611 * @param array $visibleHeaders
612 */
613 public function contentOnPartiallyTranslatedPage(string $fallbackType, array $fallbackChain, array $visibleHeaders): void
614 {
615 $this->writeSiteConfiguration(
616 'test',
617 $this->buildSiteConfiguration(1, 'https://website.local/'),
618 [
619 $this->buildDefaultLanguageConfiguration('EN', '/en/'),
620 $this->buildLanguageConfiguration('DK', '/dk/'),
621 $this->buildLanguageConfiguration('PL', '/pl/', $fallbackChain, $fallbackType)
622 ],
623 [
624 $this->buildErrorHandlingConfiguration('Fluid', [404])
625 ]
626 );
627 $response = $this->executeFrontendRequest(
628 new InternalRequest('https://website.local/pl/?id=' . static::VALUE_PageId)
629 );
630 $responseStructure = ResponseContent::fromString((string)$response->getBody());
631 $responseSections = $responseStructure->getSections('Extbase:list()');
632
633 $this->assertEquals(200, $response->getStatusCode());
634
635 $this->assertThat(
636 $responseSections,
637 $this->getRequestSectionHasRecordConstraint()
638 ->setTable(self::TABLE_Content)
639 ->setField('header')
640 ->setValues(...$visibleHeaders)
641 );
642 $this->assertThat(
643 $responseSections,
644 $this->getRequestSectionDoesNotHaveRecordConstraint()
645 ->setTable(self::TABLE_Content)
646 ->setField('header')
647 ->setValues(...$this->getNonVisibleHeaders($visibleHeaders))
648 );
649 }
650
651 /**
652 * Helper function to ease asserting that rest of the data set is not visible
653 *
654 * @param array $visibleHeaders
655 * @return array
656 */
657 protected function getNonVisibleHeaders(array $visibleHeaders): array
658 {
659 $allElements = [
660 'Regular Element #1',
661 'Regular Element #2',
662 'Regular Element #3',
663 'Hidden Element #4',
664 '[Translate to Dansk:] Regular Element #1',
665 '[Translate to Dansk:] Regular Element #3',
666 '[DK] Without default language',
667 '[DK] UnHidden Element #4',
668 '[DE] Without default language',
669 '[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1',
670 '[Translate to Polski:] Regular Element #1',
671 '[PL] Without default language',
672 '[PL] Hidden Regular Element #2'
673 ];
674 return array_diff($allElements, $visibleHeaders);
675 }
676
677 /**
678 * Helper function to ease asserting that rest of the data set is not visible
679 *
680 * @param array $visibleTitles
681 * @return array
682 */
683 protected function getNonVisibleFileTitles(array $visibleTitles): array
684 {
685 $allElements = [
686 'T3BOARD',
687 'Kasper',
688 '[Kasper] Image translated to Dansk',
689 '[T3BOARD] Image added in Dansk (without parent)',
690 '[T3BOARD] Image added to DK element without default language',
691 '[T3BOARD] image translated to DE from DK',
692 'Kasper2'
693 ];
694 return array_diff($allElements, $visibleTitles);
695 }
696
697 /**
698 * Helper function to ease asserting that rest of the data set is not visible
699 *
700 * @param array $visibleTitles
701 * @return array
702 */
703 protected function getNonVisibleCategoryTitles(array $visibleTitles): array
704 {
705 $allElements = [
706 'Category 1',
707 '[Translate to Dansk:] Category 1',
708 'Category 3 - not translated',
709 'Category 4',
710 ];
711 return array_diff($allElements, $visibleTitles);
712 }
713 }