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