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