‪TYPO3CMS  9.5
UriPrefixRenderingTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
8 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
9 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
10 
11 class ‪UriPrefixRenderingTest extends FunctionalTestCase
12 {
16  private ‪$definedResources = [
17  'absoluteCSS' => '/typo3/sysext/backend/Resources/Public/Css/backend.css',
18  'relativeCSS' => 'typo3/sysext/core/Resources/Public/Css/errorpage.css',
19  'extensionCSS' => 'EXT:rte_ckeditor/Resources/Public/Css/contents.css',
20  'externalCSS' => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css',
21  'absoluteJS' => '/typo3/sysext/backend/Resources/Public/JavaScript/backend.js',
22  'relativeJS' => 'typo3/sysext/core/Resources/Public/JavaScript/Contrib/autosize.js',
23  'extensionJS' => 'EXT:core/Resources/Public/JavaScript/Contrib/jquery.autocomplete.js',
24  'externalJS' => 'https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.11/handlebars.min.js',
25  'localImage' => 'typo3/sysext/frontend/Resources/Public/Icons/Extension.png',
26  'localLink' => '1',
27  ];
28 
32  private ‪$resolvedResources = [
33  'relativeCSS' => 'typo3/sysext/core/Resources/Public/Css/errorpage.css',
34  'extensionCSS' => 'typo3/sysext/rte_ckeditor/Resources/Public/Css/contents.css',
35  'externalCSS' => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css',
36  'relativeJS' => 'typo3/sysext/core/Resources/Public/JavaScript/Contrib/autosize.js',
37  'extensionJS' => 'typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery.autocomplete.js',
38  'externalJS' => 'https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.11/handlebars.min.js',
39  'localImage' => 'typo3/sysext/frontend/Resources/Public/Icons/Extension.png',
40  'localLink' => 'index.php?id=1',
41  ];
42 
46  protected ‪$coreExtensionsToLoad = [
47  'core', 'frontend', 'backend', 'rte_ckeditor',
48  ];
49 
54  'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/AdditionalConfiguration.php' => 'typo3conf/AdditionalConfiguration.php',
55  ];
56 
57  protected function ‪setUp()
58  {
59  parent::setUp();
60  $this->importDataSet('EXT:frontend/Tests/Functional/Fixtures/pages.xml');
61  $this->setUpFrontendRootPage(
62  1,
63  ['EXT:frontend/Tests/Functional/Rendering/Fixtures/UriPrefixRenderingTest.typoscript']
64  );
66  1,
67  $this->‪compileTypoScriptConstants($this->definedResources)
68  );
69  }
70 
72  {
73  return [
74  // no compression settings
75  'none - none' => [
76  'none', 'none',
77  [
78  'absolute' => '"{{CANDIDATE}}"',
79  'local' => '"{{CANDIDATE}}"',
80  'relative' => '"{{CANDIDATE}}\?\d+"',
81  'extension' => '"{{CANDIDATE}}\?\d+"',
82  'external' => '"{{CANDIDATE}}"',
83  ],
84  ],
85  'auto - none' => [
86  'auto', 'none',
87  [
88  'absolute' => '"{{CANDIDATE}}"',
89  'local' => '"/{{CANDIDATE}}"',
90  'relative' => '"/{{CANDIDATE}}\?\d+"',
91  'extension' => '"/{{CANDIDATE}}\?\d+"',
92  'external' => '"{{CANDIDATE}}"',
93  ],
94  ],
95  'absolute-with-host - none' => [
96  'absolute-with-host', 'none',
97  [
98  'absolute' => '"{{CANDIDATE}}"',
99  'local' => '"http://localhost/{{CANDIDATE}}"',
100  'relative' => '"http://localhost/{{CANDIDATE}}\?\d+"',
101  'extension' => '"http://localhost/{{CANDIDATE}}\?\d+"',
102  'external' => '"{{CANDIDATE}}"',
103  ],
104  ],
105  'absolute-without-host - none' => [
106  'absolute-without-host', 'none',
107  [
108  'absolute' => '"{{CANDIDATE}}"',
109  'local' => '"/{{CANDIDATE}}"',
110  'relative' => '"/{{CANDIDATE}}\?\d+"',
111  'extension' => '"/{{CANDIDATE}}\?\d+"',
112  'external' => '"{{CANDIDATE}}"',
113  ],
114  ],
115  // concatenation
116  'none - concatenate' => [
117  'none', 'concatenate',
118  [
119  '!absolute' => '{{CANDIDATE}}',
120  '!relative' => '{{CANDIDATE}}',
121  '!extension' => '{{CANDIDATE}}',
122  'absolute' => '"typo3temp/assets/compressed/merged-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
123  'local' => '"{{CANDIDATE}}"',
124  'relative' => '"typo3temp/assets/compressed/merged-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
125  'extension' => '"typo3temp/assets/compressed/merged-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
126  'external' => '"{{CANDIDATE}}"',
127  ],
128  ],
129  'auto - concatenate' => [
130  'auto', 'concatenate',
131  [
132  '!absolute' => '{{CANDIDATE}}',
133  '!relative' => '{{CANDIDATE}}',
134  '!extension' => '{{CANDIDATE}}',
135  'absolute' => '"/typo3temp/assets/compressed/merged-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
136  'local' => '"/{{CANDIDATE}}"',
137  'relative' => '"/typo3temp/assets/compressed/merged-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
138  'extension' => '"/typo3temp/assets/compressed/merged-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
139  'external' => '"{{CANDIDATE}}"',
140  ],
141  ],
142  'absolute-with-host - concatenate' => [
143  'absolute-with-host', 'concatenate',
144  [
145  '!absolute' => '{{CANDIDATE}}',
146  '!relative' => '{{CANDIDATE}}',
147  '!extension' => '{{CANDIDATE}}',
148  'absolute' => '"http://localhost/typo3temp/assets/compressed/merged-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
149  'local' => '"http://localhost/{{CANDIDATE}}"',
150  'relative' => '"http://localhost/typo3temp/assets/compressed/merged-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
151  'extension' => '"http://localhost/typo3temp/assets/compressed/merged-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
152  'external' => '"{{CANDIDATE}}"',
153  ],
154  ],
155  'absolute-without-host - concatenate' => [
156  'absolute-without-host', 'concatenate',
157  [
158  '!absolute' => '{{CANDIDATE}}',
159  '!relative' => '{{CANDIDATE}}',
160  '!extension' => '{{CANDIDATE}}',
161  'absolute' => '"/typo3temp/assets/compressed/merged-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
162  'local' => '"/{{CANDIDATE}}"',
163  'relative' => '"/typo3temp/assets/compressed/merged-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
164  'extension' => '"/typo3temp/assets/compressed/merged-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
165  'external' => '"{{CANDIDATE}}"',
166  ],
167  ],
168  // compression
169  'none - compress' => [
170  'none', 'compress',
171  [
172  '!absolute' => '{{CANDIDATE}}',
173  '!relative' => '{{CANDIDATE}}',
174  '!extension' => '{{CANDIDATE}}',
175  'absolute' => '"typo3temp/assets/compressed/{{CANDIDATE-FILENAME}}-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
176  'local' => '"{{CANDIDATE}}"',
177  'relative' => '"typo3temp/assets/compressed/{{CANDIDATE-FILENAME}}-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
178  'extension' => '"typo3temp/assets/compressed/{{CANDIDATE-FILENAME}}-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
179  'external' => '"{{CANDIDATE}}"',
180  ],
181  ],
182  'auto - compress' => [
183  'auto', 'compress',
184  [
185  '!absolute' => '{{CANDIDATE}}',
186  '!relative' => '{{CANDIDATE}}',
187  '!extension' => '{{CANDIDATE}}',
188  'absolute' => '"/typo3temp/assets/compressed/{{CANDIDATE-FILENAME}}-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
189  'local' => '"/{{CANDIDATE}}"',
190  'relative' => '"/typo3temp/assets/compressed/{{CANDIDATE-FILENAME}}-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
191  'extension' => '"/typo3temp/assets/compressed/{{CANDIDATE-FILENAME}}-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
192  'external' => '"{{CANDIDATE}}"',
193  ],
194  ],
195  'absolute-with-host - compress' => [
196  'absolute-with-host', 'compress',
197  [
198  '!absolute' => '{{CANDIDATE}}',
199  '!relative' => '{{CANDIDATE}}',
200  '!extension' => '{{CANDIDATE}}',
201  'absolute' => '"http://localhost/typo3temp/assets/compressed/{{CANDIDATE-FILENAME}}-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
202  'local' => '"http://localhost/{{CANDIDATE}}"',
203  'relative' => '"http://localhost/typo3temp/assets/compressed/{{CANDIDATE-FILENAME}}-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
204  'extension' => '"http://localhost/typo3temp/assets/compressed/{{CANDIDATE-FILENAME}}-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
205  'external' => '"{{CANDIDATE}}"',
206  ],
207  ],
208  'absolute-without-host - compress' => [
209  'absolute-without-host', 'compress',
210  [
211  '!absolute' => '{{CANDIDATE}}',
212  '!relative' => '{{CANDIDATE}}',
213  '!extension' => '{{CANDIDATE}}',
214  'absolute' => '"/typo3temp/assets/compressed/{{CANDIDATE-FILENAME}}-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
215  'local' => '"/{{CANDIDATE}}"',
216  'relative' => '"/typo3temp/assets/compressed/{{CANDIDATE-FILENAME}}-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
217  'extension' => '"/typo3temp/assets/compressed/{{CANDIDATE-FILENAME}}-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
218  'external' => '"{{CANDIDATE}}"',
219  ],
220  ],
221  // concatenation & compression
222  'none - concatenate-and-compress' => [
223  'none', 'concatenate-and-compress',
224  [
225  '!absolute' => '{{CANDIDATE}}',
226  '!relative' => '{{CANDIDATE}}',
227  '!extension' => '{{CANDIDATE}}',
228  'absolute' => '"typo3temp/assets/compressed/merged-[a-z0-9]+-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
229  'local' => '"{{CANDIDATE}}"',
230  'relative' => '"typo3temp/assets/compressed/merged-[a-z0-9]+-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
231  'extension' => '"typo3temp/assets/compressed/merged-[a-z0-9]+-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
232  'external' => '"{{CANDIDATE}}"',
233  ],
234  ],
235  'auto - concatenate-and-compress' => [
236  'auto', 'concatenate-and-compress',
237  [
238  '!absolute' => '{{CANDIDATE}}',
239  '!relative' => '{{CANDIDATE}}',
240  '!extension' => '{{CANDIDATE}}',
241  'absolute' => '"/typo3temp/assets/compressed/merged-[a-z0-9]+-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
242  'local' => '"/{{CANDIDATE}}"',
243  'relative' => '"/typo3temp/assets/compressed/merged-[a-z0-9]+-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
244  'extension' => '"/typo3temp/assets/compressed/merged-[a-z0-9]+-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
245  'external' => '"{{CANDIDATE}}"',
246  ],
247  ],
248  'absolute-with-host - concatenate-and-compress' => [
249  'absolute-with-host', 'concatenate-and-compress',
250  [
251  '!absolute' => '{{CANDIDATE}}',
252  '!relative' => '{{CANDIDATE}}',
253  '!extension' => '{{CANDIDATE}}',
254  'absolute' => '"http://localhost/typo3temp/assets/compressed/merged-[a-z0-9]+-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
255  'local' => '"http://localhost/{{CANDIDATE}}"',
256  'relative' => '"http://localhost/typo3temp/assets/compressed/merged-[a-z0-9]+-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
257  'extension' => '"http://localhost/typo3temp/assets/compressed/merged-[a-z0-9]+-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
258  'external' => '"{{CANDIDATE}}"',
259  ],
260  ],
261  'absolute-without-host - concatenate-and-compress' => [
262  'absolute-without-host', 'concatenate-and-compress',
263  [
264  '!absolute' => '{{CANDIDATE}}',
265  '!relative' => '{{CANDIDATE}}',
266  '!extension' => '{{CANDIDATE}}',
267  'absolute' => '"/typo3temp/assets/compressed/merged-[a-z0-9]+-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
268  'local' => '"/{{CANDIDATE}}"',
269  'relative' => '"/typo3temp/assets/compressed/merged-[a-z0-9]+-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
270  'extension' => '"/typo3temp/assets/compressed/merged-[a-z0-9]+-[a-z0-9]+\.{{CANDIDATE-EXTENSION}}\?\d+"',
271  'external' => '"{{CANDIDATE}}"',
272  ],
273  ],
274  ];
275  }
276 
284  public function ‪urisAreRenderedUsingAbsRefPrefix(string $absRefPrefixAspect, string $compressorAspect, array $expectations)
285  {
286  $response = $this->executeFrontendRequest(
287  (new InternalRequest())->withQueryParameters([
288  'id' => 1,
289  'testAbsRefPrefix' => $absRefPrefixAspect,
290  'testCompressor' => $compressorAspect,
291  ])
292  );
293  $content = (string)$response->getBody();
294 
295  foreach ($expectations as $type => $expectation) {
296  $shallExist = true;
297  if (strpos($type, '!') === 0) {
298  $shallExist = false;
299  $type = substr($type, 1);
300  }
301  $candidates = array_map(
302  function (string $candidateKey) {
303  return $this->resolvedResources[$candidateKey];
304  },
305  array_filter(
306  array_keys($this->resolvedResources),
307  function (string $candidateKey) use ($type) {
308  return strpos($candidateKey, $type) === 0;
309  }
310  )
311  );
312  foreach ($candidates as $candidate) {
313  $pathInfo = pathinfo($candidate);
314  $pattern = str_replace(
315  [
316  '{{CANDIDATE}}',
317  '{{CANDIDATE-FILENAME}}',
318  '{{CANDIDATE-EXTENSION}}',
319  ],
320  [
321  preg_quote($candidate, '#'),
322  preg_quote($pathInfo['filename'], '#'),
323  preg_quote($pathInfo['extension'], '#'),
324  ],
325  $expectation
326  );
327 
328  if ($shallExist) {
329  $this->assertRegExp(
330  '#' . $pattern . '#',
331  $content
332  );
333  } else {
334  $this->assertNotRegExp(
335  '#' . $pattern . '#',
336  $content
337  );
338  }
339  }
340  }
341  }
342 
350  protected function ‪setTypoScriptConstantsToTemplateRecord(int $pageId, string $constants, bool $append = false)
351  {
352  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_template');
353 
354  $template = $connection->select(['uid', 'constants'], 'sys_template', ['pid' => $pageId, 'root' => 1])->fetch();
355  if (empty($template)) {
356  $this->fail('Cannot find root template on page with id: "' . $pageId . '"');
357  }
358  $updateFields['constants'] = ($append ? $template['constants'] . LF : '') . $constants;
359  $connection->update(
360  'sys_template',
361  $updateFields,
362  ['uid' => $template['uid']]
363  );
364  }
365 
370  protected function ‪compileTypoScriptConstants(array $constants): string
371  {
372  $lines = [];
373  foreach ($constants as $constantName => $constantValue) {
374  $lines[] = $constantName . ' = ' . $constantValue;
375  }
376  return implode(PHP_EOL, $lines);
377  }
378 }
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\UriPrefixRenderingTest\$resolvedResources
‪string[] $resolvedResources
Definition: UriPrefixRenderingTest.php:30
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\UriPrefixRenderingTest\$definedResources
‪string[] $definedResources
Definition: UriPrefixRenderingTest.php:15
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\UriPrefixRenderingTest\urisAreRenderedUsingAbsRefPrefixDataProvider
‪urisAreRenderedUsingAbsRefPrefixDataProvider()
Definition: UriPrefixRenderingTest.php:67
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\UriPrefixRenderingTest\compileTypoScriptConstants
‪string compileTypoScriptConstants(array $constants)
Definition: UriPrefixRenderingTest.php:366
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\UriPrefixRenderingTest\$pathsToLinkInTestInstance
‪string[] $pathsToLinkInTestInstance
Definition: UriPrefixRenderingTest.php:49
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\UriPrefixRenderingTest\setUp
‪setUp()
Definition: UriPrefixRenderingTest.php:53
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\UriPrefixRenderingTest\$coreExtensionsToLoad
‪string[] $coreExtensionsToLoad
Definition: UriPrefixRenderingTest.php:43
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\UriPrefixRenderingTest
Definition: UriPrefixRenderingTest.php:12
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\UriPrefixRenderingTest\setTypoScriptConstantsToTemplateRecord
‪setTypoScriptConstantsToTemplateRecord(int $pageId, string $constants, bool $append=false)
Definition: UriPrefixRenderingTest.php:346
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\UriPrefixRenderingTest\urisAreRenderedUsingAbsRefPrefix
‪urisAreRenderedUsingAbsRefPrefix(string $absRefPrefixAspect, string $compressorAspect, array $expectations)
Definition: UriPrefixRenderingTest.php:280
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering
Definition: LocalizedContentRenderingTest.php:4