‪TYPO3CMS  10.4
EnhancerLinkGeneratorTest.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 
35 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerFactory;
36 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerWriter;
37 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
38 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequestContext;
39 
44 {
46 
50  private ‪$siteTitle = 'A Company that Manufactures Everything Inc';
51 
56 
57  public static function ‪setUpBeforeClass(): void
58  {
59  parent::setUpBeforeClass();
60  static::initializeDatabaseSnapshot();
61  }
62 
63  public static function ‪tearDownAfterClass(): void
64  {
65  static::destroyDatabaseSnapshot();
66  parent::tearDownAfterClass();
67  }
68 
69  protected function ‪setUp(): void
70  {
71  parent::setUp();
72 
73  // these settings are forwarded to the frontend sub-request as well
74  $this->internalRequestContext = (new InternalRequestContext())
75  ->withGlobalSettings(['TYPO3_CONF_VARS' => static::TYPO3_CONF_VARS]);
76 
78  'acme-com',
79  $this->‪buildSiteConfiguration(1000, 'https://acme.com/'),
80  [
81  $this->‪buildDefaultLanguageConfiguration('EN', 'https://acme.us/'),
82  $this->‪buildLanguageConfiguration('FR', 'https://acme.fr/', ['EN']),
83  $this->‪buildLanguageConfiguration('FR-CA', 'https://acme.ca/', ['FR', 'EN']),
84  ]
85  );
86 
88  'archive-acme-com',
89  $this->‪buildSiteConfiguration(3000, 'https://archive.acme.com/'),
90  [
91  $this->‪buildDefaultLanguageConfiguration('EN', '/'),
92  $this->‪buildLanguageConfiguration('FR', 'https://archive.acme.com/fr/', ['EN']),
93  $this->‪buildLanguageConfiguration('FR-CA', 'https://archive.acme.com/ca/', ['FR', 'EN'])
94  ]
95  );
96 
97  $this->withDatabaseSnapshot(function () {
98  $this->‪setUpDatabase();
99  });
100  }
101 
102  protected function ‪setUpDatabase()
103  {
104  $backendUser = $this->setUpBackendUserFromFixture(1);
106 
107  $scenarioFile = __DIR__ . '/Fixtures/SlugScenario.yaml';
108  $factory = DataHandlerFactory::fromYamlFile($scenarioFile);
109  $writer = DataHandlerWriter::withBackendUser($backendUser);
110  $writer->invokeFactory($factory);
111  static::failIfArrayIsNotEmpty(
112  $writer->getErrors()
113  );
114 
115  $this->setUpFrontendRootPage(
116  1000,
117  [
118  'typo3/sysext/frontend/Tests/Functional/SiteHandling/Fixtures/LinkGenerator.typoscript',
119  ],
120  [
121  'title' => 'ACME Root',
122  'sitetitle' => $this->siteTitle,
123  ]
124  );
125  }
126 
127  protected function ‪tearDown(): void
128  {
129  unset($this->internalRequestContext);
130  parent::tearDown();
131  }
132 
137  public function ‪localeModifierDataProvider($parentSet = null): array
138  {
139  $builder = ‪Builder::create();
140  // variables (applied when invoking expectations)
141  $variables = ‪Variables::create()->define([
142  'value' => 100,
143  'routePrefix' => '{enhance_name}',
144  'aspectName' => 'enhance_name',
145  ]);
146  return ‪Permutation::create($variables)
147  ->withTargets(
148  ‪TestSet::create($parentSet)
149  ->withMergedApplicables(‪LanguageContext::create(0))
150  ->withTargetPageId(1100)
151  ->withUrl(
153  'https://acme.us/welcome/enhance/[[value]][[pathSuffix]]?cHash=',
154  ‪Variables::create(['pathSuffix' => ''])
155  )
156  ),
157  ‪TestSet::create($parentSet)
158  ->withMergedApplicables(‪LanguageContext::create(1))
159  ->withTargetPageId(1100)
160  ->withUrl(
162  'https://acme.fr/bienvenue/augmenter/[[value]][[pathSuffix]]?cHash=',
163  ‪Variables::create(['pathSuffix' => ''])
164  )
165  ),
166  ‪TestSet::create($parentSet)
167  ->withMergedApplicables(‪LanguageContext::create(0))
168  ->withTargetPageId(3000)
169  ->withUrl(
171  'https://archive.acme.com/enhance/[[value]][[pathSuffix]]?cHash=',
172  ‪Variables::create(['pathSuffix' => ''])
173  )
174  ),
175  ‪TestSet::create($parentSet)
176  ->withMergedApplicables(‪LanguageContext::create(1))
177  ->withTargetPageId(3000)
178  ->withUrl(
180  'https://archive.acme.com/fr/augmenter/[[value]][[pathSuffix]]?cHash=',
181  ‪Variables::create(['pathSuffix' => ''])
182  )
183  )
184  )
185  ->withApplicableItems($builder->declareEnhancers())
186  ->withApplicableSet(
187  ‪AspectDeclaration::create('LocaleModifier')->withConfiguration([
188  ‪VariableItem::create('aspectName', [
189  'type' => 'LocaleModifier',
190  'default' => 'enhance',
191  'localeMap' => [
192  [
193  'locale' => 'fr_FR',
194  'value' => 'augmenter'
195  ]
196  ],
197  ])
198  ])
199  )
200  ->permute()
201  ->getTargetsForDataProvider();
202  }
203 
210  public function ‪localeModifierIsApplied(TestSet $testSet): void
211  {
212  $builder = ‪Builder::create();
213  $enhancerConfiguration = $builder->compileEnhancerConfiguration($testSet);
214  $additionalParameters = $builder->compileGenerateParameters($testSet);
216  $languageContext = $testSet->getSingleApplicable(LanguageContext::class);
217  $targetLanguageId = $languageContext->getLanguageId();
218  $expectation = $builder->compileUrl($testSet);
219 
220  $this->‪mergeSiteConfiguration('acme-com', [
221  'routeEnhancers' => ['Enhancer' => $enhancerConfiguration]
222  ]);
223  $this->‪mergeSiteConfiguration('archive-acme-com', [
224  'routeEnhancers' => ['Enhancer' => $enhancerConfiguration]
225  ]);
226 
227  $response = $this->executeFrontendRequest(
228  (new InternalRequest('https://acme.us/'))
229  ->withPageId(1100)
230  ->withInstructions([
231  $this->createTypoLinkUrlInstruction([
232  'parameter' => $testSet->getTargetPageId(),
233  'language' => $targetLanguageId,
234  'additionalParams' => $additionalParameters,
235  'forceAbsoluteUrl' => 1,
236  ])
237  ]),
238  $this->internalRequestContext
239  );
240 
241  $body = (string)$response->getBody();
242  self::assertStringStartsWith($expectation, $body);
243  }
244 
249  public function ‪persistedAliasMapperDataProvider($parentSet = null): array
250  {
251  $builder = ‪Builder::create();
252  // variables (applied when invoking expectations)
253  $variables = ‪Variables::create()->define([
254  'value' => 1100,
255  'routePrefix' => 'enhance',
256  'aspectName' => 'value',
257  ]);
258  return ‪Permutation::create($variables)
259  ->withTargets(
260  ‪TestSet::create($parentSet)
261  ->withMergedApplicables(‪LanguageContext::create(0))
262  ->withTargetPageId(1100)
263  ->withUrl(
265  'https://acme.us/welcome/enhance/welcome[[pathSuffix]]',
266  ‪Variables::create(['pathSuffix' => ''])
267  )
268  ),
269  ‪TestSet::create($parentSet)
270  ->withMergedApplicables(‪LanguageContext::create(1))
271  ->withTargetPageId(1100)
272  ->withUrl(
274  'https://acme.fr/bienvenue/enhance/bienvenue[[pathSuffix]]',
275  ‪Variables::create(['pathSuffix' => ''])
276  )
277  )
278  )
279  ->withApplicableItems($builder->declareEnhancers())
280  ->withApplicableSet(
281  ‪AspectDeclaration::create('PersistedAliasMapper')->withConfiguration([
282  ‪VariableItem::create('aspectName', [
283  'type' => 'PersistedAliasMapper',
284  'tableName' => 'pages',
285  'routeFieldName' => 'slug',
286  'routeValuePrefix' => '/',
287  ])
288  ])
289  )
290  ->permute()
291  ->getTargetsForDataProvider();
292  }
293 
300  public function ‪persistedAliasMapperIsApplied(TestSet $testSet): void
301  {
302  $builder = ‪Builder::create();
303  $enhancerConfiguration = $builder->compileEnhancerConfiguration($testSet);
304  $additionalParameters = $builder->compileGenerateParameters($testSet);
306  $languageContext = $testSet->getSingleApplicable(LanguageContext::class);
307  $targetLanguageId = $languageContext->getLanguageId();
308  $expectation = $builder->compileUrl($testSet);
309 
310  $this->‪mergeSiteConfiguration('acme-com', [
311  'routeEnhancers' => ['Enhancer' => $enhancerConfiguration]
312  ]);
313 
314  $response = $this->executeFrontendRequest(
315  (new InternalRequest('https://acme.us/'))
316  ->withPageId(1100)
317  ->withInstructions([
318  $this->createTypoLinkUrlInstruction([
319  'parameter' => 1100,
320  'language' => $targetLanguageId,
321  'additionalParams' => $additionalParameters,
322  'forceAbsoluteUrl' => 1,
323  ])
324  ]),
325  $this->internalRequestContext
326  );
327 
328  self::assertSame($expectation, (string)$response->getBody());
329  }
330 
335  public function ‪persistedPatternMapperDataProvider($parentSet = null): array
336  {
337  $builder = ‪Builder::create();
338  // variables (applied when invoking expectations)
339  $variables = ‪Variables::create()->define([
340  'value' => 1100,
341  'routePrefix' => 'enhance',
342  'aspectName' => 'value',
343  ]);
344  return ‪Permutation::create($variables)
345  ->withTargets(
346  ‪TestSet::create($parentSet)
347  ->withMergedApplicables(‪LanguageContext::create(0))
348  ->withTargetPageId(1100)
349  ->withUrl(
351  'https://acme.us/welcome/enhance/hello-and-welcome-[[value]][[pathSuffix]]',
352  ‪Variables::create(['pathSuffix' => ''])
353  )
354  ),
355  ‪TestSet::create($parentSet)
356  ->withMergedApplicables(‪LanguageContext::create(1))
357  ->withTargetPageId(1100)
358  ->withUrl(
360  'https://acme.fr/bienvenue/enhance/salut-et-bienvenue-[[value]][[pathSuffix]]',
361  ‪Variables::create(['pathSuffix' => ''])
362  )
363  ),
364  ‪TestSet::create($parentSet)
365  ->withMergedApplicables(‪LanguageContext::create(0))
366  ->withTargetPageId(3000)
367  ->withUrl(
369  'https://archive.acme.com/enhance/hello-and-welcome-[[value]][[pathSuffix]]',
370  ‪Variables::create(['pathSuffix' => ''])
371  )
372  ),
373  ‪TestSet::create($parentSet)
374  ->withMergedApplicables(‪LanguageContext::create(1))
375  ->withTargetPageId(3000)
376  ->withUrl(
378  'https://archive.acme.com/fr/enhance/salut-et-bienvenue-[[value]][[pathSuffix]]',
379  ‪Variables::create(['pathSuffix' => ''])
380  )
381  )
382  )
383  ->withApplicableItems($builder->declareEnhancers())
384  ->withApplicableSet(
385  ‪AspectDeclaration::create('PersistedPatternMapper')->withConfiguration([
386  ‪VariableItem::create('aspectName', [
387  'type' => 'PersistedPatternMapper',
388  'tableName' => 'pages',
389  'routeFieldPattern' => '^(?P<subtitle>.+)-(?P<uid>\d+)$',
390  'routeFieldResult' => '{subtitle}-{uid}',
391  ])
392  ])
393  )
394  ->permute()
395  ->getTargetsForDataProvider();
396  }
397 
404  public function ‪persistedPatternMapperIsApplied(TestSet $testSet): void
405  {
406  $builder = ‪Builder::create();
407  $enhancerConfiguration = $builder->compileEnhancerConfiguration($testSet);
408  $additionalParameters = $builder->compileGenerateParameters($testSet);
410  $languageContext = $testSet->getSingleApplicable(LanguageContext::class);
411  $targetLanguageId = $languageContext->getLanguageId();
412  $expectation = $builder->compileUrl($testSet);
413 
414  $this->‪mergeSiteConfiguration('acme-com', [
415  'routeEnhancers' => ['Enhancer' => $enhancerConfiguration]
416  ]);
417  $this->‪mergeSiteConfiguration('archive-acme-com', [
418  'routeEnhancers' => ['Enhancer' => $enhancerConfiguration]
419  ]);
420 
421  $response = $this->executeFrontendRequest(
422  (new InternalRequest('https://acme.us/'))
423  ->withPageId(1100)
424  ->withInstructions([
425  $this->createTypoLinkUrlInstruction([
426  'parameter' => $testSet->getTargetPageId(),
427  'language' => $targetLanguageId,
428  'additionalParams' => $additionalParameters,
429  'forceAbsoluteUrl' => 1,
430  ])
431  ]),
432  $this->internalRequestContext
433  );
434 
435  self::assertSame($expectation, (string)$response->getBody());
436  }
437 
442  public function ‪staticValueMapperDataProvider($parentSet = null): array
443  {
444  $builder = ‪Builder::create();
445  // variables (applied when invoking expectations)
446  $variables = ‪Variables::create()->define([
447  'value' => 100,
448  'routePrefix' => 'enhance',
449  'aspectName' => 'value',
450  ]);
451  return ‪Permutation::create($variables)
452  ->withTargets(
453  ‪TestSet::create($parentSet)
454  ->withMergedApplicables(‪LanguageContext::create(0))
455  ->withTargetPageId(1100)
456  ->withUrl(
458  'https://acme.us/welcome/enhance/hundred[[pathSuffix]]',
459  ‪Variables::create(['pathSuffix' => ''])
460  )
461  ),
462  ‪TestSet::create($parentSet)
463  ->withMergedApplicables(‪LanguageContext::create(1))
464  ->withTargetPageId(1100)
465  ->withUrl(
467  'https://acme.fr/bienvenue/enhance/cent[[pathSuffix]]',
468  ‪Variables::create(['pathSuffix' => ''])
469  )
470  ),
471  ‪TestSet::create($parentSet)
472  ->withMergedApplicables(‪LanguageContext::create(0))
473  ->withTargetPageId(3000)
474  ->withUrl(
476  'https://archive.acme.com/enhance/hundred[[pathSuffix]]',
477  ‪Variables::create(['pathSuffix' => ''])
478  )
479  ),
480  ‪TestSet::create($parentSet)
481  ->withMergedApplicables(‪LanguageContext::create(1))
482  ->withTargetPageId(3000)
483  ->withUrl(
485  'https://archive.acme.com/fr/enhance/cent[[pathSuffix]]',
486  ‪Variables::create(['pathSuffix' => ''])
487  )
488  )
489  )
490  ->withApplicableItems($builder->declareEnhancers())
491  ->withApplicableSet(
492  ‪AspectDeclaration::create('StaticValueMapper')->withConfiguration([
493  ‪VariableItem::create('aspectName', [
494  'type' => 'StaticValueMapper',
495  'map' => [
496  'hundred' => 100,
497  ],
498  'localeMap' => [
499  [
500  'locale' => 'fr_FR',
501  'map' => [
502  'cent' => 100,
503  ],
504  ]
505  ],
506  ])
507  ])
508  )
509  ->permute()
510  ->getTargetsForDataProvider();
511  }
512 
519  public function ‪staticValueMapperIsApplied(TestSet $testSet): void
520  {
521  $builder = ‪Builder::create();
522  $enhancerConfiguration = $builder->compileEnhancerConfiguration($testSet);
523  $additionalParameters = $builder->compileGenerateParameters($testSet);
525  $languageContext = $testSet->getSingleApplicable(LanguageContext::class);
526  $targetLanguageId = $languageContext->getLanguageId();
527  $expectation = $builder->compileUrl($testSet);
528 
529  $this->‪mergeSiteConfiguration('acme-com', [
530  'routeEnhancers' => ['Enhancer' => $enhancerConfiguration]
531  ]);
532  $this->‪mergeSiteConfiguration('archive-acme-com', [
533  'routeEnhancers' => ['Enhancer' => $enhancerConfiguration]
534  ]);
535 
536  $response = $this->executeFrontendRequest(
537  (new InternalRequest('https://acme.us/'))
538  ->withPageId(1100)
539  ->withInstructions([
540  $this->createTypoLinkUrlInstruction([
541  'parameter' => $testSet->getTargetPageId(),
542  'language' => $targetLanguageId,
543  'additionalParams' => $additionalParameters,
544  'forceAbsoluteUrl' => 1,
545  ])
546  ]),
547  $this->internalRequestContext
548  );
549 
550  self::assertStringStartsWith($expectation, (string)$response->getBody());
551  }
552 
557  public function ‪staticRangeMapperDataProvider($parentSet = null): array
558  {
559  $variableContexts = array_map(
560  function ($value) {
562  ‪Variables::create(['value' => $value])
563  );
564  },
565  range(10, 100, 30)
566  );
567 
568  $builder = ‪Builder::create();
569  // variables (applied when invoking expectations)
570  $variables = ‪Variables::create()->define([
571  'value' => null, // defined via VariableContext
572  'routePrefix' => 'enhance',
573  'aspectName' => 'value',
574  ]);
575  return ‪Permutation::create($variables)
576  ->withTargets(
577  ‪TestSet::create($parentSet)
578  ->withMergedApplicables(‪LanguageContext::create(0))
579  ->withTargetPageId(1100)
580  ->withUrl(
582  'https://acme.us/welcome/enhance/[[value]][[pathSuffix]]',
583  ‪Variables::create(['pathSuffix' => ''])
584  )
585  ),
586  ‪TestSet::create($parentSet)
587  ->withMergedApplicables(‪LanguageContext::create(1))
588  ->withTargetPageId(1100)
589  ->withUrl(
591  'https://acme.fr/bienvenue/enhance/[[value]][[pathSuffix]]',
592  ‪Variables::create(['pathSuffix' => ''])
593  )
594  )
595  )
596  ->withApplicableItems($variableContexts)
597  ->withApplicableItems($builder->declareEnhancers())
598  ->withApplicableSet(
599  ‪AspectDeclaration::create('StaticRangeMapper')->withConfiguration([
600  ‪VariableItem::create('aspectName', [
601  'type' => 'StaticRangeMapper',
602  'start' => '1',
603  'end' => '100',
604  ])
605  ])
606  )
607  ->permute()
608  ->getTargetsForDataProvider();
609  }
610 
617  public function ‪staticRangeMapperIsApplied(TestSet $testSet): void
618  {
619  $builder = ‪Builder::create();
620  $enhancerConfiguration = $builder->compileEnhancerConfiguration($testSet);
621  $additionalParameters = $builder->compileGenerateParameters($testSet);
623  $languageContext = $testSet->getSingleApplicable(LanguageContext::class);
624  $targetLanguageId = $languageContext->getLanguageId();
625  $expectation = $builder->compileUrl($testSet);
626 
627  $this->‪mergeSiteConfiguration('acme-com', [
628  'routeEnhancers' => ['Enhancer' => $enhancerConfiguration]
629  ]);
630 
631  $response = $this->executeFrontendRequest(
632  (new InternalRequest('https://acme.us/'))
633  ->withPageId(1100)
634  ->withInstructions([
635  $this->createTypoLinkUrlInstruction([
636  'parameter' => $testSet->getTargetPageId(),
637  'language' => $targetLanguageId,
638  'additionalParams' => $additionalParameters,
639  'forceAbsoluteUrl' => 1,
640  ])
641  ]),
642  $this->internalRequestContext
643  );
644 
645  self::assertStringStartsWith($expectation, (string)$response->getBody());
646  }
647 
654  public function ‪pageTypeDecoratorIsAppliedDataProvider(): array
655  {
656  $testSets = [];
657  foreach (‪Builder::create()->declarePageTypes() as $pageTypeDeclaration) {
658  $testSet = ‪TestSet::create()
659  ->withMergedApplicables($pageTypeDeclaration)
660  ->withVariables($pageTypeDeclaration->getVariables());
661  $testSets = array_merge(
662  $testSets,
663  $this->‪localeModifierDataProvider($testSet),
664  $this->‪persistedAliasMapperDataProvider($testSet),
665  $this->‪persistedPatternMapperDataProvider($testSet),
666  $this->‪staticValueMapperDataProvider($testSet),
667  $this->‪staticRangeMapperDataProvider($testSet)
668  );
669  }
670  return $testSets;
671  }
672 
679  public function ‪pageTypeDecoratorIsApplied(TestSet $testSet): void
680  {
681  $builder = ‪Builder::create();
682  $enhancerConfiguration = $builder->compileEnhancerConfiguration($testSet);
683  $pageTypeConfiguration = $builder->compilePageTypeConfiguration($testSet);
684  $additionalParameters = $builder->compileGenerateParameters($testSet);
686  $languageContext = $testSet->getSingleApplicable(LanguageContext::class);
687  $targetLanguageId = $languageContext->getLanguageId();
688  $expectation = $builder->compileUrl($testSet);
689 
690  $this->‪mergeSiteConfiguration('acme-com', [
691  'routeEnhancers' => [
692  'Enhancer' => $enhancerConfiguration,
693  'PageType' => $pageTypeConfiguration,
694  ]
695  ]);
696 
697  $this->‪mergeSiteConfiguration('archive-acme-com', [
698  'routeEnhancers' => [
699  'Enhancer' => $enhancerConfiguration,
700  'PageType' => $pageTypeConfiguration,
701  ]
702  ]);
703 
704  $response = $this->executeFrontendRequest(
705  (new InternalRequest('https://acme.us/'))
706  ->withPageId(1100)
707  ->withInstructions([
708  $this->createTypoLinkUrlInstruction([
709  'parameter' => $testSet->getTargetPageId(),
710  'language' => $targetLanguageId,
711  'additionalParams' => $additionalParameters,
712  'forceAbsoluteUrl' => 1,
713  ])
714  ]),
715  $this->internalRequestContext
716  );
717 
718  self::assertStringStartsWith($expectation, (string)$response->getBody());
719  }
720 
721  public function ‪routeDefaultsForSingleParameterAreConsideredDataProvider($parentSet = null): array
722  {
723  $builder = ‪Builder::create();
724  $enhancerDeclarations = $builder->declareEnhancers();
725  // variables (applied when invoking expectations)
726  $variables = ‪Variables::create()->define([
727  'routePrefix' => 'enhance',
728  'aspectName' => 'value',
729  ]);
730  return ‪Permutation::create($variables)
731  ->withTargets(
732  ‪TestSet::create($parentSet)
733  ->withMergedApplicables(‪LanguageContext::create(0))
734  ->withTargetPageId(1100)
735  ->withUrl(
737  'https://acme.us/welcome/enhance[[uriValue]][[pathSuffix]]',
738  ‪Variables::create(['pathSuffix' => '', 'uriValue' => '/hundred'])
739  )
740  ),
741  ‪TestSet::create($parentSet)
742  ->withMergedApplicables(‪LanguageContext::create(1))
743  ->withTargetPageId(1100)
744  ->withUrl(
746  'https://acme.fr/bienvenue/enhance[[uriValue]][[pathSuffix]]',
747  ‪Variables::create(['pathSuffix' => '', 'uriValue' => '/cent'])
748  )
749  )
750  )
751  ->withApplicableSet(
752  $enhancerDeclarations['Simple'],
753  // cannot use Plugin enhancer here - won't be used if no parameters for plugin namespace are given
754  // $enhancerDeclarations['Plugin']
755  // ->withConfiguration(['routePath' => $routePath], true),
756  $enhancerDeclarations['Extbase']
757  )
758  ->withApplicableSet(
759  ‪EnhancerDeclaration::create('defaults.value=100')->withConfiguration([
760  'defaults' => ['value' => 100],
761  ])
762  )
763  ->withApplicableSet(
764  ‪AspectDeclaration::create('StaticValueMapper')->withConfiguration([
765  ‪VariableItem::create('aspectName', [
766  'type' => 'StaticValueMapper',
767  'map' => [
768  'hundred' => 100,
769  ],
770  'localeMap' => [
771  [
772  'locale' => 'fr_FR',
773  'map' => [
774  'cent' => 100,
775  ],
776  ]
777  ],
778  ])
779  ])
780  )
781  ->withApplicableSet(
783  'routeParameter' => '{value}',
784  'uriValue' => '',
785  ])),
787  'routeParameter' => '{!value}',
788  ]))
789  )
790  ->withApplicableSet(
792  'value' => null,
793  ])),
795  'value' => 100,
796  ]))
797  )
798  ->permute()
799  ->getTargetsForDataProvider();
800  }
801 
808  public function ‪routeDefaultsForSingleParameterAreConsidered(TestSet $testSet): void
809  {
810  $this->‪assertGeneratedUriEquals($testSet);
811  }
812 
813  public function ‪routeDefaultsForMultipleParametersAreConsideredDataProvider($parentSet = null): array
814  {
815  $builder = ‪Builder::create();
816  $routePath = ‪VariableValue::create('/[[routePrefix]]/[[routeParameter]]/{additional}');
817  $enhancerDeclarations = $builder->declareEnhancers();
818  // variables (applied when invoking expectations)
819  $variables = ‪Variables::create()->define([
820  'routePrefix' => 'enhance',
821  'aspectName' => 'value',
822  ]);
823  return ‪Permutation::create($variables)
824  ->withTargets(
825  ‪TestSet::create($parentSet)
826  ->withMergedApplicables(‪LanguageContext::create(0))
827  ->withTargetPageId(1100)
828  ->withUrl(
830  'https://acme.us/welcome/enhance/hundred/20[[pathSuffix]]',
831  ‪Variables::create(['pathSuffix' => ''])
832  )
833  ),
834  ‪TestSet::create($parentSet)
835  ->withMergedApplicables(‪LanguageContext::create(1))
836  ->withTargetPageId(1100)
837  ->withUrl(
839  'https://acme.fr/bienvenue/enhance/cent/20[[pathSuffix]]',
840  ‪Variables::create(['pathSuffix' => ''])
841  )
842  )
843  )
844  ->withApplicableSet(
845  $enhancerDeclarations['Simple']
846  ->withConfiguration(['routePath' => $routePath], true)
847  ->withGenerateParameters(['&additional=20'], true),
848  $enhancerDeclarations['Plugin']
849  ->withConfiguration(['routePath' => $routePath], true)
850  ->withGenerateParameters(['&testing[additional]=20'], true),
851  $enhancerDeclarations['Extbase']
852  ->withConfiguration(['routes' => [0 => ['routePath' => $routePath]]], true)
853  ->withGenerateParameters(['&tx_testing_link[additional]=20'], true)
854  )
855  ->withApplicableSet(
856  ‪EnhancerDeclaration::create('defaults.value=100')->withConfiguration([
857  'defaults' => ['value' => 100],
858  ])
859  )
860  ->withApplicableSet(
861  ‪AspectDeclaration::create('StaticValueMapper')->withConfiguration([
862  ‪VariableItem::create('aspectName', [
863  'type' => 'StaticValueMapper',
864  'map' => [
865  'hundred' => 100,
866  ],
867  'localeMap' => [
868  [
869  'locale' => 'fr_FR',
870  'map' => [
871  'cent' => 100,
872  ],
873  ]
874  ],
875  ])
876  ])
877  )
878  ->withApplicableSet(
880  'routeParameter' => '{value}',
881  ])),
883  'routeParameter' => '{!value}',
884  ]))
885  )
886  ->withApplicableSet(
888  'value' => null,
889  ])),
891  'value' => 100,
892  ]))
893  )
894  ->permute()
895  ->getTargetsForDataProvider();
896  }
897 
904  public function ‪routeDefaultsForMultipleParametersAreConsidered(TestSet $testSet): void
905  {
906  $this->‪assertGeneratedUriEquals($testSet);
907  }
908 
909  public function ‪routeRequirementsHavingAspectsAreConsideredDataProvider($parentSet = null): array
910  {
911  $builder = ‪Builder::create();
912  // variables (applied when invoking expectations)
913  $variables = ‪Variables::create()->define([
914  'routePrefix' => 'enhance',
915  'aspectName' => 'value',
916  'inArguments' => 'staticArguments' // either 'dynamicArguments' or 'staticArguments'
917  ]);
918  return ‪Permutation::create($variables)
919  ->withTargets(
920  ‪TestSet::create($parentSet)
921  ->withMergedApplicables(‪LanguageContext::create(0))
922  ->withTargetPageId(1100)
923  ->withUrl(
925  'https://acme.us/welcome/enhance/[[resolveValue]][[pathSuffix]]',
926  ‪Variables::create(['pathSuffix' => ''])
927  )
928  )
929  )
930  ->withApplicableSet(
932  'value' => 100,
933  'resolveValue' => 'hundred',
934  ])),
936  'value' => 1100100,
937  'resolveValue' => 'hundred/binary',
938  ])),
941  'value' => 100,
942  'resolveValue' => 'hundred',
943  ])),
944  ‪EnhancerDeclaration::create('requirements.value=/[a-z_/]+/')->withConfiguration([
945  'requirements' => [
946  'value' => '[a-z_/]+',
947  ]
948  ])
949  ),
952  'value' => 1100100,
953  'resolveValue' => 'hundred/binary',
954  ])),
955  ‪EnhancerDeclaration::create('requirements.value=/[a-z_/]+/')->withConfiguration([
956  'requirements' => [
957  'value' => '[a-z_/]+',
958  ]
959  ])
960  )
961  )
962  ->withApplicableItems($builder->declareEnhancers())
963  ->withApplicableSet(
964  ‪AspectDeclaration::create('StaticValueMapper')->withConfiguration([
965  ‪VariableItem::create('aspectName', [
966  'type' => 'StaticValueMapper',
967  'map' => [
968  'hundred' => 100,
969  'hundred/binary' => 1100100,
970  ],
971  ])
972  ])
973  )
974  ->permute()
975  ->getTargetsForDataProvider();
976  }
977 
984  public function ‪routeRequirementsHavingAspectsAreConsidered(TestSet $testSet): void
985  {
986  $this->‪assertGeneratedUriEquals($testSet);
987  }
988 
989  private function ‪assertGeneratedUriEquals(‪TestSet $testSet): void
990  {
991  $builder = ‪Builder::create();
992  $enhancerConfiguration = $builder->compileEnhancerConfiguration($testSet);
993  $additionalParameters = $builder->compileGenerateParameters($testSet);
995  $languageContext = $testSet->‪getSingleApplicable(LanguageContext::class);
996  $targetLanguageId = $languageContext->getLanguageId();
997  $expectation = $builder->compileUrl($testSet);
998 
999  $this->‪mergeSiteConfiguration('acme-com', [
1000  'routeEnhancers' => ['Enhancer' => $enhancerConfiguration]
1001  ]);
1002 
1003  $response = $this->executeFrontendRequest(
1004  (new InternalRequest('https://acme.us/'))
1005  ->withPageId(1100)
1006  ->withInstructions([
1007  $this->createTypoLinkUrlInstruction([
1008  'parameter' => $testSet->‪getTargetPageId(),
1009  'language' => $targetLanguageId,
1010  'additionalParams' => $additionalParameters,
1011  'forceAbsoluteUrl' => 1,
1012  ])
1013  ]),
1014  $this->internalRequestContext
1015  );
1016 
1017  self::assertStringStartsWith($expectation, (string)$response->getBody());
1018  }
1019 
1024  {
1025  return [
1026  '*::*' => [
1027  '&tx_testing_link[value]=1',
1028  'https://acme.us/welcome/link/index/one'
1029  ],
1030  '*::list' => [
1031  '&tx_testing_link[action]=list&tx_testing_link[value]=1',
1032  'https://acme.us/welcome/link/list/one'
1033  ],
1034  'Link::*' => [
1035  // correctly falling back to defaultController here
1036  '&tx_testing_link[controller]=Link&tx_testing_link[value]=1',
1037  'https://acme.us/welcome/link/index/one'
1038  ],
1039  'Page::*' => [
1040  // correctly falling back to defaultController here
1041  '&tx_testing_link[controller]=Page&tx_testing_link[value]=1',
1042  'https://acme.us/welcome/link/index/one'
1043  ],
1044  'Page::show' => [
1045  '&tx_testing_link[controller]=Page&tx_testing_link[action]=show&tx_testing_link[value]=1',
1046  'https://acme.us/welcome/page/show/one'
1047  ],
1048  ];
1049  }
1050 
1060  public function ‪defaultExtbaseControllerActionNamesAreApplied(string $additionalParameters, string $expectation)
1061  {
1062  $targetLanguageId = 0;
1063  $this->‪mergeSiteConfiguration('acme-com', [
1064  'routeEnhancers' => [
1065  'Enhancer' => [
1066  'type' => 'Extbase',
1067  'routes' => [
1068  ['routePath' => '/link/index/{value}', '_controller' => 'Link::index'],
1069  ['routePath' => '/link/list/{value}', '_controller' => 'Link::list'],
1070  ['routePath' => '/page/show/{value}', '_controller' => 'Page::show'],
1071  ],
1072  'defaultController' => 'Link::index',
1073  'extension' => 'testing',
1074  'plugin' => 'link',
1075  'aspects' => [
1076  'value' => [
1077  'type' => 'StaticValueMapper',
1078  'map' => [
1079  'one' => 1,
1080  ],
1081  ],
1082  ],
1083  ]
1084  ]
1085  ]);
1086 
1087  $response = $this->executeFrontendRequest(
1088  (new InternalRequest('https://acme.us/'))
1089  ->withPageId(1100)
1090  ->withInstructions([
1091  $this->createTypoLinkUrlInstruction([
1092  'parameter' => 1100,
1093  'language' => $targetLanguageId,
1094  'additionalParams' => $additionalParameters,
1095  'forceAbsoluteUrl' => 1,
1096  ])
1097  ]),
1098  $this->internalRequestContext
1099  );
1100 
1101  self::assertSame($expectation, (string)$response->getBody());
1102  }
1103 
1108  {
1109  return [
1110  '*::*' => [
1111  '&tx_testing_link[value]=1&tx_testing_link[excludedValue]=random',
1112  'https://acme.us/welcome/link/index/one?tx_testing_link%5BexcludedValue%5D=random'
1113  ],
1114  '*::list' => [
1115  '&tx_testing_link[action]=list&tx_testing_link[value]=1&tx_testing_link[excludedValue]=random',
1116  'https://acme.us/welcome/link/list/one?tx_testing_link%5BexcludedValue%5D=random'
1117  ],
1118  'Link::*' => [
1119  // correctly falling back to defaultController here
1120  '&tx_testing_link[controller]=Link&tx_testing_link[value]=1&tx_testing_link[excludedValue]=random',
1121  'https://acme.us/welcome/link/index/one?tx_testing_link%5BexcludedValue%5D=random'
1122  ],
1123  'Page::*' => [
1124  // correctly falling back to defaultController here
1125  '&tx_testing_link[controller]=Page&tx_testing_link[value]=1&tx_testing_link[excludedValue]=random',
1126  'https://acme.us/welcome/link/index/one?tx_testing_link%5BexcludedValue%5D=random'
1127  ],
1128  'Page::show' => [
1129  '&tx_testing_link[controller]=Page&tx_testing_link[action]=show&tx_testing_link[value]=1&tx_testing_link[excludedValue]=random',
1130  'https://acme.us/welcome/page/show/one?tx_testing_link%5BexcludedValue%5D=random'
1131  ],
1132  ];
1133  }
1134 
1145  public function ‪defaultExtbaseControllerActionNamesAreAppliedWithAdditionalNonMappedQueryArguments(string $additionalParameters, string $expectation)
1146  {
1147  $targetLanguageId = 0;
1148  $this->‪mergeSiteConfiguration('acme-com', [
1149  'routeEnhancers' => [
1150  'Enhancer' => [
1151  'type' => 'Extbase',
1152  'routes' => [
1153  ['routePath' => '/link/index/{value}', '_controller' => 'Link::index'],
1154  ['routePath' => '/link/list/{value}', '_controller' => 'Link::list'],
1155  ['routePath' => '/page/show/{value}', '_controller' => 'Page::show'],
1156  ],
1157  'defaultController' => 'Link::index',
1158  'extension' => 'testing',
1159  'plugin' => 'link',
1160  'aspects' => [
1161  'value' => [
1162  'type' => 'StaticValueMapper',
1163  'map' => [
1164  'one' => 1,
1165  ],
1166  ],
1167  ],
1168  ]
1169  ]
1170  ]);
1171 
1172  $response = $this->executeFrontendRequest(
1173  (new InternalRequest('https://acme.us/'))
1174  ->withPageId(1100)
1175  ->withInstructions([
1176  $this->createTypoLinkUrlInstruction([
1177  'parameter' => 1100,
1178  'language' => $targetLanguageId,
1179  'additionalParams' => $additionalParameters,
1180  'forceAbsoluteUrl' => 1,
1181  ])
1182  ]),
1183  $this->internalRequestContext
1184  );
1185 
1186  self::assertSame($expectation, (string)$response->getBody());
1187  }
1188 
1193  {
1194  $this->‪mergeSiteConfiguration('archive-acme-com', [
1195  'routeEnhancers' => [
1196  'PageType' => [
1197  'type' => 'PageType',
1198  'default' => '/',
1199  'index' => '',
1200  'map' => [
1201  '/' => 0,
1202  'sitemap.xml' => '1533906435'
1203  ]
1204  ]
1205  ]
1206  ]);
1207 
1208  GeneralUtility::makeInstance(SiteConfiguration::class)->resolveAllExistingSites(false);
1209  $site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByIdentifier('archive-acme-com');
1210  $uri = $site->getRouter()->generateUri(3000);
1211  self::assertEquals('https://archive.acme.com/', (string)$uri);
1212  $uri = $site->getRouter()->generateUri(3000, ['type' => '1533906435']);
1213  self::assertEquals('https://archive.acme.com/sitemap.xml', (string)$uri);
1214  $uri = $site->getRouter()->generateUri(3000, ['type' => '13']);
1215  self::assertEquals('https://archive.acme.com/?type=13', (string)$uri);
1216  }
1217 
1223  public function ‪nestedRouteArgumentsAreConsidered(TestSet $testSet): void
1224  {
1225  $this->‪assertGeneratedUriEquals($testSet);
1226  }
1227 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Permutation
Definition: Permutation.php:23
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem\create
‪static create(string $key, $value)
Definition: VariableItem.php:35
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildLanguageConfiguration
‪array buildLanguageConfiguration(string $identifier, string $base, array $fallbackIdentifiers=[], string $fallbackType=null)
Definition: SiteBasedTestTrait.php:142
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\TestSetDataProviderTrait
Definition: TestSetDataProviderTrait.php:33
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:58
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\AspectDeclaration\create
‪static create(string $identifier)
Definition: AspectDeclaration.php:30
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\ApplicableConjunction\create
‪static create(Applicable ... $applicables)
Definition: ApplicableConjunction.php:26
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variables
Definition: Variables.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\create
‪static create(Variables $variables)
Definition: VariablesContext.php:28
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext
Definition: VariablesContext.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Permutation\create
‪static create(Variables $variables)
Definition: Permutation.php:40
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet
Definition: TestSet.php:21
‪TYPO3\CMS\Core\Configuration\SiteConfiguration
Definition: SiteConfiguration.php:41
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder
Definition: Builder.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Builder\create
‪static create()
Definition: Builder.php:22
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪array buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:124
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableValue\create
‪static create(string $value, Variables $defaultVariables=null)
Definition: VariableValue.php:39
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:617
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variables\create
‪static create(array $items=[])
Definition: Variables.php:22
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration\create
‪static create(string $identifier)
Definition: EnhancerDeclaration.php:38
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getTargetPageId
‪int null getTargetPageId()
Definition: TestSet.php:57
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\AspectDeclaration
Definition: AspectDeclaration.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getSingleApplicable
‪getSingleApplicable(string $type)
Definition: TestSet.php:74
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling
Definition: AbstractTestCase.php:18
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:66
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableItem
Definition: VariableItem.php:21
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪array buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:109
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\LanguageContext
Definition: LanguageContext.php:21
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\ApplicableConjunction
Definition: ApplicableConjunction.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableValue
Definition: VariableValue.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\EnhancerDeclaration
Definition: EnhancerDeclaration.php:21
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\mergeSiteConfiguration
‪mergeSiteConfiguration(string $identifier, array $overrides)
Definition: SiteBasedTestTrait.php:88
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\create
‪static create($parentSet=null)
Definition: TestSet.php:38
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\LanguageContext\create
‪static create(int $languageId)
Definition: LanguageContext.php:24