‪TYPO3CMS  10.4
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 ‪ENCRYPTION_KEY = '4408d27a916d51e624b69af3554f516dbab61037a9f7b9fd6f81b4d3bedeccb6';
33 
34  protected const TYPO3_CONF_VARS = [
35  'SYS' => [
36  'encryptionKey' => ‪self::ENCRYPTION_KEY,
37  ],
38  'FE' => [
39  'cacheHash' => [
40  'requireCacheHashPresenceParameters' => ['value', 'testing[value]', 'tx_testing_link[value]'],
41  'excludedParameters' => ['L', 'tx_testing_link[excludedValue]'],
42  // @todo this should be tested explicitly - enabled and disabled
43  'enforceValidation' => false,
44  ],
45  ]
46  ];
47 
48  protected const LANGUAGE_PRESETS = [
49  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8', 'iso' => 'en', 'hrefLang' => 'en-US', 'direction' => ''],
50  'FR' => ['id' => 1, 'title' => 'French', 'locale' => 'fr_FR.UTF8', 'iso' => 'fr', 'hrefLang' => 'fr-FR', 'direction' => ''],
51  'FR-CA' => ['id' => 2, 'title' => 'Franco-Canadian', 'locale' => 'fr_CA.UTF8', 'iso' => 'fr', 'hrefLang' => 'fr-CA', 'direction' => ''],
52  'ES' => ['id' => 3, 'title' => 'Spanish', 'locale' => 'es_ES.UTF8', 'iso' => 'es', 'hrefLang' => 'es-ES', 'direction' => ''],
53  'ZH-CN' => ['id' => 0, 'title' => 'Simplified Chinese', 'locale' => 'zh_CN.UTF-8', 'iso' => 'zh', 'hrefLang' => 'zh-Hans', 'direction' => ''],
54  'ZH' => ['id' => 4, 'title' => 'Simplified Chinese', 'locale' => 'zh_CN.UTF-8', 'iso' => 'zh', 'hrefLang' => 'zh-Hans', 'direction' => ''],
55  ];
56 
60  protected $coreExtensionsToLoad = ['frontend', 'workspaces'];
61 
65  protected $pathsToLinkInTestInstance = [
66  'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/AdditionalConfiguration.php' => 'typo3conf/AdditionalConfiguration.php',
67  ];
68 
73  protected function wrapInArray(array $array): array
74  {
75  return array_map(
76  function ($item) {
77  return [$item];
78  },
79  $array
80  );
81  }
82 
87  protected function keysFromValues(array $array): array
88  {
89  return array_combine($array, $array);
90  }
91 
107  protected function keysFromTemplate(array $array, string $template, callable $callback = null): array
108  {
109  $keys = array_unique(
110  array_map(
111  function (array $values) use ($template, $callback) {
112  if ($callback !== null) {
113  $values = call_user_func($callback, $values);
114  }
115  return vsprintf($template, $values);
116  },
117  $array
118  )
119  );
120 
121  if (count($keys) !== count($array)) {
122  throw new \LogicException(
123  'Amount of generated keys does not match to item count.',
124  1534682840
125  );
126  }
127 
128  return array_combine($keys, $array);
129  }
130 
135  protected function createTypoLinkUrlInstruction(array $typoScript): ArrayValueInstruction
136  {
137  return (new ArrayValueInstruction(LinkHandlingController::class))
138  ->withArray([
139  '10' => 'TEXT',
140  '10.' => [
141  'typolink.' => array_merge(
142  $typoScript,
143  ['returnLast' => 'url']
144  )
145  ]
146  ]);
147  }
148 
153  protected function createHierarchicalMenuProcessorInstruction(array $typoScript): ArrayValueInstruction
154  {
155  return (new ArrayValueInstruction(LinkHandlingController::class))
156  ->withArray([
157  '10' => 'FLUIDTEMPLATE',
158  '10.' => [
159  'file' => 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/FluidJson.html',
160  'dataProcessing.' => [
161  '1' => 'TYPO3\\CMS\\Frontend\\DataProcessing\\MenuProcessor',
162  '1.' => array_merge(
163  $typoScript,
164  ['as' => 'results']
165  )
166  ],
167  ],
168  ]);
169  }
170 
175  protected function createLanguageMenuProcessorInstruction(array $typoScript): ArrayValueInstruction
176  {
177  return (new ArrayValueInstruction(LinkHandlingController::class))
178  ->withArray([
179  '10' => 'FLUIDTEMPLATE',
180  '10.' => [
181  'file' => 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/FluidJson.html',
182  'dataProcessing.' => [
183  '1' => 'TYPO3\\CMS\\Frontend\\DataProcessing\\LanguageMenuProcessor',
184  '1.' => array_merge(
185  $typoScript,
186  ['as' => 'results']
187  )
188  ],
189  ],
190  ]);
191  }
192 
200  protected function filterMenu(
201  array $menu,
202  array $keepNames = ['title', 'link']
203  ): array {
204  if (!in_array('children', $keepNames)) {
205  $keepNames[] = 'children';
206  }
207  return array_map(
208  function (array $menuItem) use ($keepNames) {
209  $menuItem = array_filter(
210  $menuItem,
211  function (string $name) use ($keepNames) {
212  return in_array($name, $keepNames);
213  },
214  ARRAY_FILTER_USE_KEY
215  );
216  if (is_array($menuItem['children'] ?? null)) {
217  $menuItem['children'] = $this->filterMenu(
218  $menuItem['children'],
219  $keepNames
220  );
221  }
222  return $menuItem;
223  },
224  $menu
225  );
226  }
227 }
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:36
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase\ENCRYPTION_KEY
‪const ENCRYPTION_KEY
Definition: AbstractTestCase.php:31
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling
Definition: AbstractTestCase.php:18