‪TYPO3CMS  ‪main
TemplatesPathsTest.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;
23 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 final class ‪TemplatesPathsTest extends FunctionalTestCase
28 {
30 
34  protected const ‪LANGUAGE_PRESETS = [
35  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
36  ];
37 
38  protected array ‪$testExtensionsToLoad = [
39  'typo3/sysext/fluid/Tests/Functional/Fixtures/Extensions/fluid_test',
40  ];
41 
42  protected array ‪$configurationToUseInTestInstance = [
43  'EXTCONF' => [
44  'extbase' => [
45  'extensions' => [
46  'FluidTest' => [
47  'plugins' => [
48  'Pi' => [
49  'controllers' => [
50  TemplateController::class => [
51  'className' => TemplateController::class,
52  'alias' => 'Template',
53  'actions' => [
54  'baseTemplate',
55  ],
56  'nonCacheableActions' => [
57  'baseTemplate',
58  ],
59  ],
60  ],
61  ],
62  ],
63  ],
64  ],
65  ],
66  ],
67  'FE' => [
68  'cacheHash' => [
69  'enforceValidation' => false,
70  ],
71  ],
72  ];
73 
74  public function ‪setUp(): void
75  {
76  parent::setUp();
77 
78  $this->importCSVDataSet(__DIR__ . '/../Fixtures/pages.csv');
80  'test',
81  $this->‪buildSiteConfiguration(1, 'https://website.local/'),
82  [
83  $this->‪buildDefaultLanguageConfiguration('EN', '/en/'),
84  ],
85  $this->‪buildErrorHandlingConfiguration('Fluid', [404]),
86  );
87  $this->setUpFrontendRootPage(1, ['EXT:fluid_test/Configuration/TypoScript/Basic.typoscript']);
88  }
89 
90  public static function ‪differentOverrideScenariosDataProvider(): array
91  {
92  return [
93  'base' => [
94  'base',
95  'Base Template',
96  'Base Partial',
97  'Base Layout',
98  ],
99  'overrideAll' => [
100  'overrideAll',
101  'Override Template',
102  'Override Partial',
103  'Override Layout',
104  ],
105  'templateOverride' => [
106  'templateOverride',
107  'TemplateOverride',
108  'Base Partial',
109  'Base Layout',
110  ],
111  'templateOverrideManual' => [
112  'templateOverrideManual',
113  'TemplateOverride',
114  'Base Partial',
115  'Base Layout',
116  ],
117  'partialOverride' => [
118  'partialOverride',
119  'Base Template',
120  'PartialOverride',
121  'Base Layout',
122  ],
123  'partialOverrideManual' => [
124  'partialOverrideManual',
125  'Base Template',
126  'PartialOverride',
127  'Base Layout',
128  ],
129  'layoutOverride' => [
130  'layoutOverride',
131  'Base Template',
132  'Base Partial',
133  'LayoutOverride',
134  ],
135  'layoutOverrideManual' => [
136  'layoutOverrideManual',
137  'Base Template',
138  'Base Partial',
139  'LayoutOverride',
140  ],
141  ];
142  }
143 
150  #[DataProvider('differentOverrideScenariosDataProvider')]
151  #[Test]
152  public function ‪baseRenderingWorksForCObject($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout): void
153  {
154  $requestArguments = [
155  'id' => '1',
156  'override' => $overrideType,
157  'mode' => 'fluidTemplate',
158  ];
159 
160  $content = $this->‪fetchFrontendResponseBody($requestArguments);
161 
162  self::assertStringContainsString($expectedTemplate, $content);
163  self::assertStringContainsString($expectedPartial, $content);
164  self::assertStringContainsString($expectedLayout, $content);
165  }
166 
173  #[DataProvider('differentOverrideScenariosDataProvider')]
174  #[Test]
175  public function ‪baseRenderingWorksForControllerAsGlobalUsage($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout): void
176  {
177  $requestArguments = [
178  'id' => '1',
179  'override' => $overrideType,
180  'mode' => 'controller',
181  ];
182 
183  $content = $this->‪fetchFrontendResponseBody($requestArguments);
184 
185  self::assertStringContainsString($expectedTemplate, $content);
186  self::assertStringContainsString($expectedPartial, $content);
187  self::assertStringContainsString($expectedLayout, $content);
188  }
189 
196  #[DataProvider('differentOverrideScenariosDataProvider')]
197  #[Test]
198  public function ‪baseRenderingWorksForControllerAsPluginUsage($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout): void
199  {
200  $requestArguments = [
201  'id' => '1',
202  'override' => $overrideType,
203  'mode' => 'plugin',
204  'pluginConfig' => 'extensionKey',
205  ];
206 
207  $content = $this->‪fetchFrontendResponseBody($requestArguments);
208 
209  self::assertStringContainsString($expectedTemplate, $content);
210  self::assertStringContainsString($expectedPartial, $content);
211  self::assertStringContainsString($expectedLayout, $content);
212  }
213 
220  #[DataProvider('differentOverrideScenariosDataProvider')]
221  #[Test]
222  public function ‪baseRenderingWorksForControllerAsPluginUsageWithPluginConfig($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout): void
223  {
224  $requestArguments = [
225  'id' => '1',
226  'override' => $overrideType,
227  'mode' => 'plugin',
228  'pluginConfig' => 'pluginName',
229  ];
230 
231  $content = $this->‪fetchFrontendResponseBody($requestArguments);
232 
233  self::assertStringContainsString($expectedTemplate, $content);
234  self::assertStringContainsString($expectedPartial, $content);
235  self::assertStringContainsString($expectedLayout, $content);
236  }
237 
238  #[Test]
240  {
241  $requestArguments = [
242  'id' => '1',
243  'override' => 'base',
244  'mode' => 'plugin',
245  'pluginConfig' => 'incomplete',
246  ];
247 
248  $content = $this->‪fetchFrontendResponseBody($requestArguments);
249 
250  self::assertStringContainsString('Base Template', $content);
251  self::assertStringContainsString('Default Layout', $content);
252  self::assertStringContainsString('Default Partial', $content);
253  }
254 
255  #[Test]
257  {
258  $requestArguments = [
259  'id' => '1',
260  'mode' => '2plugins',
261  ];
262 
263  $content = $this->‪fetchFrontendResponseBody($requestArguments);
264 
265  self::assertStringContainsString('Base Template', $content);
266  self::assertStringContainsString('Override Template', $content);
267  }
268 
269  protected function ‪fetchFrontendResponseBody(array $requestArguments): string
270  {
271  $response = $this->executeFrontendSubRequest(
272  (new InternalRequest('https://website.local/en/'))->withQueryParameters($requestArguments)
273  );
274 
275  return (string)$response->getBody();
276  }
277 }
‪TYPO3\CMS\Fluid\Tests\Functional\View\TemplatesPathsTest\setUp
‪setUp()
Definition: TemplatesPathsTest.php:73
‪TYPO3\CMS\Fluid\Tests\Functional\View\TemplatesPathsTest\baseRenderingWorksForControllerAsPluginUsageWithPluginConfig
‪baseRenderingWorksForControllerAsPluginUsageWithPluginConfig($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
Definition: TemplatesPathsTest.php:221
‪TYPO3\CMS\Fluid\Tests\Functional\View
Definition: TemplatesPathsTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:37
‪TYPO3\CMS\Fluid\Tests\Functional\View\TemplatesPathsTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: TemplatesPathsTest.php:33
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Fluid\Tests\Functional\View\TemplatesPathsTest\differentOverrideScenariosDataProvider
‪static differentOverrideScenariosDataProvider()
Definition: TemplatesPathsTest.php:89
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:88
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildErrorHandlingConfiguration
‪buildErrorHandlingConfiguration(string $handler, array $codes)
Definition: SiteBasedTestTrait.php:142
‪TYPO3\CMS\Fluid\Tests\Functional\View\TemplatesPathsTest\baseRenderingWorksForCObject
‪baseRenderingWorksForCObject($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
Definition: TemplatesPathsTest.php:151
‪TYPO3\CMS\Fluid\Tests\Functional\View\TemplatesPathsTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: TemplatesPathsTest.php:37
‪TYPO3\CMS\Fluid\Tests\Functional\View\TemplatesPathsTest
Definition: TemplatesPathsTest.php:28
‪TYPO3\CMS\Fluid\Tests\Functional\View\TemplatesPathsTest\$configurationToUseInTestInstance
‪array $configurationToUseInTestInstance
Definition: TemplatesPathsTest.php:41
‪TYPO3\CMS\Fluid\Tests\Functional\View\TemplatesPathsTest\fetchFrontendResponseBody
‪fetchFrontendResponseBody(array $requestArguments)
Definition: TemplatesPathsTest.php:268
‪TYPO3\CMS\Fluid\Tests\Functional\View\TemplatesPathsTest\baseRenderingWorksForControllerAsGlobalUsage
‪baseRenderingWorksForControllerAsGlobalUsage($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
Definition: TemplatesPathsTest.php:174
‪TYPO3Tests\FluidTest\Controller\TemplateController
Definition: TemplateController.php:24
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:98
‪TYPO3\CMS\Fluid\Tests\Functional\View\TemplatesPathsTest\baseRenderingWorksForControllerAsPluginUsageWithIncompleteConfig
‪baseRenderingWorksForControllerAsPluginUsageWithIncompleteConfig()
Definition: TemplatesPathsTest.php:238
‪TYPO3\CMS\Fluid\Tests\Functional\View\TemplatesPathsTest\baseRenderingWorksForControllerWithTwoPlugins
‪baseRenderingWorksForControllerWithTwoPlugins()
Definition: TemplatesPathsTest.php:255
‪TYPO3\CMS\Fluid\Tests\Functional\View\TemplatesPathsTest\baseRenderingWorksForControllerAsPluginUsage
‪baseRenderingWorksForControllerAsPluginUsage($overrideType, $expectedTemplate, $expectedPartial, $expectedLayout)
Definition: TemplatesPathsTest.php:197