TYPO3 CMS  TYPO3_7-6
FilesContentObjectTest.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  */
30 
35 {
39  protected $subject = null;
40 
44  protected $tsfe = null;
45 
49  protected function setUp()
50  {
51  $templateService = $this->getMock(TemplateService::class, ['getFileName', 'linkData']);
52  $this->tsfe = $this->getMock(TypoScriptFrontendController::class, ['dummy'], [], '', false);
53  $this->tsfe->tmpl = $templateService;
54  $this->tsfe->config = [];
55  $this->tsfe->page = [];
56  $sysPageMock = $this->getMock(PageRepository::class, ['getRawRecord']);
57  $this->tsfe->sys_page = $sysPageMock;
58  $GLOBALS['TSFE'] = $this->tsfe;
59  $GLOBALS['TSFE']->csConvObj = new CharsetConverter();
60  $GLOBALS['TSFE']->renderCharset = 'utf-8';
61 
62  $contentObjectRenderer = new ContentObjectRenderer();
63  $contentObjectRenderer->setContentObjectClassMap([
64  'FILES' => FilesContentObject::class,
65  'TEXT' => TextContentObject::class,
66  ]);
67  $this->subject = $this->getMock(FilesContentObject::class, ['getFileCollector'], [$contentObjectRenderer]);
68  }
69 
74  {
75  return [
76  'One file reference' => [
77  [
78  'references' => '1',
79  'renderObj' => 'TEXT',
80  'renderObj.' => [
81  'data' => 'file:current:name',
82  'wrap' => '<p>|</p>',
83  ],
84  ],
85  '<p>File 1</p>',
86  ],
87  'One file reference with begin higher than allowed' => [
88  [
89  'references' => '1',
90  'begin' => '1',
91  'renderObj' => 'TEXT',
92  'renderObj.' => [
93  'data' => 'file:current:name',
94  'wrap' => '<p>|</p>',
95  ],
96  ],
97  '',
98  ],
99  'One file reference with maxItems higher than allowed' => [
100  [
101  'references' => '1',
102  'maxItems' => '2',
103  'renderObj' => 'TEXT',
104  'renderObj.' => [
105  'data' => 'file:current:name',
106  'wrap' => '<p>|</p>',
107  ],
108  ],
109  '<p>File 1</p>',
110  ],
111  'Multiple file references' => [
112  [
113  'references' => '1,2,3',
114  'renderObj' => 'TEXT',
115  'renderObj.' => [
116  'data' => 'file:current:name',
117  'wrap' => '<p>|</p>',
118  ],
119  ],
120  '<p>File 1</p><p>File 2</p><p>File 3</p>',
121  ],
122  'Multiple file references with begin' => [
123  [
124  'references' => '1,2,3',
125  'begin' => '1',
126  'renderObj' => 'TEXT',
127  'renderObj.' => [
128  'data' => 'file:current:name',
129  'wrap' => '<p>|</p>',
130  ],
131  ],
132  '<p>File 2</p><p>File 3</p>',
133  ],
134  'Multiple file references with negative begin' => [
135  [
136  'references' => '1,2,3',
137  'begin' => '-1',
138  'renderObj' => 'TEXT',
139  'renderObj.' => [
140  'data' => 'file:current:name',
141  'wrap' => '<p>|</p>',
142  ],
143  ],
144  '<p>File 1</p><p>File 2</p><p>File 3</p>',
145  ],
146  'Multiple file references with maxItems' => [
147  [
148  'references' => '1,2,3',
149  'maxItems' => '2',
150  'renderObj' => 'TEXT',
151  'renderObj.' => [
152  'data' => 'file:current:name',
153  'wrap' => '<p>|</p>',
154  ],
155  ],
156  '<p>File 1</p><p>File 2</p>',
157  ],
158  'Multiple file references with negative maxItems' => [
159  [
160  'references' => '1,2,3',
161  'maxItems' => '-2',
162  'renderObj' => 'TEXT',
163  'renderObj.' => [
164  'data' => 'file:current:name',
165  'wrap' => '<p>|</p>',
166  ],
167  ],
168  '',
169  ],
170  'Multiple file references with begin and maxItems' => [
171  [
172  'references' => '1,2,3',
173  'begin' => '1',
174  'maxItems' => '1',
175  'renderObj' => 'TEXT',
176  'renderObj.' => [
177  'data' => 'file:current:name',
178  'wrap' => '<p>|</p>',
179  ],
180  ],
181  '<p>File 2</p>',
182  ],
183  'Multiple file references unsorted' => [
184  [
185  'references' => '1,3,2',
186  'renderObj' => 'TEXT',
187  'renderObj.' => [
188  'data' => 'file:current:name',
189  'wrap' => '<p>|</p>',
190  ],
191  ],
192  '<p>File 1</p><p>File 3</p><p>File 2</p>',
193  ],
194  'Multiple file references sorted by name' => [
195  [
196  'references' => '3,1,2',
197  'sorting' => 'name',
198  'renderObj' => 'TEXT',
199  'renderObj.' => [
200  'data' => 'file:current:name',
201  'wrap' => '<p>|</p>',
202  ],
203  ],
204  '<p>File 1</p><p>File 2</p><p>File 3</p>',
205  ],
206  ];
207  }
208 
213  public function renderReturnsFilesForFileReferences($configuration, $expected)
214  {
215  $fileReferenceMap = [];
216  for ($i = 1; $i < 4; $i++) {
217  $fileReference = $this->getMock(FileReference::class, [], [], '', false);
218  $fileReference->expects($this->any())
219  ->method('getName')
220  ->will($this->returnValue('File ' . $i));
221  $fileReference->expects($this->any())
222  ->method('hasProperty')
223  ->with('name')
224  ->will($this->returnValue(true));
225  $fileReference->expects($this->any())
226  ->method('getProperty')
227  ->with('name')
228  ->will($this->returnValue('File ' . $i));
229 
230  $fileReferenceMap[] = [$i, $fileReference];
231  }
232 
233  $fileRepository = $this->getMock(\TYPO3\CMS\Core\Resource\FileRepository::class);
234  $fileRepository->expects($this->any())
235  ->method('findFileReferenceByUid')
236  ->will($this->returnValueMap($fileReferenceMap));
237  $fileCollector = $this->getMock(FileCollector::class, ['getFileRepository']);
238  $fileCollector->expects($this->any())
239  ->method('getFileRepository')
240  ->will($this->returnValue($fileRepository));
241 
242  $this->subject->expects($this->any())
243  ->method('getFileCollector')
244  ->will($this->returnValue($fileCollector));
245 
246  $this->assertSame($expected, $this->subject->render($configuration));
247  }
248 
253  {
254  return [
255  'One file' => [
256  [
257  'files' => '1',
258  'renderObj' => 'TEXT',
259  'renderObj.' => [
260  'data' => 'file:current:name',
261  'wrap' => '<p>|</p>',
262  ],
263  ],
264  '<p>File 1</p>',
265  ],
266  'One file with begin higher than allowed' => [
267  [
268  'files' => '1',
269  'begin' => '1',
270  'renderObj' => 'TEXT',
271  'renderObj.' => [
272  'data' => 'file:current:name',
273  'wrap' => '<p>|</p>',
274  ],
275  ],
276  '',
277  ],
278  'One file with maxItems higher than allowed' => [
279  [
280  'files' => '1',
281  'maxItems' => '2',
282  'renderObj' => 'TEXT',
283  'renderObj.' => [
284  'data' => 'file:current:name',
285  'wrap' => '<p>|</p>',
286  ],
287  ],
288  '<p>File 1</p>',
289  ],
290  'Multiple files' => [
291  [
292  'files' => '1,2,3',
293  'renderObj' => 'TEXT',
294  'renderObj.' => [
295  'data' => 'file:current:name',
296  'wrap' => '<p>|</p>',
297  ],
298  ],
299  '<p>File 1</p><p>File 2</p><p>File 3</p>',
300  ],
301  'Multiple files with begin' => [
302  [
303  'files' => '1,2,3',
304  'begin' => '1',
305  'renderObj' => 'TEXT',
306  'renderObj.' => [
307  'data' => 'file:current:name',
308  'wrap' => '<p>|</p>',
309  ],
310  ],
311  '<p>File 2</p><p>File 3</p>',
312  ],
313  'Multiple files with negative begin' => [
314  [
315  'files' => '1,2,3',
316  'begin' => '-1',
317  'renderObj' => 'TEXT',
318  'renderObj.' => [
319  'data' => 'file:current:name',
320  'wrap' => '<p>|</p>',
321  ],
322  ],
323  '<p>File 1</p><p>File 2</p><p>File 3</p>',
324  ],
325  'Multiple files with maxItems' => [
326  [
327  'files' => '1,2,3',
328  'maxItems' => '2',
329  'renderObj' => 'TEXT',
330  'renderObj.' => [
331  'data' => 'file:current:name',
332  'wrap' => '<p>|</p>',
333  ],
334  ],
335  '<p>File 1</p><p>File 2</p>',
336  ],
337  'Multiple files with negative maxItems' => [
338  [
339  'files' => '1,2,3',
340  'maxItems' => '-2',
341  'renderObj' => 'TEXT',
342  'renderObj.' => [
343  'data' => 'file:current:name',
344  'wrap' => '<p>|</p>',
345  ],
346  ],
347  '',
348  ],
349  'Multiple files with begin and maxItems' => [
350  [
351  'files' => '1,2,3',
352  'begin' => '1',
353  'maxItems' => '1',
354  'renderObj' => 'TEXT',
355  'renderObj.' => [
356  'data' => 'file:current:name',
357  'wrap' => '<p>|</p>',
358  ],
359  ],
360  '<p>File 2</p>',
361  ],
362  'Multiple files unsorted' => [
363  [
364  'files' => '1,3,2',
365  'renderObj' => 'TEXT',
366  'renderObj.' => [
367  'data' => 'file:current:name',
368  'wrap' => '<p>|</p>',
369  ],
370  ],
371  '<p>File 1</p><p>File 3</p><p>File 2</p>',
372  ],
373  'Multiple files sorted by name' => [
374  [
375  'files' => '3,1,2',
376  'sorting' => 'name',
377  'renderObj' => 'TEXT',
378  'renderObj.' => [
379  'data' => 'file:current:name',
380  'wrap' => '<p>|</p>',
381  ],
382  ],
383  '<p>File 1</p><p>File 2</p><p>File 3</p>',
384  ],
385  ];
386  }
387 
392  public function renderReturnsFilesForFiles($configuration, $expected)
393  {
394  $fileMap = [];
395  for ($i = 1; $i < 4; $i++) {
396  $file = $this->getMock(File::class, [], [], '', false);
397  $file->expects($this->any())
398  ->method('getName')
399  ->will($this->returnValue('File ' . $i));
400  $file->expects($this->any())
401  ->method('hasProperty')
402  ->with('name')
403  ->will($this->returnValue(true));
404  $file->expects($this->any())
405  ->method('getProperty')
406  ->with('name')
407  ->will($this->returnValue('File ' . $i));
408 
409  $fileMap[] = [$i, [], $file];
410  }
411 
412  $resourceFactory = $this->getMock(ResourceFactory::class);
413  $resourceFactory->expects($this->any())
414  ->method('getFileObject')
415  ->will($this->returnValueMap($fileMap));
416  $fileCollector = $this->getMock(FileCollector::class, ['getResourceFactory']);
417  $fileCollector->expects($this->any())
418  ->method('getResourceFactory')
419  ->will($this->returnValue($resourceFactory));
420 
421  $this->subject->expects($this->any())
422  ->method('getFileCollector')
423  ->will($this->returnValue($fileCollector));
424 
425  $this->assertSame($expected, $this->subject->render($configuration));
426  }
427 
432  {
433  return [
434  'One collection' => [
435  [
436  'collections' => '1',
437  'renderObj' => 'TEXT',
438  'renderObj.' => [
439  'data' => 'file:current:name',
440  'wrap' => '<p>|</p>',
441  ],
442  ],
443  '<p>File 1</p><p>File 2</p><p>File 3</p>',
444  ],
445  'One collection with begin' => [
446  [
447  'collections' => '1',
448  'begin' => '1',
449  'renderObj' => 'TEXT',
450  'renderObj.' => [
451  'data' => 'file:current:name',
452  'wrap' => '<p>|</p>',
453  ],
454  ],
455  '<p>File 2</p><p>File 3</p>',
456  ],
457  'One collection with begin higher than allowed' => [
458  [
459  'collections' => '1',
460  'begin' => '3',
461  'renderObj' => 'TEXT',
462  'renderObj.' => [
463  'data' => 'file:current:name',
464  'wrap' => '<p>|</p>',
465  ],
466  ],
467  '',
468  ],
469  'One collection with maxItems' => [
470  [
471  'collections' => '1',
472  'maxItems' => '2',
473  'renderObj' => 'TEXT',
474  'renderObj.' => [
475  'data' => 'file:current:name',
476  'wrap' => '<p>|</p>',
477  ],
478  ],
479  '<p>File 1</p><p>File 2</p>',
480  ],
481  'One collection with maxItems higher than allowed' => [
482  [
483  'collections' => '1',
484  'maxItems' => '4',
485  'renderObj' => 'TEXT',
486  'renderObj.' => [
487  'data' => 'file:current:name',
488  'wrap' => '<p>|</p>',
489  ],
490  ],
491  '<p>File 1</p><p>File 2</p><p>File 3</p>',
492  ],
493  'One collections with begin and maxItems' => [
494  [
495  'collections' => '1',
496  'begin' => '1',
497  'maxItems' => '1',
498  'renderObj' => 'TEXT',
499  'renderObj.' => [
500  'data' => 'file:current:name',
501  'wrap' => '<p>|</p>',
502  ],
503  ],
504  '<p>File 2</p>',
505  ],
506  'Multiple collections' => [
507  [
508  'collections' => '1,2,3',
509  'renderObj' => 'TEXT',
510  'renderObj.' => [
511  'data' => 'file:current:name',
512  'wrap' => '<p>|</p>',
513  ],
514  ],
515  '<p>File 1</p><p>File 2</p><p>File 3</p><p>File 4</p><p>File 5</p><p>File 6</p><p>File 7</p><p>File 8</p><p>File 9</p>',
516  ],
517  'Multiple collections with begin' => [
518  [
519  'collections' => '1,2,3',
520  'begin' => '3',
521  'renderObj' => 'TEXT',
522  'renderObj.' => [
523  'data' => 'file:current:name',
524  'wrap' => '<p>|</p>',
525  ],
526  ],
527  '<p>File 4</p><p>File 5</p><p>File 6</p><p>File 7</p><p>File 8</p><p>File 9</p>',
528  ],
529  'Multiple collections with negative begin' => [
530  [
531  'collections' => '1,2,3',
532  'begin' => '-3',
533  'renderObj' => 'TEXT',
534  'renderObj.' => [
535  'data' => 'file:current:name',
536  'wrap' => '<p>|</p>',
537  ],
538  ],
539  '<p>File 1</p><p>File 2</p><p>File 3</p><p>File 4</p><p>File 5</p><p>File 6</p><p>File 7</p><p>File 8</p><p>File 9</p>',
540  ],
541  'Multiple collections with maxItems' => [
542  [
543  'collections' => '1,2,3',
544  'maxItems' => '5',
545  'renderObj' => 'TEXT',
546  'renderObj.' => [
547  'data' => 'file:current:name',
548  'wrap' => '<p>|</p>',
549  ],
550  ],
551  '<p>File 1</p><p>File 2</p><p>File 3</p><p>File 4</p><p>File 5</p>',
552  ],
553  'Multiple collections with negative maxItems' => [
554  [
555  'collections' => '1,2,3',
556  'maxItems' => '-5',
557  'renderObj' => 'TEXT',
558  'renderObj.' => [
559  'data' => 'file:current:name',
560  'wrap' => '<p>|</p>',
561  ],
562  ],
563  '',
564  ],
565  'Multiple collections with begin and maxItems' => [
566  [
567  'collections' => '1,2,3',
568  'begin' => '4',
569  'maxItems' => '3',
570  'renderObj' => 'TEXT',
571  'renderObj.' => [
572  'data' => 'file:current:name',
573  'wrap' => '<p>|</p>',
574  ],
575  ],
576  '<p>File 5</p><p>File 6</p><p>File 7</p>',
577  ],
578  'Multiple collections unsorted' => [
579  [
580  'collections' => '1,3,2',
581  'renderObj' => 'TEXT',
582  'renderObj.' => [
583  'data' => 'file:current:name',
584  'wrap' => '<p>|</p>',
585  ],
586  ],
587  '<p>File 1</p><p>File 2</p><p>File 3</p><p>File 7</p><p>File 8</p><p>File 9</p><p>File 4</p><p>File 5</p><p>File 6</p>',
588  ],
589  'Multiple collections sorted by name' => [
590  [
591  'collections' => '3,1,2',
592  'sorting' => 'name',
593  'renderObj' => 'TEXT',
594  'renderObj.' => [
595  'data' => 'file:current:name',
596  'wrap' => '<p>|</p>',
597  ],
598  ],
599  '<p>File 1</p><p>File 2</p><p>File 3</p><p>File 4</p><p>File 5</p><p>File 6</p><p>File 7</p><p>File 8</p><p>File 9</p>',
600  ],
601  ];
602  }
603 
608  public function renderReturnsFilesForCollections($configuration, $expected)
609  {
610  $collectionMap = [];
611  $fileCount = 1;
612  for ($i = 1; $i < 4; $i++) {
613  $fileReferenceArray = [];
614  for ($j = 1; $j < 4; $j++) {
615  $fileReference = $this->getMock(FileReference::class, [], [], '', false);
616  $fileReference->expects($this->any())
617  ->method('getName')
618  ->will($this->returnValue('File ' . $fileCount));
619  $fileReference->expects($this->any())
620  ->method('hasProperty')
621  ->with('name')
622  ->will($this->returnValue(true));
623  $fileReference->expects($this->any())
624  ->method('getProperty')
625  ->with('name')
626  ->will($this->returnValue('File ' . $fileCount));
627 
628  $fileReferenceArray[] = $fileReference;
629  $fileCount++;
630  }
631 
632  $collection = $this->getMock(StaticFileCollection::class, [], [], '', false);
633  $collection->expects($this->any())
634  ->method('getItems')
635  ->will($this->returnValue($fileReferenceArray));
636 
637  $collectionMap[] = [$i, $collection];
638  }
639 
640  $collectionRepository = $this->getMock(FileCollectionRepository::class);
641  $collectionRepository->expects($this->any())
642  ->method('findByUid')
643  ->will($this->returnValueMap($collectionMap));
644  $fileCollector = $this->getMock(FileCollector::class, ['getFileCollectionRepository']);
645  $fileCollector->expects($this->any())
646  ->method('getFileCollectionRepository')
647  ->will($this->returnValue($collectionRepository));
648  $this->subject->expects($this->any())
649  ->method('getFileCollector')
650  ->will($this->returnValue($fileCollector));
651 
652  $this->assertSame($expected, $this->subject->render($configuration));
653  }
654 
659  {
660  return [
661  'One folder' => [
662  [
663  'folders' => '1:myfolder/',
664  'renderObj' => 'TEXT',
665  'renderObj.' => [
666  'data' => 'file:current:name',
667  'wrap' => '<p>|</p>',
668  ],
669  ],
670  '<p>File 1</p><p>File 2</p><p>File 3</p>',
671  ],
672  'One folder with begin' => [
673  [
674  'folders' => '1:myfolder/',
675  'begin' => '1',
676  'renderObj' => 'TEXT',
677  'renderObj.' => [
678  'data' => 'file:current:name',
679  'wrap' => '<p>|</p>',
680  ],
681  ],
682  '<p>File 2</p><p>File 3</p>',
683  ],
684  'One folder with begin higher than allowed' => [
685  [
686  'folders' => '1:myfolder/',
687  'begin' => '3',
688  'renderObj' => 'TEXT',
689  'renderObj.' => [
690  'data' => 'file:current:name',
691  'wrap' => '<p>|</p>',
692  ],
693  ],
694  '',
695  ],
696  'One folder with maxItems' => [
697  [
698  'folders' => '1:myfolder/',
699  'maxItems' => '2',
700  'renderObj' => 'TEXT',
701  'renderObj.' => [
702  'data' => 'file:current:name',
703  'wrap' => '<p>|</p>',
704  ],
705  ],
706  '<p>File 1</p><p>File 2</p>',
707  ],
708  'One folder with maxItems higher than allowed' => [
709  [
710  'folders' => '1:myfolder/',
711  'maxItems' => '4',
712  'renderObj' => 'TEXT',
713  'renderObj.' => [
714  'data' => 'file:current:name',
715  'wrap' => '<p>|</p>',
716  ],
717  ],
718  '<p>File 1</p><p>File 2</p><p>File 3</p>',
719  ],
720  'One folder with begin and maxItems' => [
721  [
722  'folders' => '1:myfolder/',
723  'begin' => '1',
724  'maxItems' => '1',
725  'renderObj' => 'TEXT',
726  'renderObj.' => [
727  'data' => 'file:current:name',
728  'wrap' => '<p>|</p>',
729  ],
730  ],
731  '<p>File 2</p>',
732  ],
733  'Multiple folders' => [
734  [
735  'folders' => '1:myfolder/,2:myfolder/,3:myfolder/',
736  'renderObj' => 'TEXT',
737  'renderObj.' => [
738  'data' => 'file:current:name',
739  'wrap' => '<p>|</p>',
740  ],
741  ],
742  '<p>File 1</p><p>File 2</p><p>File 3</p><p>File 4</p><p>File 5</p><p>File 6</p><p>File 7</p><p>File 8</p><p>File 9</p>',
743  ],
744  'Multiple folders with begin' => [
745  [
746  'folders' => '1:myfolder/,2:myfolder/,3:myfolder/',
747  'begin' => '3',
748  'renderObj' => 'TEXT',
749  'renderObj.' => [
750  'data' => 'file:current:name',
751  'wrap' => '<p>|</p>',
752  ],
753  ],
754  '<p>File 4</p><p>File 5</p><p>File 6</p><p>File 7</p><p>File 8</p><p>File 9</p>',
755  ],
756  'Multiple folders with negative begin' => [
757  [
758  'folders' => '1:myfolder/,2:myfolder/,3:myfolder/',
759  'begin' => '-3',
760  'renderObj' => 'TEXT',
761  'renderObj.' => [
762  'data' => 'file:current:name',
763  'wrap' => '<p>|</p>',
764  ],
765  ],
766  '<p>File 1</p><p>File 2</p><p>File 3</p><p>File 4</p><p>File 5</p><p>File 6</p><p>File 7</p><p>File 8</p><p>File 9</p>',
767  ],
768  'Multiple folders with maxItems' => [
769  [
770  'folders' => '1:myfolder/,2:myfolder/,3:myfolder/',
771  'maxItems' => '5',
772  'renderObj' => 'TEXT',
773  'renderObj.' => [
774  'data' => 'file:current:name',
775  'wrap' => '<p>|</p>',
776  ],
777  ],
778  '<p>File 1</p><p>File 2</p><p>File 3</p><p>File 4</p><p>File 5</p>',
779  ],
780  'Multiple folders with negative maxItems' => [
781  [
782  'folders' => '1:myfolder/,2:myfolder/,3:myfolder/',
783  'maxItems' => '-5',
784  'renderObj' => 'TEXT',
785  'renderObj.' => [
786  'data' => 'file:current:name',
787  'wrap' => '<p>|</p>',
788  ],
789  ],
790  '',
791  ],
792  'Multiple folders with begin and maxItems' => [
793  [
794  'folders' => '1:myfolder/,2:myfolder/,3:myfolder/',
795  'begin' => '4',
796  'maxItems' => '3',
797  'renderObj' => 'TEXT',
798  'renderObj.' => [
799  'data' => 'file:current:name',
800  'wrap' => '<p>|</p>',
801  ],
802  ],
803  '<p>File 5</p><p>File 6</p><p>File 7</p>',
804  ],
805  'Multiple folders unsorted' => [
806  [
807  'folders' => '1:myfolder/,3:myfolder/,2:myfolder/',
808  'renderObj' => 'TEXT',
809  'renderObj.' => [
810  'data' => 'file:current:name',
811  'wrap' => '<p>|</p>',
812  ],
813  ],
814  '<p>File 1</p><p>File 2</p><p>File 3</p><p>File 7</p><p>File 8</p><p>File 9</p><p>File 4</p><p>File 5</p><p>File 6</p>',
815  ],
816  'Multiple folders sorted by name' => [
817  [
818  'folders' => '3:myfolder/,1:myfolder/,2:myfolder/',
819  'sorting' => 'name',
820  'renderObj' => 'TEXT',
821  'renderObj.' => [
822  'data' => 'file:current:name',
823  'wrap' => '<p>|</p>',
824  ],
825  ],
826  '<p>File 1</p><p>File 2</p><p>File 3</p><p>File 4</p><p>File 5</p><p>File 6</p><p>File 7</p><p>File 8</p><p>File 9</p>',
827  ],
828  'Multiple folders recursively' => [
829  [
830  'folders' => '1:myfolder/',
831  'folders.' => [
832  'recursive' => '1'
833  ],
834  'renderObj' => 'TEXT',
835  'renderObj.' => [
836  'data' => 'file:current:name',
837  'wrap' => '<p>|</p>',
838  ],
839  ],
840  '<p>File 7</p><p>File 8</p><p>File 9</p><p>File 1</p><p>File 2</p><p>File 3</p><p>File 4</p><p>File 5</p><p>File 6</p>',
841  true
842  ],
843  'Multiple folders recursively, sorted by name' => [
844  [
845  'folders' => '1:myfolder/',
846  'folders.' => [
847  'recursive' => '1'
848  ],
849  'sorting' => 'name',
850  'renderObj' => 'TEXT',
851  'renderObj.' => [
852  'data' => 'file:current:name',
853  'wrap' => '<p>|</p>',
854  ],
855  ],
856  '<p>File 1</p><p>File 2</p><p>File 3</p><p>File 4</p><p>File 5</p><p>File 6</p><p>File 7</p><p>File 8</p><p>File 9</p>',
857  true
858  ],
859  ];
860  }
861 
866  public function renderReturnsFilesForFolders($configuration, $expected, $recursive = false)
867  {
868  $folderMap = [];
869  $folders = [];
870  $fileCount = 1;
871  $filesArrayForFolder = [];
872  for ($i = 1; $i < 4; $i++) {
873  $filesArrayForFolder[$i] = [];
874  for ($j = 1; $j < 4; $j++) {
875  $file = $this->getMock(File::class, [], [], '', false);
876  $file->expects($this->any())
877  ->method('getName')
878  ->will($this->returnValue('File ' . $fileCount));
879  $file->expects($this->any())
880  ->method('hasProperty')
881  ->with('name')
882  ->will($this->returnValue(true));
883  $file->expects($this->any())
884  ->method('getProperty')
885  ->with('name')
886  ->will($this->returnValue('File ' . $fileCount));
887 
888  $filesArrayForFolder[$i][] = $file;
889  $fileCount++;
890  }
891 
892  $folder = $this->getMock(Folder::class, [], [], '', false);
893 
894  if ($recursive) {
895  if ($i < 3) {
896  $folders[$i] = $folder;
897  $folderMap[$i] = ['1:myfolder/mysubfolder-' . $i . '/', $folder];
898  } else {
899  $folder->expects($this->any())
900  ->method('getSubfolders')
901  ->will($this->returnValue($folders));
902  $folderMap[$i] = ['1:myfolder/', $folder];
903  }
904  } else {
905  $folderMap[$i] = [$i . ':myfolder/', $folder];
906  }
907  }
908  foreach ($folderMap as $i => $folderMapInfo) {
909  if ($i < 3 || !$recursive) {
910  $folderMapInfo[1]->expects($this->any())
911  ->method('getFiles')
912  ->will($this->returnValue($filesArrayForFolder[$i]));
913  } else {
914  $recursiveFiles = array_merge($filesArrayForFolder[3], $filesArrayForFolder[1], $filesArrayForFolder[2]);
915  $folderMapInfo[1]->expects($this->any())
916  ->method('getFiles')
917  ->will($this->returnValue($recursiveFiles));
918  }
919  }
920 
921  $resourceFactory = $this->getMock(ResourceFactory::class);
922  $resourceFactory->expects($this->any())
923  ->method('getFolderObjectFromCombinedIdentifier')
924  ->will($this->returnValueMap($folderMap));
925  $fileCollector = $this->getMock(FileCollector::class, ['getResourceFactory']);
926  $fileCollector->expects($this->any())
927  ->method('getResourceFactory')
928  ->will($this->returnValue($resourceFactory));
929 
930  $this->subject->expects($this->any())
931  ->method('getFileCollector')
932  ->will($this->returnValue($fileCollector));
933 
934  $this->assertSame($expected, $this->subject->render($configuration));
935  }
936 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
renderReturnsFilesForFolders($configuration, $expected, $recursive=false)