‪TYPO3CMS  11.5
AbstractTestCase.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\Frontend\Internal\ArrayValueInstruction;
23 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24 
28 abstract class ‪AbstractTestCase extends FunctionalTestCase
29 {
31 
32  protected const ‪LANGUAGE_PRESETS = [
33  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8', 'iso' => 'en', 'hrefLang' => 'en-US', 'direction' => ''],
34  'FR' => ['id' => 1, 'title' => 'French', 'locale' => 'fr_FR.UTF8', 'iso' => 'fr', 'hrefLang' => 'fr-FR', 'direction' => ''],
35  'FR-CA' => ['id' => 2, 'title' => 'Franco-Canadian', 'locale' => 'fr_CA.UTF8', 'iso' => 'fr', 'hrefLang' => 'fr-CA', 'direction' => ''],
36  'ES' => ['id' => 3, 'title' => 'Spanish', 'locale' => 'es_ES.UTF8', 'iso' => 'es', 'hrefLang' => 'es-ES', 'direction' => ''],
37  'ZH-CN' => ['id' => 0, 'title' => 'Simplified Chinese', 'locale' => 'zh_CN.UTF-8', 'iso' => 'zh', 'hrefLang' => 'zh-Hans', 'direction' => ''],
38  'ZH' => ['id' => 4, 'title' => 'Simplified Chinese', 'locale' => 'zh_CN.UTF-8', 'iso' => 'zh', 'hrefLang' => 'zh-Hans', 'direction' => ''],
39  ];
40 
42  'SYS' => [
43  'encryptionKey' => '4408d27a916d51e624b69af3554f516dbab61037a9f7b9fd6f81b4d3bedeccb6',
44  ],
45  'FE' => [
46  'cacheHash' => [
47  'requireCacheHashPresenceParameters' => ['value', 'testing[value]', 'tx_testing_link[value]'],
48  'excludedParameters' => ['L', 'tx_testing_link[excludedValue]'],
49  // @todo this should be tested explicitly - enabled and disabled
50  'enforceValidation' => false,
51  ],
52  'debug' => false,
53  ],
54  'SC_OPTIONS' => [
55  'Core/TypoScript/TemplateService' => [
56  'runThroughTemplatesPostProcessing' => [
57  'FunctionalTest' => \TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Hook\TypoScriptInstructionModifier::class . '->apply',
58  ],
59  ],
60  ],
61  ];
62 
63  protected ‪$coreExtensionsToLoad = ['workspaces'];
64 
69  protected function ‪wrapInArray(array $array): array
70  {
71  return array_map(
72  static function ($item) {
73  return [$item];
74  },
75  $array
76  );
77  }
78 
83  protected function ‪keysFromValues(array $array): array
84  {
85  return array_combine($array, $array);
86  }
87 
103  protected function ‪keysFromTemplate(array $array, string $template, callable $callback = null): array
104  {
105  $keys = array_unique(
106  array_map(
107  static function (array $values) use ($template, $callback) {
108  if ($callback !== null) {
109  $values = $callback($values);
110  }
111  return vsprintf($template, $values);
112  },
113  $array
114  )
115  );
116 
117  if (count($keys) !== count($array)) {
118  throw new \LogicException(
119  'Amount of generated keys does not match to item count.',
120  1534682840
121  );
122  }
123 
124  return array_combine($keys, $array);
125  }
126 
131  protected function ‪createTypoLinkUrlInstruction(array $typoScript): ArrayValueInstruction
132  {
133  return (new ArrayValueInstruction(LinkHandlingController::class))
134  ->withArray([
135  '10' => 'TEXT',
136  '10.' => [
137  'typolink.' => array_merge(
138  $typoScript,
139  ['returnLast' => 'url']
140  ),
141  ],
142  ]);
143  }
144 
149  protected function ‪createHierarchicalMenuProcessorInstruction(array $typoScript): ArrayValueInstruction
150  {
151  return (new ArrayValueInstruction(LinkHandlingController::class))
152  ->withArray([
153  '10' => 'FLUIDTEMPLATE',
154  '10.' => [
155  'file' => 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/FluidJson.html',
156  'dataProcessing.' => [
157  '1' => 'TYPO3\\CMS\\Frontend\\DataProcessing\\MenuProcessor',
158  '1.' => array_merge(
159  $typoScript,
160  ['as' => 'results']
161  ),
162  ],
163  ],
164  ]);
165  }
166 
171  protected function ‪createLanguageMenuProcessorInstruction(array $typoScript): ArrayValueInstruction
172  {
173  return (new ArrayValueInstruction(LinkHandlingController::class))
174  ->withArray([
175  '10' => 'FLUIDTEMPLATE',
176  '10.' => [
177  'file' => 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/FluidJson.html',
178  'dataProcessing.' => [
179  '1' => 'TYPO3\\CMS\\Frontend\\DataProcessing\\LanguageMenuProcessor',
180  '1.' => array_merge(
181  $typoScript,
182  ['as' => 'results']
183  ),
184  ],
185  ],
186  ]);
187  }
188 
196  protected function ‪filterMenu(
197  array $menu,
198  array $keepNames = ['title', 'link']
199  ): array {
200  if (!in_array('children', $keepNames, true)) {
201  $keepNames[] = 'children';
202  }
203  return array_map(
204  function (array $menuItem) use ($keepNames) {
205  $menuItem = array_filter(
206  $menuItem,
207  static function (string $name) use ($keepNames) {
208  return in_array($name, $keepNames);
209  },
210  ARRAY_FILTER_USE_KEY
211  );
212  if (is_array($menuItem['children'] ?? null)) {
213  $menuItem['children'] = $this->‪filterMenu(
214  $menuItem['children'],
215  $keepNames
216  );
217  }
218  return $menuItem;
219  },
220  $menu
221  );
222  }
223 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase\filterMenu
‪array filterMenu(array $menu, array $keepNames=['title', 'link'])
Definition: AbstractTestCase.php:195
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:36
‪TYPO3
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase\keysFromTemplate
‪array keysFromTemplate(array $array, string $template, callable $callback=null)
Definition: AbstractTestCase.php:102
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase\$coreExtensionsToLoad
‪$coreExtensionsToLoad
Definition: AbstractTestCase.php:62
‪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\Frontend\Tests\Functional\SiteHandling\AbstractTestCase\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: AbstractTestCase.php:31
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase\createTypoLinkUrlInstruction
‪ArrayValueInstruction createTypoLinkUrlInstruction(array $typoScript)
Definition: AbstractTestCase.php:130
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase\wrapInArray
‪array wrapInArray(array $array)
Definition: AbstractTestCase.php:68
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase\keysFromValues
‪array keysFromValues(array $array)
Definition: AbstractTestCase.php:82
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling
Definition: AbstractTestCase.php:18
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase\$configurationToUseInTestInstance
‪$configurationToUseInTestInstance
Definition: AbstractTestCase.php:40