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