‪TYPO3CMS  9.5
GalleryProcessorTest.php
Go to the documentation of this file.
1 <?php
2 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  */
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪GalleryProcessorTest extends UnitTestCase
27 {
31  protected ‪$contentObjectRenderer;
32 
36  protected function ‪setUp()
37  {
38  $this->contentObjectRenderer = $this->getMockBuilder(ContentObjectRenderer::class)
39  ->setMethods(['dummy'])
40  ->getMock();
41  }
42 
47  {
48  $this->expectException(ContentRenderingException::class);
49  $this->expectExceptionCode(1436809789);
50  $processor = new ‪GalleryProcessor();
51  $processor->process(
52  $this->contentObjectRenderer,
53  [],
54  [],
55  []
56  );
57  }
58 
62  public function ‪galleryPositionDataProvider()
63  {
64  return [
65  'Default: horizontal above' => [
66  [],
67  [
68  'horizontal' => 'center',
69  'vertical' => 'above',
70  'noWrap' => false
71  ]
72  ],
73  'right above' => [
74  ['mediaOrientation' => 1],
75  [
76  'horizontal' => 'right',
77  'vertical' => 'above',
78  'noWrap' => false
79  ]
80  ],
81  'left above' => [
82  ['mediaOrientation' => 2],
83  [
84  'horizontal' => 'left',
85  'vertical' => 'above',
86  'noWrap' => false
87  ]
88  ],
89  'center below' => [
90  ['mediaOrientation' => 8],
91  [
92  'horizontal' => 'center',
93  'vertical' => 'below',
94  'noWrap' => false
95  ]
96  ],
97  'right below' => [
98  ['mediaOrientation' => 9],
99  [
100  'horizontal' => 'right',
101  'vertical' => 'below',
102  'noWrap' => false
103  ]
104  ],
105  'left below' => [
106  ['mediaOrientation' => 10],
107  [
108  'horizontal' => 'left',
109  'vertical' => 'below',
110  'noWrap' => false
111  ]
112  ],
113  'right intext' => [
114  ['mediaOrientation' => 17],
115  [
116  'horizontal' => 'right',
117  'vertical' => 'intext',
118  'noWrap' => false
119  ]
120  ],
121  'left intext' => [
122  ['mediaOrientation' => 18],
123  [
124  'horizontal' => 'left',
125  'vertical' => 'intext',
126  'noWrap' => false
127  ]
128  ],
129  'right intext no wrap' => [
130  ['mediaOrientation' => 25],
131  [
132  'horizontal' => 'right',
133  'vertical' => 'intext',
134  'noWrap' => true
135  ]
136  ],
137  'left intext no wrap' => [
138  ['mediaOrientation' => 26],
139  [
140  'horizontal' => 'left',
141  'vertical' => 'intext',
142  'noWrap' => true
143  ]
144  ],
145 
146  ];
147  }
148 
153  public function ‪galleryPositionTest($processorConfiguration, $expected)
154  {
155  $processor = new ‪GalleryProcessor();
156  $processedData = $processor->process(
157  $this->contentObjectRenderer,
158  [],
159  $processorConfiguration,
160  ['files' => []]
161  );
162 
163  $this->assertEquals($expected, $processedData['gallery']['position']);
164  }
165 
169  public function ‪maxGalleryWidthTest()
170  {
171  $processor = new ‪GalleryProcessor();
172  $processedData = $processor->process(
173  $this->contentObjectRenderer,
174  [],
175  ['maxGalleryWidth' => 200, 'maxGalleryWidthInText' => 100],
176  ['files' => []]
177  );
178 
179  $this->assertEquals(200, $processedData['gallery']['width']);
180  }
181 
185  public function ‪maxGalleryWidthWhenInTextTest()
186  {
187  $processor = new ‪GalleryProcessor();
188  $processedData = $processor->process(
189  $this->contentObjectRenderer,
190  [],
191  ['maxGalleryWidth' => 200, 'maxGalleryWidthInText' => 100, 'mediaOrientation' => 26],
192  ['files' => []]
193  );
194 
195  $this->assertEquals(100, $processedData['gallery']['width']);
196  }
197 
202  public function ‪countDataProvider()
203  {
204  return [
205  'Default settings with 3 files' => [
206  3,
207  [],
208  [],
209  [
210  'files' => 3,
211  'columns' => 1,
212  'rows' => 3
213  ]
214  ],
215  'NumberOfColumns set by value' => [
216  3,
217  [],
218  ['numberOfColumns' => 2],
219  [
220  'files' => 3,
221  'columns' => 2,
222  'rows' => 2
223  ]
224  ],
225  'NumberOfColumns set in data' => [
226  3,
227  ['imagecols' => 3],
228  [],
229  [
230  'files' => 3,
231  'columns' => 3,
232  'rows' => 1
233  ]
234  ],
235  'NumberOfColumns set in custom data field' => [
236  6,
237  ['my_imagecols' => 4],
238  ['numberOfColumns.' => [
239  'field' => 'my_imagecols'
240  ]],
241  [
242  'files' => 6,
243  'columns' => 4,
244  'rows' => 2
245  ]
246  ]
247  ];
248  }
249 
254  public function ‪countResultTest($numberOfFiles, $data, $processorConfiguration, $expected)
255  {
256  $files = [];
257  for ($i = 0; $i < $numberOfFiles; $i++) {
258  $files[] = $this->createMock(FileReference::class);
259  }
260  $this->contentObjectRenderer->data = $data;
261  $processor = new ‪GalleryProcessor();
262  $processedData = $processor->process(
263  $this->contentObjectRenderer,
264  [],
265  $processorConfiguration,
266  ['files' => $files]
267  );
268 
269  $this->assertEquals($expected, $processedData['gallery']['count']);
270  }
271 
278  {
279  return [
280  'Default settings' => [
281  [
282  [200, 100],
283  [200, 100],
284  [200, 100],
285  ],
286  [],
287  [
288  1 => [
289  1 => ['width' => 200, 'height' => 100]
290  ],
291  2 => [
292  1 => ['width' => 200, 'height' => 100]
293  ],
294  3 => [
295  1 => ['width' => 200, 'height' => 100]
296  ],
297  ]
298  ],
299  'Max width set + number of columns set' => [
300  [
301  [200, 100],
302  [200, 100],
303  [200, 100],
304  ],
305  ['maxGalleryWidth' => 200, 'numberOfColumns' => 2],
306  [
307  1 => [
308  1 => ['width' => 100, 'height' => 50],
309  2 => ['width' => 100, 'height' => 50]
310  ],
311  2 => [
312  1 => ['width' => 100, 'height' => 50],
313  2 => ['width' => null, 'height' => null]
314  ],
315  ]
316  ],
317  'Max width set, number of columns + border (padding) set' => [
318  [
319  [200, 100],
320  [200, 100],
321  [200, 100],
322  ],
323  [
324  'maxGalleryWidth' => 200,
325  'numberOfColumns' => 2,
326  'borderEnabled' => true,
327  'borderPadding' => 4,
328  'borderWidth' => 0,
329  ],
330  [
331  1 => [
332  1 => ['width' => 92, 'height' => 46],
333  2 => ['width' => 92, 'height' => 46]
334  ],
335  2 => [
336  1 => ['width' => 92, 'height' => 46],
337  2 => ['width' => null, 'height' => null]
338  ],
339  ]
340  ],
341  'Max width set, number of columns + border (width) set' => [
342  [
343  [200, 100],
344  [200, 100],
345  [200, 100],
346  ],
347  [
348  'maxGalleryWidth' => 200,
349  'numberOfColumns' => 2,
350  'borderEnabled' => true,
351  'borderPadding' => 0,
352  'borderWidth' => 4,
353  ],
354  [
355  1 => [
356  1 => ['width' => 92, 'height' => 46],
357  2 => ['width' => 92, 'height' => 46]
358  ],
359  2 => [
360  1 => ['width' => 92, 'height' => 46],
361  2 => ['width' => null, 'height' => null]
362  ],
363  ]
364  ],
365  'Max width set, number of columns + border (padding + width) set' => [
366  [
367  [200, 100],
368  [200, 100],
369  [200, 100],
370  ],
371  [
372  'maxGalleryWidth' => 200,
373  'numberOfColumns' => 2,
374  'borderEnabled' => true,
375  'borderPadding' => 1,
376  'borderWidth' => 4,
377  ],
378  [
379  1 => [
380  1 => ['width' => 90, 'height' => 45],
381  2 => ['width' => 90, 'height' => 45]
382  ],
383  2 => [
384  1 => ['width' => 90, 'height' => 45],
385  2 => ['width' => null, 'height' => null]
386  ],
387  ]
388  ],
389  'Equal height set' => [
390  [
391  [200, 100],
392  [200, 300],
393  [100, 50],
394  [2020, 1000],
395  [1000, 1000],
396  ],
397  [
398  'maxGalleryWidth' => 500,
399  'numberOfColumns' => 3,
400  'equalMediaHeight' => 75
401  ],
402  [
403  1 => [
404  1 => ['width' => 150, 'height' => 75],
405  2 => ['width' => 50, 'height' => 75],
406  3 => ['width' => 150, 'height' => 75]
407  ],
408  2 => [
409  1 => ['width' => 151, 'height' => 75],
410  2 => ['width' => 75, 'height' => 75],
411  3 => ['width' => null, 'height' => null]
412  ],
413  ]
414  ],
415  'Equal width set' => [
416  [
417  [200, 100],
418  [200, 300],
419  [100, 50],
420  ],
421  [
422  'maxGalleryWidth' => 200,
423  'numberOfColumns' => 3,
424  'equalMediaWidth' => 75
425  ],
426  [
427  1 => [
428  1 => ['width' => 66, 'height' => 33],
429  2 => ['width' => 66, 'height' => 99],
430  3 => ['width' => 66, 'height' => 33]
431  ],
432  ]
433  ]
434  ];
435  }
436 
441  public function ‪calculateMediaWidthsAndHeightsTest($testFiles, $processorConfiguration, $expected)
442  {
443  $files = [];
444  foreach ($testFiles as $fileConfig) {
445  $fileReference = $this->createMock(FileReference::class);
446  $fileReference->expects($this->any())
447  ->method('getProperty')
448  ->will($this->returnValueMap([
449  ['width', $fileConfig[0]],
450  ['height', $fileConfig[1]]
451  ]));
452  $files[] = $fileReference;
453  }
454 
455  $processor = new ‪GalleryProcessor();
456  $processedData = $processor->process(
457  $this->contentObjectRenderer,
458  [],
459  $processorConfiguration,
460  ['files' => $files]
461  );
462 
463  foreach ($expected as $row => $columns) {
464  $this->assertArrayHasKey($row, $processedData['gallery']['rows'], 'Row exists');
465  foreach ($columns as $column => $dimensions) {
466  $this->assertArrayHasKey($column, $processedData['gallery']['rows'][$row]['columns'], 'Column exists');
467  $this->assertEquals($dimensions, $processedData['gallery']['rows'][$row]['columns'][$column]['dimensions'], 'Dimensions match');
468  }
469  }
470  }
471 }
‪TYPO3\CMS\Core\Resource\FileReference
Definition: FileReference.php:31
‪TYPO3\CMS\Frontend\ContentObject\Exception\ContentRenderingException
Definition: ContentRenderingException.php:22
‪TYPO3\CMS\Frontend\Tests\Unit\Processor
Definition: GalleryProcessorTest.php:3
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:91