‪TYPO3CMS  10.4
AssetDataProvider.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 
22 
24 {
25  public static function ‪filesDataProvider(): array
26  {
27  return [
28  '1 file from fileadmin' => [
29  [
30  ['file1', 'fileadmin/foo.ext', [], []]
31  ],
32  [
33  'file1' => [
34  'source' => 'fileadmin/foo.ext',
35  'attributes' => [],
36  'options' => [],
37  ]
38  ],
39  [
40  'css_no_prio' => '<link href="fileadmin/foo.ext" rel="stylesheet" type="text/css" >',
41  'css_prio' => '',
42  'js_no_prio' => '<script src="fileadmin/foo.ext"></script>',
43  'js_prio' => '',
44  ]
45  ],
46  '1 file from extension' => [
47  [
48  ['file1', 'EXT:core/Resource/Public/foo.ext', [], []]
49  ],
50  [
51  'file1' => [
52  'source' => 'EXT:core/Resource/Public/foo.ext',
53  'attributes' => [],
54  'options' => [],
55  ]
56  ],
57  [
58  'css_no_prio' => '<link href="typo3/sysext/core/Resource/Public/foo.ext" rel="stylesheet" type="text/css" >',
59  'css_prio' => '',
60  'js_no_prio' => '<script src="typo3/sysext/core/Resource/Public/foo.ext"></script>',
61  'js_prio' => '',
62  ]
63  ],
64  '1 file with suspicious source' => [
65  [
66  ['file1', '"><script>alert(1)</script><x "', [], []]
67  ],
68  [
69  'file1' => [
70  'source' => '"><script>alert(1)</script><x "',
71  'attributes' => [],
72  'options' => [],
73  ]
74  ],
75  [
76  'css_no_prio' => '<link href="&quot;&gt;&lt;script&gt;alert(1)&lt;/script&gt;&lt;x &quot;" rel="stylesheet" type="text/css" >',
77  'css_prio' => '',
78  'js_no_prio' => '<script src="&quot;&gt;&lt;script&gt;alert(1)&lt;/script&gt;&lt;x &quot;"></script>',
79  'js_prio' => '',
80  ]
81  ],
82  '1 file from external source' => [
83  [
84  ['file1', 'https://typo3.org/foo.ext', [], []]
85  ],
86  [
87  'file1' => [
88  'source' => 'https://typo3.org/foo.ext',
89  'attributes' => [],
90  'options' => [],
91  ]
92  ],
93  [
94  'css_no_prio' => '<link href="https://typo3.org/foo.ext" rel="stylesheet" type="text/css" >',
95  'css_prio' => '',
96  'js_no_prio' => '<script src="https://typo3.org/foo.ext"></script>',
97  'js_prio' => '',
98  ]
99  ],
100  '1 file from external source with one parameter' => [
101  [
102  ['file1', 'https://typo3.org/foo.ext?foo=bar', [], []]
103  ],
104  [
105  'file1' => [
106  'source' => 'https://typo3.org/foo.ext?foo=bar',
107  'attributes' => [],
108  'options' => [],
109  ]
110  ],
111  [
112  'css_no_prio' => '<link href="https://typo3.org/foo.ext?foo=bar" rel="stylesheet" type="text/css" >',
113  'css_prio' => '',
114  'js_no_prio' => '<script src="https://typo3.org/foo.ext?foo=bar"></script>',
115  'js_prio' => '',
116  ]
117  ],
118  '1 file from external source with two parameters' => [
119  [
120  ['file1', 'https://typo3.org/foo.ext?foo=bar&bar=baz', [], []]
121  ],
122  [
123  'file1' => [
124  'source' => 'https://typo3.org/foo.ext?foo=bar&bar=baz',
125  'attributes' => [],
126  'options' => [],
127  ]
128  ],
129  [
130  'css_no_prio' => '<link href="https://typo3.org/foo.ext?foo=bar&amp;bar=baz" rel="stylesheet" type="text/css" >',
131  'css_prio' => '',
132  'js_no_prio' => '<script src="https://typo3.org/foo.ext?foo=bar&amp;bar=baz"></script>',
133  'js_prio' => '',
134  ]
135  ],
136  '2 files' => [
137  [
138  ['file1', 'fileadmin/foo.ext', [], []],
139  ['file2', 'EXT:core/Resource/Public/foo.ext', [], []]
140  ],
141  [
142  'file1' => [
143  'source' => 'fileadmin/foo.ext',
144  'attributes' => [],
145  'options' => [],
146  ],
147  'file2' => [
148  'source' => 'EXT:core/Resource/Public/foo.ext',
149  'attributes' => [],
150  'options' => [],
151  ]
152  ],
153  [
154  'css_no_prio' => '<link href="fileadmin/foo.ext" rel="stylesheet" type="text/css" >' . LF . '<link href="typo3/sysext/core/Resource/Public/foo.ext" rel="stylesheet" type="text/css" >',
155  'css_prio' => '',
156  'js_no_prio' => '<script src="fileadmin/foo.ext"></script>' . LF . '<script src="typo3/sysext/core/Resource/Public/foo.ext"></script>',
157  'js_prio' => '',
158  ]
159  ],
160  '2 files with override' => [
161  [
162  ['file1', 'fileadmin/foo.ext', [], []],
163  ['file2', 'EXT:core/Resource/Public/foo.ext', [], []],
164  ['file1', 'EXT:core/Resource/Public/bar.ext', [], []]
165  ],
166  [
167  'file1' => [
168  'source' => 'EXT:core/Resource/Public/bar.ext',
169  'attributes' => [],
170  'options' => [],
171  ],
172  'file2' => [
173  'source' => 'EXT:core/Resource/Public/foo.ext',
174  'attributes' => [],
175  'options' => [],
176  ]
177  ],
178  [
179  'css_no_prio' => '<link href="typo3/sysext/core/Resource/Public/bar.ext" rel="stylesheet" type="text/css" >' . LF . '<link href="typo3/sysext/core/Resource/Public/foo.ext" rel="stylesheet" type="text/css" >',
180  'css_prio' => '',
181  'js_no_prio' => '<script src="typo3/sysext/core/Resource/Public/bar.ext"></script>' . LF . '<script src="typo3/sysext/core/Resource/Public/foo.ext"></script>',
182  'js_prio' => '',
183  ]
184  ],
185  '1 file with attributes' => [
186  [
187  ['file1', 'fileadmin/foo.ext', ['rel' => 'foo'], []]
188  ],
189  [
190  'file1' => [
191  'source' => 'fileadmin/foo.ext',
192  'attributes' => [
193  'rel' => 'foo'
194  ],
195  'options' => [],
196  ]
197  ],
198  [
199  'css_no_prio' => '<link rel="foo" href="fileadmin/foo.ext" type="text/css" >',
200  'css_prio' => '',
201  'js_no_prio' => '<script rel="foo" src="fileadmin/foo.ext"></script>',
202  'js_prio' => '',
203  ]
204  ],
205  '1 file with controlled type' => [
206  [
207  ['file1', 'fileadmin/foo.ext', ['type' => 'module'], []]
208  ],
209  [
210  'file1' => [
211  'source' => 'fileadmin/foo.ext',
212  'attributes' => [
213  'type' => 'module'
214  ],
215  'options' => [],
216  ]
217  ],
218  [
219  'css_no_prio' => '<link type="module" href="fileadmin/foo.ext" rel="stylesheet" >',
220  'css_prio' => '',
221  'js_no_prio' => '<script type="module" src="fileadmin/foo.ext"></script>',
222  'js_prio' => '',
223  ]
224  ],
225  '1 file with attributes override' => [
226  [
227  ['file1', 'fileadmin/foo.ext', ['rel' => 'foo', 'another' => 'keep on override'], []],
228  ['file1', 'fileadmin/foo.ext', ['rel' => 'bar'], []]
229  ],
230  [
231  'file1' => [
232  'source' => 'fileadmin/foo.ext',
233  'attributes' => [
234  'rel' => 'bar',
235  'another' => 'keep on override'
236  ],
237  'options' => [],
238  ]
239  ],
240  [
241  'css_no_prio' => '<link rel="bar" another="keep on override" href="fileadmin/foo.ext" type="text/css" >',
242  'css_prio' => '',
243  'js_no_prio' => '<script rel="bar" another="keep on override" src="fileadmin/foo.ext"></script>',
244  'js_prio' => '',
245  ]
246  ],
247  '1 file with options' => [
248  [
249  ['file1', 'fileadmin/foo.ext', [], ['priority' => true]]
250  ],
251  [
252  'file1' => [
253  'source' => 'fileadmin/foo.ext',
254  'attributes' => [],
255  'options' => [
256  'priority' => true
257  ],
258  ]
259  ],
260  [
261  'css_no_prio' => '',
262  'css_prio' => '<link href="fileadmin/foo.ext" rel="stylesheet" type="text/css" >',
263  'js_no_prio' => '',
264  'js_prio' => '<script src="fileadmin/foo.ext"></script>',
265  ]
266  ],
267  '1 file with options override' => [
268  [
269  ['file1', 'fileadmin/foo.ext', [], ['priority' => true, 'another' => 'keep on override']],
270  ['file1', 'fileadmin/foo.ext', [], ['priority' => false]]
271  ],
272  [
273  'file1' => [
274  'source' => 'fileadmin/foo.ext',
275  'attributes' => [],
276  'options' => [
277  'priority' => false,
278  'another' => 'keep on override'
279  ],
280  ]
281  ],
282  [
283  'css_no_prio' => '<link href="fileadmin/foo.ext" rel="stylesheet" type="text/css" >',
284  'css_prio' => '',
285  'js_no_prio' => '<script src="fileadmin/foo.ext"></script>',
286  'js_prio' => '',
287  ]
288  ],
289  ];
290  }
291 
292  public static function ‪inlineDataProvider(): array
293  {
294  return [
295  'simple data' => [
296  [
297  ['identifier_1', 'foo bar baz', [], []]
298  ],
299  [
300  'identifier_1' => [
301  'source' => 'foo bar baz',
302  'attributes' => [],
303  'options' => [],
304  ]
305  ],
306  [
307  'css_no_prio' => '<style>foo bar baz</style>',
308  'css_prio' => '',
309  'js_no_prio' => '<script>foo bar baz</script>',
310  'js_prio' => '',
311  ]
312  ],
313  '2 times simple data' => [
314  [
315  ['identifier_1', 'foo bar baz', [], []],
316  ['identifier_2', 'bar baz foo', [], []]
317  ],
318  [
319  'identifier_1' => [
320  'source' => 'foo bar baz',
321  'attributes' => [],
322  'options' => [],
323  ],
324  'identifier_2' => [
325  'source' => 'bar baz foo',
326  'attributes' => [],
327  'options' => [],
328  ]
329  ],
330  [
331  'css_no_prio' => '<style>foo bar baz</style>' . LF . '<style>bar baz foo</style>',
332  'css_prio' => '',
333  'js_no_prio' => '<script>foo bar baz</script>' . LF . '<script>bar baz foo</script>',
334  'js_prio' => '',
335  ]
336  ],
337  '2 times simple data with override' => [
338  [
339  ['identifier_1', 'foo bar baz', [], []],
340  ['identifier_2', 'bar baz foo', [], []],
341  ['identifier_1', 'baz foo bar', [], []],
342  ],
343  [
344  'identifier_1' => [
345  'source' => 'baz foo bar',
346  'attributes' => [],
347  'options' => [],
348  ],
349  'identifier_2' => [
350  'source' => 'bar baz foo',
351  'attributes' => [],
352  'options' => [],
353  ]
354  ],
355  [
356  'css_no_prio' => '<style>baz foo bar</style>' . LF . '<style>bar baz foo</style>',
357  'css_prio' => '',
358  'js_no_prio' => '<script>baz foo bar</script>' . LF . '<script>bar baz foo</script>',
359  'js_prio' => '',
360  ]
361  ],
362  'simple data with attributes' => [
363  [
364  ['identifier_1', 'foo bar baz', ['rel' => 'foo'], []],
365  ],
366  [
367  'identifier_1' => [
368  'source' => 'foo bar baz',
369  'attributes' => [
370  'rel' => 'foo'
371  ],
372  'options' => [],
373  ]
374  ],
375  [
376  'css_no_prio' => '<style rel="foo">foo bar baz</style>',
377  'css_prio' => '',
378  'js_no_prio' => '<script rel="foo">foo bar baz</script>',
379  'js_prio' => '',
380  ]
381  ],
382  'simple data with attributes override' => [
383  [
384  ['identifier_1', 'foo bar baz', ['rel' => 'foo', 'another' => 'keep on override'], []],
385  ['identifier_1', 'foo bar baz', ['rel' => 'bar'], []],
386  ],
387  [
388  'identifier_1' => [
389  'source' => 'foo bar baz',
390  'attributes' => [
391  'rel' => 'bar',
392  'another' => 'keep on override'
393  ],
394  'options' => [],
395  ]
396  ],
397  [
398  'css_no_prio' => '<style rel="bar" another="keep on override">foo bar baz</style>',
399  'css_prio' => '',
400  'js_no_prio' => '<script rel="bar" another="keep on override">foo bar baz</script>',
401  'js_prio' => '',
402  ]
403  ],
404  'simple data with options' => [
405  [
406  ['identifier_1', 'foo bar baz', [], ['priority' => true]]
407  ],
408  [
409  'identifier_1' => [
410  'source' => 'foo bar baz',
411  'attributes' => [],
412  'options' => [
413  'priority' => true
414  ],
415  ]
416  ],
417  [
418  'css_no_prio' => '',
419  'css_prio' => '<style>foo bar baz</style>',
420  'js_no_prio' => '',
421  'js_prio' => '<script>foo bar baz</script>',
422  ]
423  ],
424  'simple data with options override' => [
425  [
426  ['identifier_1', 'foo bar baz', [], ['priority' => true, 'another' => 'keep on override']],
427  ['identifier_1', 'foo bar baz', [], ['priority' => false]]
428  ],
429  [
430  'identifier_1' => [
431  'source' => 'foo bar baz',
432  'attributes' => [],
433  'options' => [
434  'priority' => false,
435  'another' => 'keep on override'
436  ],
437  ]
438  ],
439  [
440  'css_no_prio' => '<style>foo bar baz</style>',
441  'css_prio' => '',
442  'js_no_prio' => '<script>foo bar baz</script>',
443  'js_prio' => '',
444  ]
445  ],
446  ];
447  }
448 
449  public static function ‪mediaDataProvider(): array
450  {
451  return [
452  '1 image no additional information' => [
453  [
454  ['fileadmin/foo.png', []]
455  ],
456  [
457  'fileadmin/foo.png' => []
458  ]
459  ],
460  '2 images no additional information' => [
461  [
462  ['fileadmin/foo.png', []],
463  ['fileadmin/bar.png', []],
464  ],
465  [
466  'fileadmin/foo.png' => [],
467  'fileadmin/bar.png' => [],
468  ]
469  ],
470  '1 image with additional information' => [
471  [
472  ['fileadmin/foo.png', ['foo' => 'bar']]
473  ],
474  [
475  'fileadmin/foo.png' => ['foo' => 'bar']
476  ]
477  ],
478  '2 images with additional information' => [
479  [
480  ['fileadmin/foo.png', ['foo' => 'bar']],
481  ['fileadmin/bar.png', ['foo' => 'baz']],
482  ],
483  [
484  'fileadmin/foo.png' => ['foo' => 'bar'],
485  'fileadmin/bar.png' => ['foo' => 'baz'],
486  ]
487  ],
488  '2 images with additional information override' => [
489  [
490  ['fileadmin/foo.png', ['foo' => 'bar']],
491  ['fileadmin/bar.png', ['foo' => 'baz']],
492  ['fileadmin/foo.png', ['foo' => 'baz']],
493  ],
494  [
495  'fileadmin/foo.png' => ['foo' => 'baz'],
496  'fileadmin/bar.png' => ['foo' => 'baz'],
497  ]
498  ],
499  '2 images with additional information override keep existing' => [
500  [
501  ['fileadmin/foo.png', ['foo' => 'bar', 'bar' => 'baz']],
502  ['fileadmin/bar.png', ['foo' => 'baz']],
503  ['fileadmin/foo.png', ['foo' => 'baz']],
504  ],
505  [
506  'fileadmin/foo.png' => ['foo' => 'baz', 'bar' => 'baz'],
507  'fileadmin/bar.png' => ['foo' => 'baz'],
508  ]
509  ],
510  ];
511  }
512 
517  public static function ‪renderMethodsAndEventsDataProvider(): array
518  {
519  return [
520  ['renderInlineJavaScript', true, true, BeforeJavaScriptsRenderingEvent::class],
521  ['renderInlineJavaScript', true, false, BeforeJavaScriptsRenderingEvent::class],
522  ['renderJavaScript', false, true, BeforeJavaScriptsRenderingEvent::class],
523  ['renderJavaScript', false, false, BeforeJavaScriptsRenderingEvent::class],
524  ['renderInlineStylesheets', true, true, BeforeStylesheetsRenderingEvent::class],
525  ['renderInlineStylesheets', true, false, BeforeStylesheetsRenderingEvent::class],
526  ['renderStylesheets', false, true, BeforeStylesheetsRenderingEvent::class],
527  ['renderStylesheets', false, false, BeforeStylesheetsRenderingEvent::class],
528  ];
529  }
530 }
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetDataProvider\mediaDataProvider
‪static mediaDataProvider()
Definition: AssetDataProvider.php:449
‪TYPO3\CMS\Core\Tests\Unit\Page
Definition: AssetCollectorTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetDataProvider\filesDataProvider
‪static filesDataProvider()
Definition: AssetDataProvider.php:25
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetDataProvider\inlineDataProvider
‪static inlineDataProvider()
Definition: AssetDataProvider.php:292
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetDataProvider\renderMethodsAndEventsDataProvider
‪static array[] renderMethodsAndEventsDataProvider()
Definition: AssetDataProvider.php:517
‪TYPO3\CMS\Core\Page\Event\BeforeJavaScriptsRenderingEvent
Definition: BeforeJavaScriptsRenderingEvent.php:26
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetDataProvider
Definition: AssetDataProvider.php:24
‪TYPO3\CMS\Core\Page\Event\BeforeStylesheetsRenderingEvent
Definition: BeforeStylesheetsRenderingEvent.php:26