‪TYPO3CMS  ‪main
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'],
34  'FR' => ['id' => 1, 'title' => 'French', 'locale' => 'fr_FR.UTF8'],
35  'FR-CA' => ['id' => 2, 'title' => 'Franco-Canadian', 'locale' => 'fr_CA.UTF8'],
36  'ES' => ['id' => 3, 'title' => 'Spanish', 'locale' => 'es_ES.UTF8'],
37  'ZH-CN' => ['id' => 0, 'title' => 'Simplified Chinese', 'locale' => 'zh_CN.UTF-8'],
38  'ZH' => ['id' => 4, 'title' => 'Simplified Chinese', 'locale' => 'zh_CN.UTF-8'],
39  ];
40 
41  protected array $configurationToUseInTestInstance = [
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  ];
55 
56  protected array $coreExtensionsToLoad = ['workspaces'];
57 
58  protected static function wrapInArray(array $array): array
59  {
60  return array_map(
61  static function ($item) {
62  return [$item];
63  },
64  $array
65  );
66  }
67 
71  protected static function keysFromValues(array $array): array
72  {
73  return array_combine($array, $array);
74  }
75 
86  protected static function keysFromTemplate(array $array, string $template, callable $callback = null): array
87  {
88  $keys = array_unique(
89  array_map(
90  static function (array $values) use ($template, $callback) {
91  if ($callback !== null) {
92  $values = $callback($values);
93  }
94  return vsprintf($template, $values);
95  },
96  $array
97  )
98  );
99 
100  if (count($keys) !== count($array)) {
101  throw new \LogicException(
102  'Amount of generated keys does not match to item count.',
103  1534682840
104  );
105  }
106 
107  return array_combine($keys, $array);
108  }
109 
110  protected function createTypoLinkUrlInstruction(array $typoScript): ArrayValueInstruction
111  {
112  return (new ArrayValueInstruction(LinkHandlingController::class))
113  ->withArray([
114  '10' => 'TEXT',
115  '10.' => [
116  'typolink.' => array_merge(
117  $typoScript,
118  ['returnLast' => 'url']
119  ),
120  ],
121  ]);
122  }
123 
124  protected function createTypoLinkTagInstruction(array $typoScript): ArrayValueInstruction
125  {
126  return (new ArrayValueInstruction(LinkHandlingController::class))
127  ->withArray([
128  '10' => 'TEXT',
129  '10.' => [
130  'typolink.' => $typoScript,
131  ],
132  ]);
133  }
134 
135  protected function createHierarchicalMenuProcessorInstruction(array $typoScript): ArrayValueInstruction
136  {
137  return (new ArrayValueInstruction(LinkHandlingController::class))
138  ->withArray([
139  '10' => 'FLUIDTEMPLATE',
140  '10.' => [
141  'file' => 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/FluidJson.html',
142  'dataProcessing.' => [
143  '1' => 'TYPO3\\CMS\\Frontend\\DataProcessing\\MenuProcessor',
144  '1.' => array_merge(
145  $typoScript,
146  ['as' => 'results']
147  ),
148  ],
149  ],
150  ]);
151  }
152 
153  protected function createLanguageMenuProcessorInstruction(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\\LanguageMenuProcessor',
162  '1.' => array_merge(
163  $typoScript,
164  ['as' => 'results']
165  ),
166  ],
167  ],
168  ]);
169  }
170 
174  protected function filterMenu(
175  array $menu,
176  array $keepNames = ['title', 'link']
177  ): array {
178  if (!in_array('children', $keepNames, true)) {
179  $keepNames[] = 'children';
180  }
181  return array_map(
182  function (array $menuItem) use ($keepNames) {
183  $menuItem = array_filter(
184  $menuItem,
185  static function (string $name) use ($keepNames) {
186  return in_array($name, $keepNames);
187  },
188  ARRAY_FILTER_USE_KEY
189  );
190  if (is_array($menuItem['children'] ?? null)) {
191  $menuItem['children'] = $this->filterMenu(
192  $menuItem['children'],
193  $keepNames
194  );
195  }
196  return $menuItem;
197  },
198  $menu
199  );
200  }
201 }
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:37
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: AbstractTestCase.php:31
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling
Definition: AbstractTestCase.php:18