‪TYPO3CMS  11.5
AbstractLocalizedPagesTestCase.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 
19 
22 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerFactory;
23 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerWriter;
24 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
25 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\ResponseContent;
26 
28 {
29  protected const ‪LANGUAGE_PRESETS = [
30  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8', 'iso' => 'en', 'hrefLang' => 'en-US', 'direction' => ''],
31  'DE' => ['id' => 1, 'title' => 'German', 'locale' => 'de_DE.UTF8', 'iso' => 'de', 'hrefLang' => 'de-DE', 'direction' => ''],
32  'DE-CH' => ['id' => 2, 'title' => 'Swiss German', 'locale' => 'de_CH.UTF8', 'iso' => 'de', 'hrefLang' => 'de-CH', 'direction' => ''],
33  ];
34 
35  protected function ‪setUpDatabaseWithYamlPayload(string $pathToYamlFile): void
36  {
37  $this->withDatabaseSnapshot(function () use ($pathToYamlFile) {
38  $backendUser = $this->setUpBackendUserFromFixture(1);
40 
41  $factory = DataHandlerFactory::fromYamlFile($pathToYamlFile);
42  $writer = DataHandlerWriter::withBackendUser($backendUser);
43  $writer->invokeFactory($factory);
44  static::failIfArrayIsNotEmpty(
45  $writer->getErrors()
46  );
47  });
48  }
49 
54  protected function ‪assertScopes(string $url, array $scopes): void
55  {
56  $this->setUpFrontendRootPage(
57  1000,
58  ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript'],
59  [
60  'title' => 'ACME Root',
61  ]
62  );
63 
64  $response = $this->executeFrontendSubRequest(new InternalRequest($url));
65  $responseStructure = ResponseContent::fromString((string)$response->getBody());
66 
67  foreach ($scopes as $scopePath => $expectedScopeValue) {
68  self::assertSame($expectedScopeValue, $responseStructure->getScopePath($scopePath));
69  }
70  }
71 
75  protected function ‪assertResponseStatusCode(string $url): void
76  {
77  $this->setUpFrontendRootPage(
78  1000,
79  ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript']
80  );
81 
82  $response = $this->executeFrontendSubRequest(new InternalRequest($url));
83  self::assertSame(404, $response->getStatusCode());
84  }
85 
90  protected function ‪assertMenu(string $url, array $expectation): void
91  {
92  $this->setUpFrontendRootPage(
93  1000,
94  ['typo3/sysext/frontend/Tests/Functional/SiteHandling/Fixtures/LinkGenerator.typoscript'],
95  [
96  'title' => 'ACME Root',
97  ]
98  );
99 
100  $response = $this->executeFrontendSubRequest(
101  (new InternalRequest($url))
102  ->withInstructions([
104  'levels' => 1,
105  'entryLevel' => 0,
106  'expandAll' => 1,
107  'includeSpacer' => 1,
108  'titleField' => 'title',
109  'as' => 'results',
110  ]),
111  ])
112  );
113 
114  $json = json_decode((string)$response->getBody(), true);
115  $json = $this->‪filterMenu($json);
116 
117  self::assertSame($expectation, $json);
118  }
119 
120  protected function ‪createLanguageMenu(string $url): array
121  {
122  $this->setUpFrontendRootPage(
123  1000,
124  ['typo3/sysext/frontend/Tests/Functional/SiteHandling/Fixtures/LinkGenerator.typoscript'],
125  ['title' => 'ACME Root']
126  );
127 
128  $response = $this->executeFrontendSubRequest(
129  (new InternalRequest($url))->withInstructions([$this->‪createLanguageMenuProcessorInstruction(['languages' => 'auto'])])
130  );
131 
132  $json = json_decode((string)$response->getBody(), true);
133  $json = $this->‪filterMenu($json);
134 
135  return $json;
136  }
137 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\assertScopes
‪assertScopes(string $url, array $scopes)
Definition: AbstractLocalizedPagesTestCase.php:54
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase\filterMenu
‪array filterMenu(array $menu, array $keepNames=['title', 'link'])
Definition: AbstractTestCase.php:195
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\assertResponseStatusCode
‪assertResponseStatusCode(string $url)
Definition: AbstractLocalizedPagesTestCase.php:75
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering
Definition: AbstractLocalizedPagesTestCase.php:18
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase
Definition: AbstractLocalizedPagesTestCase.php:28
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase\createHierarchicalMenuProcessorInstruction
‪ArrayValueInstruction createHierarchicalMenuProcessorInstruction(array $typoScript)
Definition: AbstractTestCase.php:148
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase\createLanguageMenuProcessorInstruction
‪ArrayValueInstruction createLanguageMenuProcessorInstruction(array $typoScript)
Definition: AbstractTestCase.php:170
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:598
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\assertMenu
‪assertMenu(string $url, array $expectation)
Definition: AbstractLocalizedPagesTestCase.php:90
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\createLanguageMenu
‪createLanguageMenu(string $url)
Definition: AbstractLocalizedPagesTestCase.php:120
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\setUpDatabaseWithYamlPayload
‪setUpDatabaseWithYamlPayload(string $pathToYamlFile)
Definition: AbstractLocalizedPagesTestCase.php:35
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:70
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: AbstractLocalizedPagesTestCase.php:29