[TASK] Correctly initialize environment for DataHandler in tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Functional / SiteHandling / AbstractRequestTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Frontend\Tests\Functional\SiteHandling;
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
18 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
19
20 /**
21 * Abstract test case for frontend requests
22 */
23 abstract class AbstractRequestTest extends FunctionalTestCase
24 {
25 protected const ENCRYPTION_KEY = '4408d27a916d51e624b69af3554f516dbab61037a9f7b9fd6f81b4d3bedeccb6';
26
27 protected const TYPO3_CONF_VARS = [
28 'SYS' => [
29 'encryptionKey' => self::ENCRYPTION_KEY,
30 ],
31 'FE' => [
32 'cacheHash' => [
33 'requireCacheHashPresenceParameters' => ['testing[value]']
34 ],
35 ]
36 ];
37
38 /**
39 * @var array
40 */
41 protected $coreExtensionsToLoad = ['frontend'];
42
43 /**
44 * Combines string values of multiple array as cross-product into flat items.
45 *
46 * Example:
47 * + meltStrings(['a','b'], ['c','e'], ['f','g'])
48 * + results into ['acf', 'acg', 'aef', 'aeg', 'bcf', 'bcg', 'bef', 'beg']
49 *
50 * @param array $arrays Distinct array that should be melted
51 * @param callable $finalCallback Callback being executed on last multiplier
52 * @param string $prefix Prefix containing concatenated previous values
53 * @return array
54 */
55 protected function meltStrings(array $arrays, callable $finalCallback = null, string $prefix = ''): array
56 {
57 $results = [];
58 $array = array_shift($arrays);
59 foreach ($array as $item) {
60 $resultItem = $prefix . $item;
61 if (count($arrays) > 0) {
62 $results = array_merge(
63 $results,
64 $this->meltStrings($arrays, $finalCallback, $resultItem)
65 );
66 continue;
67 }
68 if ($finalCallback !== null) {
69 $resultItem = call_user_func($finalCallback, $resultItem);
70 }
71 $results[] = $resultItem;
72 }
73 return $results;
74 }
75
76 /**
77 * @param array $array
78 * @return array
79 */
80 protected function wrapInArray(array $array): array
81 {
82 return array_map(
83 function ($item) {
84 return [$item];
85 },
86 $array
87 );
88 }
89
90 /**
91 * @param array $array
92 * @return array
93 */
94 protected function keysFromValues(array $array): array
95 {
96 return array_combine($array, $array);
97 }
98
99 /**
100 * @param array $items
101 */
102 protected static function failIfArrayIsNotEmpty(array $items): void
103 {
104 if (empty($items)) {
105 return;
106 }
107
108 static::fail(
109 'Array was not empty as expected, but contained these items:' . LF
110 . '* ' . implode(LF . '* ', $items)
111 );
112 }
113 }