‪TYPO3CMS  ‪main
SvgImageViewHelperTest.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;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 use TYPO3Fluid\Fluid\View\TemplateView;
26 
27 final class ‪SvgImageViewHelperTest extends FunctionalTestCase
28 {
29  protected array ‪$coreExtensionsToLoad = ['filemetadata'];
30 
32  'typo3/sysext/fluid/Tests/Functional/Fixtures/ViewHelpers/ImageViewHelperTest1.svg' => 'fileadmin/user_upload/FALImageViewHelperTest1.svg',
33  'typo3/sysext/fluid/Tests/Functional/Fixtures/ViewHelpers/ImageViewHelperTest2.svg' => 'fileadmin/user_upload/FALImageViewHelperTest2.svg',
34  'typo3/sysext/fluid/Tests/Functional/Fixtures/ViewHelpers/ImageViewHelperTest3.svg' => 'fileadmin/user_upload/FALImageViewHelperTest3.svg',
35  'typo3/sysext/fluid/Tests/Functional/Fixtures/ViewHelpers/ImageViewHelperTest4.svg' => 'fileadmin/user_upload/FALImageViewHelperTest4.svg',
36  'typo3/sysext/fluid/Tests/Functional/Fixtures/ViewHelpers/ImageViewHelperTest5.svg' => 'fileadmin/user_upload/FALImageViewHelperTest5.svg',
37  ];
38 
39  protected array ‪$additionalFoldersToCreate = [
40  '/fileadmin/user_upload',
41  ];
42 
43  public function ‪setUp(): void
44  {
45  parent::setUp();
46  $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv');
47  $this->importCSVDataSet(__DIR__ . '/../Fixtures/crops.csv');
48  $this->setUpBackendUser(1);
49  }
50 
51  public static function ‪renderReturnsExpectedMarkupDataProvider(): array
52  {
62  // width, height, [scalingFactorBasedOnWidth (60px/80%)], [scalingFactorBasedOnOffset (15px/10%)], [pixelBasedOnOffset]
63  $dimensionMap = [
64  'ImageViewHelperTest1.svg' => [
65  'input' => [1680, 1050],
66  'fixedCrop60px' => [60, 38, 0.03571428572, 0.008928571429, 15, 9],
67  'heightAtMaxWidth60px' => 62,
68  'relativeCrop80Percent' => [1344, 840, 0.8, 0.1, 168, 105],
69  'falUidCropped' => 1,
70  'falUidUncropped' => 6,
71  'falCropString' => '77 581 231 238',
72  'falCropDim' => [231, 238],
73  ],
74  'ImageViewHelperTest2.svg' => [
75  'input' => [283.5, 283.5],
76  'fixedCrop60px' => [60, 60, 0.2116402117, 0.05291005291, 14, 14],
77  'heightAtMaxWidth60px' => 15,
78  'relativeCrop80Percent' => [226, 226, 0.8, 0.1, 28, 28],
79  'falUidCropped' => 2,
80  'falUidUncropped' => 7,
81  'falCropString' => '18 62 241 60',
82  'falCropDim' => [241, 60],
83  ],
84  'ImageViewHelperTest3.svg' => [
85  'input' => [940.7, 724],
86  'fixedCrop60px' => [60, 46, 0.06378228979, 0.01594557245, 15, 11],
87  'heightAtMaxWidth60px' => 109,
88  'relativeCrop80Percent' => [753, 579, 0.8, 0.1, 94, 72],
89  'falUidCropped' => 3,
90  'falUidUncropped' => 8,
91  'falCropString' => '235 303 176 320',
92  'falCropDim' => [176, 320],
93  ],
94  'ImageViewHelperTest4.svg' => [
95  'input' => [1680, 1050],
96  'fixedCrop60px' => [60, 38, 0.03571428572, 0.008928571429, 15, 9],
97  'heightAtMaxWidth60px' => 69,
98  'relativeCrop80Percent' => [1344, 840, 0.8, 0.1, 168, 105],
99  'falUidCropped' => 4,
100  'falUidUncropped' => 9,
101  'falCropString' => '59 345 114 131',
102  'falCropDim' => [113, 131],
103  ],
104  ];
105 
106  $expected = [];
107 
108  $maximum = count($dimensionMap);
109 
110  $storageDirOriginal = 'typo3/sysext/fluid/Tests/Functional/Fixtures/ViewHelpers';
111  $storageDirTemp = 'typo3temp/assets/_processed_/[0-9a-f]/[0-9a-f]';
112  $storageDirFal = 'fileadmin/user_upload';
113  $storageDirFalTemp = 'fileadmin/_processed_/[0-9a-f]/[0-9a-f]';
114 
115  // To prevent excess copy and paste labor, this is done programmatically:
116  for ($i = 1; $i <= $maximum; $i++) {
117  $fn = 'ImageViewHelperTest' . $i . '.svg';
118  $fUid = $dimensionMap[$fn]['falUidCropped'];
119  $fUidUncropped = $dimensionMap[$fn]['falUidUncropped'];
120 
121  $width = round($dimensionMap[$fn]['input'][0]);
122  $height = round($dimensionMap[$fn]['input'][1]);
123 
124  // Note: Uncropped SVGs are returned from their original location. No conversion/tampering is done.
125 
126  //# SECTION 1: Referenced via EXT: ###
127  $expected[sprintf('no crop (%s)', $fn)] = [
128  sprintf(
129  '<f:image src="EXT:fluid/Tests/Functional/Fixtures/ViewHelpers/%s" width="%d" height="%d" />',
130  $fn,
131  $width,
132  $height,
133  ),
134  sprintf(
135  '@^<img src="(%s/%s)" width="%d" height="%d" alt="" />$@',
136  $storageDirOriginal,
137  $fn,
138  $width,
139  $height,
140  ),
141  null,
142  false,
143  ];
144 
145  $expected[sprintf('empty crop (%s)', $fn)] = [
146  sprintf(
147  '<f:image src="EXT:fluid/Tests/Functional/Fixtures/ViewHelpers/%s" width="%d" height="%d" crop="null" />',
148  $fn,
149  $width,
150  $height,
151  ),
152  sprintf(
153  '@^<img src="(%s/%s)" width="%d" height="%d" alt="" />$@',
154  $storageDirOriginal,
155  $fn,
156  $width,
157  $height,
158  ),
159  null,
160  false,
161  ];
162 
163  $expected[sprintf('crop as array - forced 60px (%s)', $fn)] = [
164  sprintf(
165  '<f:image src="EXT:fluid/Tests/Functional/Fixtures/ViewHelpers/%1$s" width="%2$d" height="%3$d" crop="{\'default\':{\'cropArea\':{\'width\':%4$s,\'height\':%4$s,\'x\':%5$s,\'y\':%5$s},\'selectedRatio\':\'1:1\',\'focusArea\':null}}" />',
166  $fn,
167  $dimensionMap[$fn]['fixedCrop60px'][0], // width
168  $dimensionMap[$fn]['fixedCrop60px'][1], // height
169  $dimensionMap[$fn]['fixedCrop60px'][2], // crop-string width/height
170  $dimensionMap[$fn]['fixedCrop60px'][3] // crop-string offset left/top
171  ),
172  sprintf(
173  '@^<img src="(%s/csm_ImageViewHelperTest%d_.*\.svg)" width="%d" height="%d" alt="" />$@',
174  $storageDirTemp,
175  $i,
176  $dimensionMap[$fn]['fixedCrop60px'][0],
177  $dimensionMap[$fn]['fixedCrop60px'][1],
178  ),
179  $dimensionMap[$fn]['fixedCrop60px'][4] . ' ' . $dimensionMap[$fn]['fixedCrop60px'][5] . ' ' . $dimensionMap[$fn]['fixedCrop60px'][0] . ' ' . $dimensionMap[$fn]['fixedCrop60px'][1],
180  ];
181 
182  $expected[sprintf('crop as array - no width/height (%s)', $fn)] = [
183  sprintf(
184  '<f:image src="EXT:fluid/Tests/Functional/Fixtures/ViewHelpers/%1$s" crop="{\'default\':{\'cropArea\':{\'width\':%2$s,\'height\':%2$s,\'x\':%3$s,\'y\':%3$s},\'selectedRatio\':\'1:1\',\'focusArea\':null}}" />',
185  $fn,
186  $dimensionMap[$fn]['relativeCrop80Percent'][2], // crop-string width/height
187  $dimensionMap[$fn]['relativeCrop80Percent'][3] // crop-string offset left/top
188  ),
189  sprintf(
190  '@^<img src="(%s/csm_ImageViewHelperTest%d_.*\.svg)" width="%d" height="%d" alt="" />$@',
191  $storageDirTemp,
192  $i,
193  $dimensionMap[$fn]['relativeCrop80Percent'][0],
194  $dimensionMap[$fn]['relativeCrop80Percent'][1],
195  ),
196  $dimensionMap[$fn]['relativeCrop80Percent'][4] . ' ' . $dimensionMap[$fn]['relativeCrop80Percent'][5] . ' ' . $dimensionMap[$fn]['relativeCrop80Percent'][0] . ' ' . $dimensionMap[$fn]['relativeCrop80Percent'][1],
197  ];
198 
199  $expected[sprintf('force pixel-conversion, no crop (%s)', $fn)] = [
200  sprintf(
201  '<f:image src="EXT:fluid/Tests/Functional/Fixtures/ViewHelpers/%s" width="%d" height="%d" fileExtension="png" />',
202  $fn,
203  $width,
204  $height,
205  ),
206  sprintf(
207  '@^<img src="(%s/csm_ImageViewHelperTest%d_.*\.png)" width="%d" height="%d" alt="" />$@',
208  $storageDirTemp,
209  $i,
210  $width,
211  $height,
212  ),
213  null,
214  ];
215 
216  $expected[sprintf('force pixel-conversion, with crop (%s)', $fn)] = [
217  sprintf(
218  '<f:image src="EXT:fluid/Tests/Functional/Fixtures/ViewHelpers/%1$s" fileExtension="png" width="%2$d" height="%3$d" crop="{\'default\':{\'cropArea\':{\'width\':%4$s,\'height\':%4$s,\'x\':%5$s,\'y\':%5$s},\'selectedRatio\':\'1:1\',\'focusArea\':null}}" />',
219  $fn,
220  $dimensionMap[$fn]['relativeCrop80Percent'][0], // width
221  $dimensionMap[$fn]['relativeCrop80Percent'][1], // height
222  $dimensionMap[$fn]['relativeCrop80Percent'][2], // crop-string width/height
223  $dimensionMap[$fn]['relativeCrop80Percent'][3] // crop-string offset left/top
224  ),
225  sprintf(
226  '@^<img src="(%s/csm_ImageViewHelperTest%d_.*\.png)" width="%d" height="%d" alt="" />$@',
227  $storageDirTemp,
228  $i,
229  $dimensionMap[$fn]['relativeCrop80Percent'][0],
230  $dimensionMap[$fn]['relativeCrop80Percent'][1],
231  ),
232  $dimensionMap[$fn]['relativeCrop80Percent'][4] . ' ' . $dimensionMap[$fn]['relativeCrop80Percent'][5] . $dimensionMap[$fn]['relativeCrop80Percent'][0] . ' ' . $dimensionMap[$fn]['relativeCrop80Percent'][1],
233  ];
234  //############################################################################
235 
236  //# SECTION 2: Referenced via UID, cropped via sys_file_reference (with overrides) ###
237  // width/height is using the original dimensions, contained crop will be rendered within
238  $expected[sprintf('using sys_file_reference crop (UID %d)', $fUid)] = [
239  sprintf(
240  '<f:image src="%1$d" treatIdAsReference="true" width="%2$d" height="%3$d" />',
241  $fUid,
242  $width,
243  $height,
244  ),
245  sprintf(
246  '@^<img src="(%s/csm_FALImageViewHelperTest%d_.*\.svg)" width="%d" height="%d" alt="" />$@',
247  $storageDirFalTemp,
248  $i,
249  $width,
250  $height,
251  ),
252  $dimensionMap[$fn]['falCropString'], // Stored in sys_file_reference
253  true,
254  ];
255 
256  $expected[sprintf('using sys_file_reference crop, using maxWidth (60px, UID %d)', $fUid)] = [
257  sprintf(
258  '<f:image src="%1$d" treatIdAsReference="true" maxWidth="60" />',
259  $fUid,
260  ),
261  sprintf(
262  '@^<img src="(%s/csm_FALImageViewHelperTest%d_.*\.svg)" width="60" height="%d" alt="" />$@',
263  $storageDirFalTemp,
264  $i,
265  $dimensionMap[$fn]['heightAtMaxWidth60px']
266  ),
267  $dimensionMap[$fn]['falCropString'], // Stored in sys_file_reference
268  true,
269  ];
270 
271  $expected[sprintf('empty crop (UID %d)', $fUid)] = [
272  sprintf(
273  '<f:image src="%1$d" treatIdAsReference="true" width="%2$d" height="%3$d" crop="null" />',
274  $fUid,
275  $width,
276  $height,
277  ),
278  sprintf(
279  '@^<img src="(%s/%s)" width="%d" height="%d" alt="" />$@',
280  $storageDirFal,
281  'FAL' . $fn,
282  $width,
283  $height,
284  ),
285  null,
286  false,
287  ];
288 
289  $expected[sprintf('crop as array - forced 60px (UID %d)', $fUid)] = [
290  sprintf(
291  '<f:image src="%1$d" treatIdAsReference="true" width="%2$d" height="%3$d" crop="{\'default\':{\'cropArea\':{\'width\':%4$s,\'height\':%4$s,\'x\':%5$s,\'y\':%5$s},\'selectedRatio\':\'1:1\',\'focusArea\':null}}" />',
292  $fUid,
293  $dimensionMap[$fn]['fixedCrop60px'][0], // width
294  $dimensionMap[$fn]['fixedCrop60px'][1], // height
295  $dimensionMap[$fn]['fixedCrop60px'][2], // crop-string width/height
296  $dimensionMap[$fn]['fixedCrop60px'][3] // crop-string offset left/top
297  ),
298  sprintf(
299  '@^<img src="(%s/csm_FALImageViewHelperTest%d_.*\.svg)" width="%d" height="%d" alt="" />$@',
300  $storageDirFalTemp,
301  $i,
302  $dimensionMap[$fn]['fixedCrop60px'][0],
303  $dimensionMap[$fn]['fixedCrop60px'][1],
304  ),
305  $dimensionMap[$fn]['fixedCrop60px'][4] . ' ' . $dimensionMap[$fn]['fixedCrop60px'][5] . ' ' . $dimensionMap[$fn]['fixedCrop60px'][0] . ' ' . $dimensionMap[$fn]['fixedCrop60px'][1],
306  ];
307 
308  $expected[sprintf('crop as array - no width/height (UID %d)', $fUid)] = [
309  sprintf(
310  '<f:image src="%1$d" treatIdAsReference="true" crop="{\'default\':{\'cropArea\':{\'width\':%2$s,\'height\':%2$s,\'x\':%3$s,\'y\':%3$s},\'selectedRatio\':\'1:1\',\'focusArea\':null}}" />',
311  $fUid,
312  $dimensionMap[$fn]['relativeCrop80Percent'][2], // crop-string width/height
313  $dimensionMap[$fn]['relativeCrop80Percent'][3] // crop-string offset left/top
314  ),
315  sprintf(
316  '@^<img src="(%s/csm_FALImageViewHelperTest%d_.*\.svg)" width="%d" height="%d" alt="" />$@',
317  $storageDirFalTemp,
318  $i,
319  $dimensionMap[$fn]['relativeCrop80Percent'][0],
320  $dimensionMap[$fn]['relativeCrop80Percent'][1],
321  ),
322  $dimensionMap[$fn]['relativeCrop80Percent'][4] . ' ' . $dimensionMap[$fn]['relativeCrop80Percent'][5] . ' ' . $dimensionMap[$fn]['relativeCrop80Percent'][0] . ' ' . $dimensionMap[$fn]['relativeCrop80Percent'][1],
323  ];
324 
325  $expected[sprintf('force pixel-conversion, sys_file_reference crop (UID %d)', $fUid)] = [
326  sprintf(
327  '<f:image src="%1$d" treatIdAsReference="true" width="%2$d" height="%3$d" fileExtension="png" />',
328  $fUid,
329  $width,
330  $height,
331  ),
332  sprintf(
333  '@^<img src="(%s/csm_FALImageViewHelperTest%d_.*\.png)" width="%d" height="%d" alt="" />$@',
334  $storageDirFalTemp,
335  $i,
336  $width,
337  $height,
338  ),
339  null,
340  ];
341 
342  $expected[sprintf('force pixel-conversion, with crop (UID %d)', $fUid)] = [
343  sprintf(
344  '<f:image src="%1$d" treatIdAsReference="true" fileExtension="png" width="%2$d" height="%3$d" crop="{\'default\':{\'cropArea\':{\'width\':%4$s,\'height\':%4$s,\'x\':%5$s,\'y\':%5$s},\'selectedRatio\':\'1:1\',\'focusArea\':null}}" />',
345  $fUid,
346  $dimensionMap[$fn]['relativeCrop80Percent'][0], // width
347  $dimensionMap[$fn]['relativeCrop80Percent'][1], // height
348  $dimensionMap[$fn]['relativeCrop80Percent'][2], // crop-string width/height
349  $dimensionMap[$fn]['relativeCrop80Percent'][3] // crop-string offset left/top
350  ),
351  sprintf(
352  '@^<img src="(%s/csm_FALImageViewHelperTest%d_.*\.png)" width="%d" height="%d" alt="" />$@',
353  $storageDirFalTemp,
354  $i,
355  $dimensionMap[$fn]['relativeCrop80Percent'][0],
356  $dimensionMap[$fn]['relativeCrop80Percent'][1],
357  ),
358  $dimensionMap[$fn]['relativeCrop80Percent'][4] . ' ' . $dimensionMap[$fn]['relativeCrop80Percent'][5] . $dimensionMap[$fn]['relativeCrop80Percent'][0] . ' ' . $dimensionMap[$fn]['relativeCrop80Percent'][1],
359  ];
360  //############################################################################
361 
362  //# SECTION 3: Referenced via UID, uncropped in sys_file_reference ###
363  $expected[sprintf('no crop (uncrop-UID %d)', $fUidUncropped)] = [
364  sprintf(
365  '<f:image src="%1$d" treatIdAsReference="true" width="%2$d" height="%3$d" />',
366  $fUidUncropped,
367  $width,
368  $height,
369  ),
370  sprintf(
371  '@^<img src="(%s/%s)" width="%d" height="%d" alt="" />$@',
372  $storageDirFal,
373  'FAL' . $fn,
374  $width,
375  $height,
376  ),
377  null,
378  false,
379  ];
380 
381  $expected[sprintf('empty crop (uncrop-UID %d)', $fUidUncropped)] = [
382  sprintf(
383  '<f:image src="%1$d" treatIdAsReference="true" width="%2$d" height="%3$d" crop="null" />',
384  $fUidUncropped,
385  $width,
386  $height,
387  ),
388  sprintf(
389  '@^<img src="(%s/%s)" width="%d" height="%d" alt="" />$@',
390  $storageDirFal,
391  'FAL' . $fn,
392  $width,
393  $height,
394  ),
395  null,
396  false,
397  ];
398 
399  $expected[sprintf('crop as array - forced 60px (uncrop-UID %d)', $fUidUncropped)] = [
400  sprintf(
401  '<f:image src="%1$d" treatIdAsReference="true" width="%2$d" height="%3$d" crop="{\'default\':{\'cropArea\':{\'width\':%4$s,\'height\':%4$s,\'x\':%5$s,\'y\':%5$s},\'selectedRatio\':\'1:1\',\'focusArea\':null}}" />',
402  $fUidUncropped,
403  $dimensionMap[$fn]['fixedCrop60px'][0], // width
404  $dimensionMap[$fn]['fixedCrop60px'][1], // height
405  $dimensionMap[$fn]['fixedCrop60px'][2], // crop-string width/height
406  $dimensionMap[$fn]['fixedCrop60px'][3] // crop-string offset left/top
407  ),
408  sprintf(
409  '@^<img src="(%s/csm_FALImageViewHelperTest%d_.*\.svg)" width="%d" height="%d" alt="" />$@',
410  $storageDirFalTemp,
411  $i,
412  $dimensionMap[$fn]['fixedCrop60px'][0],
413  $dimensionMap[$fn]['fixedCrop60px'][1],
414  ),
415  $dimensionMap[$fn]['fixedCrop60px'][4] . ' ' . $dimensionMap[$fn]['fixedCrop60px'][5] . ' ' . $dimensionMap[$fn]['fixedCrop60px'][0] . ' ' . $dimensionMap[$fn]['fixedCrop60px'][1],
416  ];
417 
418  $expected[sprintf('crop as array - no width/height (uncrop-UID %d)', $fUidUncropped)] = [
419  sprintf(
420  '<f:image src="%1$d" treatIdAsReference="true" crop="{\'default\':{\'cropArea\':{\'width\':%2$s,\'height\':%2$s,\'x\':%3$s,\'y\':%3$s},\'selectedRatio\':\'1:1\',\'focusArea\':null}}" />',
421  $fUidUncropped,
422  $dimensionMap[$fn]['relativeCrop80Percent'][2], // crop-string width/height
423  $dimensionMap[$fn]['relativeCrop80Percent'][3] // crop-string offset left/top
424  ),
425  sprintf(
426  '@^<img src="(%s/csm_FALImageViewHelperTest%d_.*\.svg)" width="%d" height="%d" alt="" />$@',
427  $storageDirFalTemp,
428  $i,
429  $dimensionMap[$fn]['relativeCrop80Percent'][0],
430  $dimensionMap[$fn]['relativeCrop80Percent'][1],
431  ),
432  $dimensionMap[$fn]['relativeCrop80Percent'][4] . ' ' . $dimensionMap[$fn]['relativeCrop80Percent'][5] . ' ' . $dimensionMap[$fn]['relativeCrop80Percent'][0] . ' ' . $dimensionMap[$fn]['relativeCrop80Percent'][1],
433  ];
434 
435  $expected[sprintf('force pixel-conversion, no crop (uncrop-UID %d)', $fUidUncropped)] = [
436  sprintf(
437  '<f:image src="%1$d" treatIdAsReference="true" width="%2$d" height="%3$d" fileExtension="png" />',
438  $fUidUncropped,
439  $width,
440  $height,
441  ),
442  sprintf(
443  '@^<img src="(%s/csm_FALImageViewHelperTest%d_.*\.png)" width="%d" height="%d" alt="" />$@',
444  $storageDirFalTemp,
445  $i,
446  $width,
447  $height,
448  ),
449  null,
450  ];
451 
452  $expected[sprintf('force pixel-conversion, with crop (uncrop-UID %d)', $fUidUncropped)] = [
453  sprintf(
454  '<f:image src="%1$d" treatIdAsReference="true" fileExtension="png" width="%2$d" height="%3$d" crop="{\'default\':{\'cropArea\':{\'width\':%4$s,\'height\':%4$s,\'x\':%5$s,\'y\':%5$s},\'selectedRatio\':\'1:1\',\'focusArea\':null}}" />',
455  $fUidUncropped,
456  $dimensionMap[$fn]['relativeCrop80Percent'][0], // width
457  $dimensionMap[$fn]['relativeCrop80Percent'][1], // height
458  $dimensionMap[$fn]['relativeCrop80Percent'][2], // crop-string width/height
459  $dimensionMap[$fn]['relativeCrop80Percent'][3] // crop-string offset left/top
460  ),
461  sprintf(
462  '@^<img src="(%s/csm_FALImageViewHelperTest%d_.*\.png)" width="%d" height="%d" alt="" />$@',
463  $storageDirFalTemp,
464  $i,
465  $dimensionMap[$fn]['relativeCrop80Percent'][0],
466  $dimensionMap[$fn]['relativeCrop80Percent'][1],
467  ),
468  $dimensionMap[$fn]['relativeCrop80Percent'][4] . ' ' . $dimensionMap[$fn]['relativeCrop80Percent'][5] . $dimensionMap[$fn]['relativeCrop80Percent'][0] . ' ' . $dimensionMap[$fn]['relativeCrop80Percent'][1],
469  ];
470  //############################################################################
471  }
472 
473  // Iterate the whole array, utilize and test f:uri.image with the same inputs.
474  // This is done if in the future the two viewHelpers may diverge from each other,
475  // to still perform all tests properly.
476  $uriImageCopy = $expected;
477  foreach ($uriImageCopy as $expectedKey => $imageViewHelperGreatExpectations) {
478  // Switch and bait execution string
479  $imageViewHelperGreatExpectations[0] = str_replace('<f:image', '<f:uri.image', $imageViewHelperGreatExpectations[0]);
480  // ... and expectation string
481  $imageViewHelperGreatExpectations[1] = '@^' . preg_replace('@^.+src="(.+)".+$@imsU', '\1', $imageViewHelperGreatExpectations[1]) . '$@';
482 
483  // ... and append to the main data provider
484  $expected[$expectedKey . ' (f:uri.image)'] = $imageViewHelperGreatExpectations;
485  }
486 
487  return $expected;
488  }
489 
490  #[DataProvider('renderReturnsExpectedMarkupDataProvider')]
491  #[Test]
492  public function ‪renderReturnsExpectedMarkup(string $template, string $expected, string|null $cropResult, bool $expectProcessedFile = true): void
493  {
494  $context = $this->get(RenderingContextFactory::class)->create();
495  $context->getTemplatePaths()->setTemplateSource($template);
496  $actual = (new TemplateView($context))->render();
497  self::assertMatchesRegularExpression($expected, $actual);
498 
499  $dumpTables = [
500  'sys_file_processedfile' => 1,
501  ];
502 
503  foreach ($dumpTables as $dumpTable => $expectedRecords) {
504  $queryBuilder = $this->getConnectionPool()->getQueryBuilderForTable($dumpTable);
505  $rows =
506  $queryBuilder
507  ->select('*')
508  ->from($dumpTable)
509  ->executeQuery()
510  ->fetchAllAssociative();
511 
512  self::assertEquals(count($rows), $expectedRecords, sprintf('Expected post-conversion database records in %s do not match.', $dumpTable));
513 
514  if ($dumpTable === 'sys_file_processedfile' && $expectProcessedFile) {
515  // Only SVGs count
516  if (str_ends_with($rows[0]['identifier'], '.svg')) {
517  $this->‪verifySvg($rows[0], $cropResult);
518  }
519  }
520  }
521  }
522 
523  protected function ‪verifySvg(array $file, string|null $cropResult)
524  {
525  if ($file['storage'] == 1) {
526  ‪$dir = ‪Environment::getPublicPath() . '/fileadmin';
527  } else {
529  }
530 
531  $svg = new \DOMDocument();
532  $svg->load(‪$dir . $file['identifier']);
533 
534  self::assertEquals($file['width'], $svg->documentElement->getAttribute('width'), 'SVG "width" mismatch.');
535  self::assertEquals($file['height'], $svg->documentElement->getAttribute('height'), 'SVG "height" mismatch.');
536  self::assertEquals($cropResult, $svg->documentElement->getAttribute('viewBox'), 'SVG "viewBox" (crop) mismatch.');
537  unlink(‪$dir . $file['identifier']);
538  }
539 
540 }
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\SvgImageViewHelperTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: SvgImageViewHelperTest.php:29
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\SvgImageViewHelperTest
Definition: SvgImageViewHelperTest.php:28
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\SvgImageViewHelperTest\verifySvg
‪verifySvg(array $file, string|null $cropResult)
Definition: SvgImageViewHelperTest.php:523
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\SvgImageViewHelperTest\$pathsToProvideInTestInstance
‪array $pathsToProvideInTestInstance
Definition: SvgImageViewHelperTest.php:31
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\SvgImageViewHelperTest\renderReturnsExpectedMarkup
‪renderReturnsExpectedMarkup(string $template, string $expected, string|null $cropResult, bool $expectProcessedFile=true)
Definition: SvgImageViewHelperTest.php:492
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers
‪$dir
‪$dir
Definition: validateRstFiles.php:257
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\SvgImageViewHelperTest\setUp
‪setUp()
Definition: SvgImageViewHelperTest.php:43
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\SvgImageViewHelperTest\$additionalFoldersToCreate
‪array $additionalFoldersToCreate
Definition: SvgImageViewHelperTest.php:39
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory
Definition: RenderingContextFactory.php:51
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\SvgImageViewHelperTest\renderReturnsExpectedMarkupDataProvider
‪static renderReturnsExpectedMarkupDataProvider()
Definition: SvgImageViewHelperTest.php:51