2 declare(strict_types = 1);
21 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Internal\AbstractInstruction;
22 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Internal\ArrayValueInstruction;
23 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Internal\TypoScriptInstruction;
24 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
45 'Array was not empty as expected, but contained these items:' . LF
46 .
'* ' . implode(LF .
'* ', $items)
59 array $languages = [],
60 array $errorHandling = []
62 $configuration = $site;
63 if (!empty($languages)) {
64 $configuration[
'languages'] = $languages;
66 if (!empty($errorHandling)) {
67 $configuration[
'errorHandling'] = $errorHandling;
70 $this->instancePath .
'/typo3conf/sites/'
75 GeneralUtility::rmdir($this->instancePath .
'/typo3conf/sites/' . $identifier,
true);
76 $siteConfiguration->write($identifier, $configuration);
78 $this->markTestSkipped($exception->getMessage());
91 $this->instancePath .
'/typo3conf/sites/'
93 $configuration = $siteConfiguration->load($identifier);
94 $configuration = array_merge($configuration, $overrides);
96 $siteConfiguration->write($identifier, $configuration);
98 $this->markTestSkipped($exception->getMessage());
112 'rootPageId' => $rootPageId,
126 $configuration = $this->buildLanguageConfiguration($identifier, $base);
127 $configuration[
'typo3Language'] =
'default';
128 $configuration[
'flag'] =
'global';
129 unset($configuration[
'fallbackType'], $configuration[
'fallbacks']);
130 return $configuration;
143 array $fallbackIdentifiers = [],
144 string $fallbackType =
null
146 $preset = $this->resolveLanguagePreset($identifier);
149 'languageId' => $preset[
'id'],
150 'title' => $preset[
'title'],
151 'navigationTitle' => $preset[
'title'],
153 'locale' => $preset[
'locale'],
154 'iso-639-1' => $preset[
'iso'],
155 'hreflang' => $preset[
'hrefLang'],
156 'direction' => $preset[
'direction'],
157 'typo3Language' => $preset[
'iso'],
158 'flag' => $preset[
'iso'],
159 'fallbackType' => $fallbackType ?? (empty($fallbackIdentifiers) ?
'strict' :
'fallback'),
162 if (!empty($fallbackIdentifiers)) {
163 $fallbackIds = array_map(
164 function (
string $fallbackIdentifier) {
165 $preset = $this->resolveLanguagePreset($fallbackIdentifier);
166 return $preset[
'id'];
170 $configuration[
'fallbackType'] = $fallbackType ??
'fallback';
171 $configuration[
'fallbacks'] = implode(
',', $fallbackIds);
174 return $configuration;
186 if ($handler ===
'Page') {
187 $baseConfiguration = [
188 'errorContentSource' =>
'404',
190 } elseif ($handler ===
'Fluid') {
191 $baseConfiguration = [
192 'errorFluidTemplate' =>
'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/FluidError.html',
193 'errorFluidTemplatesRootPath' =>
'',
194 'errorFluidLayoutsRootPath' =>
'',
195 'errorFluidPartialsRootPath' =>
'',
197 } elseif ($handler ===
'PHP') {
198 $baseConfiguration = [
199 'errorPhpClassFQCN' => PhpError::class,
202 throw new \LogicException(
203 sprintf(
'Invalid handler "%s"', $handler),
208 $baseConfiguration[
'errorHandler'] = $handler;
211 function (
int $code) use ($baseConfiguration) {
212 $baseConfiguration[
'errorCode'] = $code;
213 return $baseConfiguration;
225 if (!isset(static::LANGUAGE_PRESETS[$identifier])) {
226 throw new \LogicException(
227 sprintf(
'Undefined preset identifier "%s"', $identifier),
231 return static::LANGUAGE_PRESETS[$identifier];
241 protected function applyInstructions(InternalRequest $request, AbstractInstruction ...$instructions): InternalRequest
243 $modifiedInstructions = [];
245 foreach ($instructions as $instruction) {
246 $identifier = $instruction->getIdentifier();
247 if (isset($modifiedInstructions[$identifier]) || $request->getInstruction($identifier) !==
null) {
248 $modifiedInstructions[$identifier] = $this->mergeInstruction(
249 $modifiedInstructions[$identifier] ?? $request->getInstruction($identifier),
253 $modifiedInstructions[$identifier] = $instruction;
257 return $request->withInstructions($modifiedInstructions);
265 protected function mergeInstruction(AbstractInstruction $current, AbstractInstruction $other): AbstractInstruction
267 if (get_class($current) !== get_class($other)) {
268 throw new \LogicException(
'Cannot merge different instruction types', 1565863174);
271 if ($current instanceof TypoScriptInstruction) {
273 $typoScript = array_replace_recursive(
274 $current->getTypoScript() ?? [],
275 $other->getTypoScript() ?? []
277 $constants = array_replace_recursive(
278 $current->getConstants() ?? [],
279 $other->getConstants() ?? []
281 if ($typoScript !== []) {
282 $current = $current->withTypoScript($typoScript);
284 if ($constants !== []) {
285 $current = $current->withConstants($constants);
290 if ($current instanceof ArrayValueInstruction) {
292 $array = array_merge_recursive($current->getArray(), $other->getArray());
293 return $current->withArray($array);