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