‪TYPO3CMS  9.5
Builder.php
Go to the documentation of this file.
1 <?php
2 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 {
20  public static function ‪create(): self
21  {
22  return new static();
23  }
24 
28  public function ‪declareEnhancers(): array
29  {
30  $routePath = ‪VariableValue::create(
31  '/[[routePrefix]]/[[routeParameter]]',
32  ‪Variables::create(['routeParameter' => '{value}'])
33  );
34  $resolveValue = ‪Variable::create('resolveValue', ‪Variable::CAST_STRING);
35 
36  return [
37  'Simple' => ‪EnhancerDeclaration::create('Simple')
38  ->withConfiguration([
39  'type' => 'Simple',
40  'routePath' => $routePath,
41  '_arguments' => [],
42  ])
43  ->withGenerateParameters([
44  ‪VariableValue::create('&value=[[value]]')
45  ->withRequiredDefinedVariableNames('value'),
46  ])
47  ->withResolveArguments([
48  ‪VariableItem::create('inArguments', [
49  'value' => $resolveValue
50  ]),
51  ]),
52  'Plugin' => ‪EnhancerDeclaration::create('Plugin')
53  ->withConfiguration([
54  'type' => 'Plugin',
55  'routePath' => $routePath,
56  'namespace' => 'testing',
57  '_arguments' => [],
58  ])
59  ->withGenerateParameters([
60  ‪VariableValue::create('&testing[value]=[[value]]')
61  ->withRequiredDefinedVariableNames('value'),
62  ])
63  ->withResolveArguments([
64  ‪VariableItem::create('inArguments', [
65  'testing' => [
66  'value' => $resolveValue,
67  ],
68  ]),
69  ]),
70  'Extbase' => ‪EnhancerDeclaration::create('Extbase')
71  ->withConfiguration([
72  'type' => 'Extbase',
73  'routes' => [
74  [
75  'routePath' => $routePath,
76  '_controller' => 'Link::index',
77  '_arguments' => [],
78  ],
79  ],
80  'extension' => 'testing',
81  'plugin' => 'link',
82  ])
83  ->withGenerateParameters([
84  ‪VariableValue::create('&tx_testing_link[value]=[[value]]')
85  ->withRequiredDefinedVariableNames('value'),
86  '&tx_testing_link[controller]=Link&tx_testing_link[action]=index',
87  ])
88  ->withResolveArguments([
89  ‪VariableItem::create('inArguments', [
90  'tx_testing_link' => [
91  'value' => $resolveValue,
92  ],
93  ]),
94  'staticArguments' => [
95  'tx_testing_link' => [
96  'controller' => 'Link',
97  'action' => 'index',
98  ],
99  ],
100  ])
101  ];
102  }
103 
107  public function ‪declarePageTypes(): array
108  {
109  $multipleTypesConfiguration = [
110  'type' => 'PageType',
111  'default' => '.html',
112  'index' => 'index',
113  'map' => [
114  '.html' => 0,
115  'menu.json' => 10,
116  '.xml' => 20
117  ],
118  ];
119  $singleTypeConfiguration = [
120  'type' => 'PageType',
121  'default' => '/',
122  'index' => '/',
123  'map' => [
124  'menu.json' => 10,
125  ],
126  ];
127 
128  return [
129  ‪PageTypeDeclaration::create('null ".html"')
130  ->withConfiguration($multipleTypesConfiguration)
131  ->withResolveArguments(['pageType' => 0])
132  ->withVariables(‪Variables::create(['pathSuffix' => '.html', 'index' => 'index'])),
133  ‪PageTypeDeclaration::create('0 ".html"')
134  ->withConfiguration($multipleTypesConfiguration)
135  ->withGenerateParameters(['&type=0'])
136  ->withResolveArguments(['pageType' => 0])
137  ->withVariables(‪Variables::create(['pathSuffix' => '.html', 'index' => 'index'])),
138  ‪PageTypeDeclaration::create('10 "/menu.json"')
139  ->withConfiguration($multipleTypesConfiguration)
140  ->withGenerateParameters(['&type=10'])
141  ->withResolveArguments(['pageType' => 10])
142  ->withVariables(‪Variables::create(['pathSuffix' => '/menu.json', 'index' => ''])),
143  ‪PageTypeDeclaration::create('20 ".xml"')
144  ->withConfiguration($multipleTypesConfiguration)
145  ->withGenerateParameters(['&type=20'])
146  ->withResolveArguments(['pageType' => 20])
147  ->withVariables(‪Variables::create(['pathSuffix' => '.xml', 'index' => 'index'])),
149  ->withConfiguration($singleTypeConfiguration)
150  ->withResolveArguments(['pageType' => 0])
151  ->withVariables(‪Variables::create(['pathSuffix' => '/', 'index' => ''])),
153  ->withConfiguration($singleTypeConfiguration)
154  ->withGenerateParameters(['&type=0'])
155  ->withResolveArguments(['pageType' => 0])
156  ->withVariables(‪Variables::create(['pathSuffix' => '/', 'index' => ''])),
157  ];
158  }
159 
160  public function ‪compileEnhancerConfiguration(‪TestSet $testSet): array
161  {
162  $enhancerConfiguration = [];
164  foreach ($testSet->‪getApplicables(EnhancerDeclaration::class) as $enhancerDeclaration) {
165  $enhancerConfiguration = array_replace_recursive(
166  $enhancerConfiguration,
167  (new ‪VariableCompiler($enhancerDeclaration->getConfiguration(), $testSet->‪getVariables()))
168  ->compile()
169  ->getResults()
170  );
171  }
173  foreach ($testSet->‪getApplicables(AspectDeclaration::class) as $aspectDeclaration) {
174  $enhancerConfiguration['aspects'] = array_replace_recursive(
175  $enhancerConfiguration['aspects'] ?? [],
176  (new ‪VariableCompiler($aspectDeclaration->getConfiguration(), $testSet->‪getVariables()))
177  ->compile()
178  ->getResults()
179  );
180  }
181  return $enhancerConfiguration;
182  }
183 
184  public function ‪compilePageTypeConfiguration(‪TestSet $testSet): array
185  {
186  $pageTypeConfiguration = [];
187  foreach ($testSet->‪getApplicables(PageTypeDeclaration::class) as $pageTypeDeclaration) {
188  $pageTypeConfiguration = array_replace_recursive(
189  $pageTypeConfiguration,
190  (new ‪VariableCompiler($pageTypeDeclaration->getConfiguration(), $testSet->‪getVariables()))
191  ->compile()
192  ->getResults()
193  );
194  }
195  return $pageTypeConfiguration;
196  }
197 
198  public function ‪compileGenerateParameters(‪TestSet $testSet): string
199  {
200  $generateParameters = [];
202  foreach ($testSet->‪getApplicables(HasGenerateParameters::class) as $applicable) {
203  $generateParameters[] = $applicable->getGenerateParameters();
204  }
205  $generateParameters = (new ‪VariableCompiler($generateParameters, $testSet->‪getVariables()))
206  ->compile()
207  ->getResults();
208  return implode('', array_merge([], ...$generateParameters));
209  }
210 
211  public function ‪compileUrl(‪TestSet $testSet): string
212  {
213  return $testSet->‪getUrl()->‪apply($testSet->‪getVariables());
214  }
215 
216  public function ‪compileResolveArguments(‪TestSet $testSet): array
217  {
218  $resolveArguments = [];
220  foreach ($testSet->‪getApplicables(HasResolveArguments::class) as $applicable) {
221  $resolveArguments = array_replace_recursive(
222  $resolveArguments,
223  (new ‪VariableCompiler($applicable->getResolveArguments(), $testSet->‪getVariables()))
224  ->compile()
225  ->getResults()
226  );
227  }
228  $resolveArguments['staticArguments'] = $resolveArguments['staticArguments'] ?? [];
229  $resolveArguments['dynamicArguments'] = $resolveArguments['dynamicArguments'] ?? [];
230  $resolveArguments['queryArguments'] = $resolveArguments['queryArguments'] ?? [];
231  // generate ("assume") `routeArguments` from expected static and dynamic arguments if not declared
232  $resolveArguments['routeArguments'] = $resolveArguments['routeArguments'] ?? array_replace_recursive(
233  $resolveArguments['staticArguments'],
234  $resolveArguments['dynamicArguments']
235  );
236  if (preg_match('#\?cHash=([a-z0-9]+)#i', $this->‪compileUrl($testSet), $matches)) {
237  $resolveArguments['dynamicArguments']['cHash'] = $matches[1];
238  $resolveArguments['queryArguments']['cHash'] = $matches[1];
239  }
240 
241  return $resolveArguments;
242  }
243 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\create
‪static create(string $key, $value)
Definition: VariableItem.php:33
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\declarePageTypes
‪PageTypeDeclaration[] declarePageTypes()
Definition: Builder.php:107
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\compilePageTypeConfiguration
‪compilePageTypeConfiguration(TestSet $testSet)
Definition: Builder.php:184
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet
Definition: TestSet.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\compileUrl
‪compileUrl(TestSet $testSet)
Definition: Builder.php:211
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder
Definition: Builder.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\create
‪static create()
Definition: Builder.php:20
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableValue\create
‪static create(string $value, Variables $defaultVariables=null)
Definition: VariableValue.php:37
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variables\create
‪static create(array $items=[])
Definition: Variables.php:20
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\create
‪static create(string $identifier)
Definition: EnhancerDeclaration.php:36
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getVariables
‪Variables getVariables()
Definition: TestSet.php:87
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getApplicables
‪Applicable[] getApplicables(string $type=null)
Definition: TestSet.php:64
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\compileResolveArguments
‪compileResolveArguments(TestSet $testSet)
Definition: Builder.php:216
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableCompiler
Definition: VariableCompiler.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\PageTypeDeclaration
Definition: PageTypeDeclaration.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getUrl
‪VariableValue getUrl()
Definition: TestSet.php:47
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableValue\apply
‪apply(Variables $variables)
Definition: VariableValue.php:60
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder
Definition: Applicable.php:3
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\compileGenerateParameters
‪compileGenerateParameters(TestSet $testSet)
Definition: Builder.php:198
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\compileEnhancerConfiguration
‪compileEnhancerConfiguration(TestSet $testSet)
Definition: Builder.php:160
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\declareEnhancers
‪EnhancerDeclaration[] declareEnhancers()
Definition: Builder.php:28
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration
Definition: EnhancerDeclaration.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\PageTypeDeclaration\create
‪static create(string $identifier)
Definition: PageTypeDeclaration.php:40
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variable\create
‪static create(string $variableName, int $cast=self::CAST_NONE)
Definition: Variable.php:33
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variable\CAST_STRING
‪const CAST_STRING
Definition: Variable.php:21