b88861c9ba7280d5e2dddd01902e722584552528
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Functional / SiteHandling / AbstractRequestTest.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Functional\SiteHandling;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
18
19 /**
20 * Abstract test case for frontend requests
21 */
22 abstract class AbstractRequestTest extends FunctionalTestCase
23 {
24 protected const ENCRYPTION_KEY = '4408d27a916d51e624b69af3554f516dbab61037a9f7b9fd6f81b4d3bedeccb6';
25
26 protected const TYPO3_CONF_VARS = [
27 'SYS' => [
28 'encryptionKey' => self::ENCRYPTION_KEY,
29 ],
30 'FE' => [
31 'cacheHash' => [
32 'requireCacheHashPresenceParameters' => ['testing[value]']
33 ],
34 ]
35 ];
36
37 /**
38 * @var array
39 */
40 protected $coreExtensionsToLoad = ['frontend'];
41
42 /**
43 * Combines string values of multiple array as cross-product into flat items.
44 *
45 * Example:
46 * + meltStrings(['a','b'], ['c','e'], ['f','g'])
47 * + results into ['acf', 'acg', 'aef', 'aeg', 'bcf', 'bcg', 'bef', 'beg']
48 *
49 * @param array $arrays Distinct array that should be melted
50 * @param callable $finalCallback Callback being executed on last multiplier
51 * @param string $prefix Prefix containing concatenated previous values
52 * @return array
53 */
54 protected function meltStrings(array $arrays, callable $finalCallback = null, string $prefix = ''): array
55 {
56 $results = [];
57 $array = array_shift($arrays);
58 foreach ($array as $item) {
59 $resultItem = $prefix . $item;
60 if (count($arrays) > 0) {
61 $results = array_merge(
62 $results,
63 $this->meltStrings($arrays, $finalCallback, $resultItem)
64 );
65 continue;
66 }
67 if ($finalCallback !== null) {
68 $resultItem = call_user_func($finalCallback, $resultItem);
69 }
70 $results[] = $resultItem;
71 }
72 return $results;
73 }
74
75 /**
76 * @param array $array
77 * @return array
78 */
79 protected function wrapInArray(array $array): array
80 {
81 return array_map(
82 function ($item) {
83 return [$item];
84 },
85 $array
86 );
87 }
88
89 /**
90 * @param array $array
91 * @return array
92 */
93 protected function keysFromValues(array $array): array
94 {
95 return array_combine($array, $array);
96 }
97 }