‪TYPO3CMS  ‪main
DefaultExtbaseControllerTest.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 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
22 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
23 
25 {
27  {
28  return [
29  '*::*' => [
30  '&tx_testing_link[value]=1&tx_testing_link[excludedValue]=random',
31  'https://acme.us/welcome/link/index/one?tx_testing_link%5BexcludedValue%5D=random',
32  ],
33  '*::list' => [
34  '&tx_testing_link[action]=list&tx_testing_link[value]=1&tx_testing_link[excludedValue]=random',
35  'https://acme.us/welcome/link/list/one?tx_testing_link%5BexcludedValue%5D=random',
36  ],
37  'Link::*' => [
38  // correctly falling back to defaultController here
39  '&tx_testing_link[controller]=Link&tx_testing_link[value]=1&tx_testing_link[excludedValue]=random',
40  'https://acme.us/welcome/link/index/one?tx_testing_link%5BexcludedValue%5D=random',
41  ],
42  'Page::*' => [
43  // correctly falling back to defaultController here
44  '&tx_testing_link[controller]=Page&tx_testing_link[value]=1&tx_testing_link[excludedValue]=random',
45  'https://acme.us/welcome/link/index/one?tx_testing_link%5BexcludedValue%5D=random',
46  ],
47  'Page::show' => [
48  '&tx_testing_link[controller]=Page&tx_testing_link[action]=show&tx_testing_link[value]=1&tx_testing_link[excludedValue]=random',
49  'https://acme.us/welcome/page/show/one?tx_testing_link%5BexcludedValue%5D=random',
50  ],
51  ];
52  }
53 
57  #[DataProvider('defaultExtbaseControllerActionNamesAreAppliedWithAdditionalNonMappedQueryArgumentsDataProvider')]
58  #[Test]
59  public function ‪defaultExtbaseControllerActionNamesAreAppliedWithAdditionalNonMappedQueryArguments(string $additionalParameters, string $expectation): void
60  {
61  $targetLanguageId = 0;
62  $this->‪mergeSiteConfiguration('acme-com', [
63  'routeEnhancers' => [
64  'Enhancer' => [
65  'type' => 'Extbase',
66  'routes' => [
67  ['routePath' => '/link/index/{value}', '_controller' => 'Link::index'],
68  ['routePath' => '/link/list/{value}', '_controller' => 'Link::list'],
69  ['routePath' => '/page/show/{value}', '_controller' => 'Page::show'],
70  ],
71  'defaultController' => 'Link::index',
72  'extension' => 'testing',
73  'plugin' => 'link',
74  'aspects' => [
75  'value' => [
76  'type' => 'StaticValueMapper',
77  'map' => [
78  'one' => 1,
79  ],
80  ],
81  ],
82  ],
83  ],
84  ]);
85 
86  $response = $this->executeFrontendSubRequest(
87  (new InternalRequest('https://acme.us/'))
88  ->withPageId(1100)
89  ->withInstructions([
90  $this->createTypoLinkUrlInstruction([
91  'parameter' => 1100,
92  'language' => $targetLanguageId,
93  'additionalParams' => $additionalParameters,
94  'forceAbsoluteUrl' => 1,
95  ]),
96  ])
97  );
98 
99  self::assertSame($expectation, (string)$response->getBody());
100  }
101 
103  {
104  return [
105  '*::*' => [
106  '&tx_testing_link[value]=1',
107  'https://acme.us/welcome/link/index/one',
108  ],
109  '*::list' => [
110  '&tx_testing_link[action]=list&tx_testing_link[value]=1',
111  'https://acme.us/welcome/link/list/one',
112  ],
113  'Link::*' => [
114  // correctly falling back to defaultController here
115  '&tx_testing_link[controller]=Link&tx_testing_link[value]=1',
116  'https://acme.us/welcome/link/index/one',
117  ],
118  'Page::*' => [
119  // correctly falling back to defaultController here
120  '&tx_testing_link[controller]=Page&tx_testing_link[value]=1',
121  'https://acme.us/welcome/link/index/one',
122  ],
123  'Page::show' => [
124  '&tx_testing_link[controller]=Page&tx_testing_link[action]=show&tx_testing_link[value]=1',
125  'https://acme.us/welcome/page/show/one',
126  ],
127  ];
128  }
129 
133  #[DataProvider('defaultExtbaseControllerActionNamesAreAppliedDataProvider')]
134  #[Test]
135  public function ‪defaultExtbaseControllerActionNamesAreApplied(string $additionalParameters, string $expectation): void
136  {
137  $targetLanguageId = 0;
138  $this->‪mergeSiteConfiguration('acme-com', [
139  'routeEnhancers' => [
140  'Enhancer' => [
141  'type' => 'Extbase',
142  'routes' => [
143  ['routePath' => '/link/index/{value}', '_controller' => 'Link::index'],
144  ['routePath' => '/link/list/{value}', '_controller' => 'Link::list'],
145  ['routePath' => '/page/show/{value}', '_controller' => 'Page::show'],
146  ],
147  'defaultController' => 'Link::index',
148  'extension' => 'testing',
149  'plugin' => 'link',
150  'aspects' => [
151  'value' => [
152  'type' => 'StaticValueMapper',
153  'map' => [
154  'one' => 1,
155  ],
156  ],
157  ],
158  ],
159  ],
160  ]);
161 
162  $response = $this->executeFrontendSubRequest(
163  (new InternalRequest('https://acme.us/'))
164  ->withPageId(1100)
165  ->withInstructions([
166  $this->createTypoLinkUrlInstruction([
167  'parameter' => 1100,
168  'language' => $targetLanguageId,
169  'additionalParams' => $additionalParameters,
170  'forceAbsoluteUrl' => 1,
171  ]),
172  ])
173  );
174 
175  self::assertSame($expectation, (string)$response->getBody());
176  }
177 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EnhancerLinkGenerator\DefaultExtbaseControllerTest
Definition: DefaultExtbaseControllerTest.php:25
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EnhancerLinkGenerator\AbstractEnhancerLinkGeneratorTestCase
Definition: AbstractEnhancerLinkGeneratorTestCase.php:30
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EnhancerLinkGenerator\DefaultExtbaseControllerTest\defaultExtbaseControllerActionNamesAreAppliedDataProvider
‪static defaultExtbaseControllerActionNamesAreAppliedDataProvider()
Definition: DefaultExtbaseControllerTest.php:102
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EnhancerLinkGenerator\DefaultExtbaseControllerTest\defaultExtbaseControllerActionNamesAreApplied
‪defaultExtbaseControllerActionNamesAreApplied(string $additionalParameters, string $expectation)
Definition: DefaultExtbaseControllerTest.php:135
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EnhancerLinkGenerator\DefaultExtbaseControllerTest\defaultExtbaseControllerActionNamesAreAppliedWithAdditionalNonMappedQueryArgumentsDataProvider
‪static defaultExtbaseControllerActionNamesAreAppliedWithAdditionalNonMappedQueryArgumentsDataProvider()
Definition: DefaultExtbaseControllerTest.php:26
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\EnhancerLinkGenerator\DefaultExtbaseControllerTest\defaultExtbaseControllerActionNamesAreAppliedWithAdditionalNonMappedQueryArguments
‪defaultExtbaseControllerActionNamesAreAppliedWithAdditionalNonMappedQueryArguments(string $additionalParameters, string $expectation)
Definition: DefaultExtbaseControllerTest.php:59
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\mergeSiteConfiguration
‪mergeSiteConfiguration(string $identifier, array $overrides)
Definition: SiteBasedTestTrait.php:73