2 declare(strict_types = 1);
18 use TYPO3\CMS\Core\Package\PackageManager;
31 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
52 protected function setUp()
55 $packageManagerMock = $this->getMockBuilder(PackageManager::class)
56 ->disableOriginalConstructor()
58 $templateService = $this->getMockBuilder(TemplateService::class)
59 ->setConstructorArgs([
null, $packageManagerMock])
60 ->setMethods([
'getFileName',
'linkData'])
62 $tsfe = $this->getMockBuilder(TypoScriptFrontendController::class)
63 ->setMethods([
'dummy'])
64 ->disableOriginalConstructor()
66 $tsfe->tmpl = $templateService;
69 $contentObjectRenderer->setContentObjectClassMap([
70 'FILES' => FilesContentObject::class,
71 'TEXT' => TextContentObject::class,
73 $this->subject = $this->getMockBuilder(FilesContentObject::class)
74 ->setMethods([
'getFileCollector'])
75 ->setConstructorArgs([$contentObjectRenderer])
85 'One file reference' => [
88 'renderObj' =>
'TEXT',
90 'data' =>
'file:current:name',
96 'One file reference with begin higher than allowed' => [
100 'renderObj' =>
'TEXT',
102 'data' =>
'file:current:name',
103 'wrap' =>
'<p>|</p>',
108 'One file reference with maxItems higher than allowed' => [
112 'renderObj' =>
'TEXT',
114 'data' =>
'file:current:name',
115 'wrap' =>
'<p>|</p>',
120 'Multiple file references' => [
122 'references' =>
'1,2,3',
123 'renderObj' =>
'TEXT',
125 'data' =>
'file:current:name',
126 'wrap' =>
'<p>|</p>',
129 '<p>File 1</p><p>File 2</p><p>File 3</p>',
131 'Multiple file references with begin' => [
133 'references' =>
'1,2,3',
135 'renderObj' =>
'TEXT',
137 'data' =>
'file:current:name',
138 'wrap' =>
'<p>|</p>',
141 '<p>File 2</p><p>File 3</p>',
143 'Multiple file references with negative begin' => [
145 'references' =>
'1,2,3',
147 'renderObj' =>
'TEXT',
149 'data' =>
'file:current:name',
150 'wrap' =>
'<p>|</p>',
153 '<p>File 1</p><p>File 2</p><p>File 3</p>',
155 'Multiple file references with maxItems' => [
157 'references' =>
'1,2,3',
159 'renderObj' =>
'TEXT',
161 'data' =>
'file:current:name',
162 'wrap' =>
'<p>|</p>',
165 '<p>File 1</p><p>File 2</p>',
167 'Multiple file references with negative maxItems' => [
169 'references' =>
'1,2,3',
171 'renderObj' =>
'TEXT',
173 'data' =>
'file:current:name',
174 'wrap' =>
'<p>|</p>',
179 'Multiple file references with begin and maxItems' => [
181 'references' =>
'1,2,3',
184 'renderObj' =>
'TEXT',
186 'data' =>
'file:current:name',
187 'wrap' =>
'<p>|</p>',
192 'Multiple file references unsorted' => [
194 'references' =>
'1,3,2',
195 'renderObj' =>
'TEXT',
197 'data' =>
'file:current:name',
198 'wrap' =>
'<p>|</p>',
201 '<p>File 1</p><p>File 3</p><p>File 2</p>',
203 'Multiple file references sorted by name' => [
205 'references' =>
'3,1,2',
207 'renderObj' =>
'TEXT',
209 'data' =>
'file:current:name',
210 'wrap' =>
'<p>|</p>',
213 '<p>File 1</p><p>File 2</p><p>File 3</p>',
226 $fileReferenceMap = [];
227 for ($i = 1; $i < 4; $i++) {
228 $fileReference = $this->createMock(FileReference::class);
229 $fileReference->expects($this->any())
231 ->will($this->returnValue(
'File ' . $i));
232 $fileReference->expects($this->any())
233 ->method(
'hasProperty')
235 ->will($this->returnValue(
true));
236 $fileReference->expects($this->any())
237 ->method(
'getProperty')
239 ->will($this->returnValue(
'File ' . $i));
241 $fileReferenceMap[] = [$i, $fileReference];
244 $fileRepository = $this->createMock(\
TYPO3\CMS\Core\Resource\FileRepository::class);
245 $fileRepository->expects($this->any())
246 ->method(
'findFileReferenceByUid')
247 ->will($this->returnValueMap($fileReferenceMap));
248 $fileCollector = $this->getMockBuilder(FileCollector::class)
249 ->setMethods([
'getFileRepository'])
251 $fileCollector->expects($this->any())
252 ->method(
'getFileRepository')
253 ->will($this->returnValue($fileRepository));
255 $this->subject->expects($this->any())
256 ->method(
'getFileCollector')
257 ->will($this->returnValue($fileCollector));
259 $this->assertSame($expected, $this->subject->render($configuration));
271 'renderObj' =>
'TEXT',
273 'data' =>
'file:current:name',
274 'wrap' =>
'<p>|</p>',
279 'One file with begin higher than allowed' => [
283 'renderObj' =>
'TEXT',
285 'data' =>
'file:current:name',
286 'wrap' =>
'<p>|</p>',
291 'One file with maxItems higher than allowed' => [
295 'renderObj' =>
'TEXT',
297 'data' =>
'file:current:name',
298 'wrap' =>
'<p>|</p>',
303 'Multiple files' => [
306 'renderObj' =>
'TEXT',
308 'data' =>
'file:current:name',
309 'wrap' =>
'<p>|</p>',
312 '<p>File 1</p><p>File 2</p><p>File 3</p>',
314 'Multiple files with begin' => [
318 'renderObj' =>
'TEXT',
320 'data' =>
'file:current:name',
321 'wrap' =>
'<p>|</p>',
324 '<p>File 2</p><p>File 3</p>',
326 'Multiple files with negative begin' => [
330 'renderObj' =>
'TEXT',
332 'data' =>
'file:current:name',
333 'wrap' =>
'<p>|</p>',
336 '<p>File 1</p><p>File 2</p><p>File 3</p>',
338 'Multiple files with maxItems' => [
342 'renderObj' =>
'TEXT',
344 'data' =>
'file:current:name',
345 'wrap' =>
'<p>|</p>',
348 '<p>File 1</p><p>File 2</p>',
350 'Multiple files with negative maxItems' => [
354 'renderObj' =>
'TEXT',
356 'data' =>
'file:current:name',
357 'wrap' =>
'<p>|</p>',
362 'Multiple files with begin and maxItems' => [
367 'renderObj' =>
'TEXT',
369 'data' =>
'file:current:name',
370 'wrap' =>
'<p>|</p>',
375 'Multiple files unsorted' => [
378 'renderObj' =>
'TEXT',
380 'data' =>
'file:current:name',
381 'wrap' =>
'<p>|</p>',
384 '<p>File 1</p><p>File 3</p><p>File 2</p>',
386 'Multiple files sorted by name' => [
390 'renderObj' =>
'TEXT',
392 'data' =>
'file:current:name',
393 'wrap' =>
'<p>|</p>',
396 '<p>File 1</p><p>File 2</p><p>File 3</p>',
410 for ($i = 1; $i < 4; $i++) {
411 $file = $this->createMock(File::class);
412 $file->expects($this->any())
414 ->will($this->returnValue(
'File ' . $i));
415 $file->expects($this->any())
416 ->method(
'hasProperty')
418 ->will($this->returnValue(
true));
419 $file->expects($this->any())
420 ->method(
'getProperty')
422 ->will($this->returnValue(
'File ' . $i));
424 $fileMap[] = [$i, [], $file];
427 $resourceFactory = $this->createMock(ResourceFactory::class);
428 $resourceFactory->expects($this->any())
429 ->method(
'getFileObject')
430 ->will($this->returnValueMap($fileMap));
431 $fileCollector = $this->getMockBuilder(FileCollector::class)
432 ->setMethods([
'getResourceFactory'])
434 $fileCollector->expects($this->any())
435 ->method(
'getResourceFactory')
436 ->will($this->returnValue($resourceFactory));
438 $this->subject->expects($this->any())
439 ->method(
'getFileCollector')
440 ->will($this->returnValue($fileCollector));
442 $this->assertSame($expected, $this->subject->render($configuration));
451 'One collection' => [
453 'collections' =>
'1',
454 'renderObj' =>
'TEXT',
456 'data' =>
'file:current:name',
457 'wrap' =>
'<p>|</p>',
460 '<p>File 1</p><p>File 2</p><p>File 3</p>',
462 'One collection with begin' => [
464 'collections' =>
'1',
466 'renderObj' =>
'TEXT',
468 'data' =>
'file:current:name',
469 'wrap' =>
'<p>|</p>',
472 '<p>File 2</p><p>File 3</p>',
474 'One collection with begin higher than allowed' => [
476 'collections' =>
'1',
478 'renderObj' =>
'TEXT',
480 'data' =>
'file:current:name',
481 'wrap' =>
'<p>|</p>',
486 'One collection with maxItems' => [
488 'collections' =>
'1',
490 'renderObj' =>
'TEXT',
492 'data' =>
'file:current:name',
493 'wrap' =>
'<p>|</p>',
496 '<p>File 1</p><p>File 2</p>',
498 'One collection with maxItems higher than allowed' => [
500 'collections' =>
'1',
502 'renderObj' =>
'TEXT',
504 'data' =>
'file:current:name',
505 'wrap' =>
'<p>|</p>',
508 '<p>File 1</p><p>File 2</p><p>File 3</p>',
510 'One collections with begin and maxItems' => [
512 'collections' =>
'1',
515 'renderObj' =>
'TEXT',
517 'data' =>
'file:current:name',
518 'wrap' =>
'<p>|</p>',
523 'Multiple collections' => [
525 'collections' =>
'1,2,3',
526 'renderObj' =>
'TEXT',
528 'data' =>
'file:current:name',
529 'wrap' =>
'<p>|</p>',
532 '<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>',
534 'Multiple collections with begin' => [
536 'collections' =>
'1,2,3',
538 'renderObj' =>
'TEXT',
540 'data' =>
'file:current:name',
541 'wrap' =>
'<p>|</p>',
544 '<p>File 4</p><p>File 5</p><p>File 6</p><p>File 7</p><p>File 8</p><p>File 9</p>',
546 'Multiple collections with negative begin' => [
548 'collections' =>
'1,2,3',
550 'renderObj' =>
'TEXT',
552 'data' =>
'file:current:name',
553 'wrap' =>
'<p>|</p>',
556 '<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>',
558 'Multiple collections with maxItems' => [
560 'collections' =>
'1,2,3',
562 'renderObj' =>
'TEXT',
564 'data' =>
'file:current:name',
565 'wrap' =>
'<p>|</p>',
568 '<p>File 1</p><p>File 2</p><p>File 3</p><p>File 4</p><p>File 5</p>',
570 'Multiple collections with negative maxItems' => [
572 'collections' =>
'1,2,3',
574 'renderObj' =>
'TEXT',
576 'data' =>
'file:current:name',
577 'wrap' =>
'<p>|</p>',
582 'Multiple collections with begin and maxItems' => [
584 'collections' =>
'1,2,3',
587 'renderObj' =>
'TEXT',
589 'data' =>
'file:current:name',
590 'wrap' =>
'<p>|</p>',
593 '<p>File 5</p><p>File 6</p><p>File 7</p>',
595 'Multiple collections unsorted' => [
597 'collections' =>
'1,3,2',
598 'renderObj' =>
'TEXT',
600 'data' =>
'file:current:name',
601 'wrap' =>
'<p>|</p>',
604 '<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>',
606 'Multiple collections sorted by name' => [
608 'collections' =>
'3,1,2',
610 'renderObj' =>
'TEXT',
612 'data' =>
'file:current:name',
613 'wrap' =>
'<p>|</p>',
616 '<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>',
631 for ($i = 1; $i < 4; $i++) {
632 $fileReferenceArray = [];
633 for ($j = 1; $j < 4; $j++) {
634 $fileReference = $this->createMock(FileReference::class);
635 $fileReference->expects($this->any())
637 ->will($this->returnValue(
'File ' . $fileCount));
638 $fileReference->expects($this->any())
639 ->method(
'hasProperty')
641 ->will($this->returnValue(
true));
642 $fileReference->expects($this->any())
643 ->method(
'getProperty')
645 ->will($this->returnValue(
'File ' . $fileCount));
647 $fileReferenceArray[] = $fileReference;
651 $collection = $this->createMock(StaticFileCollection::class);
652 $collection->expects($this->any())
654 ->will($this->returnValue($fileReferenceArray));
656 $collectionMap[] = [$i, $collection];
659 $collectionRepository = $this->getMockBuilder(FileCollectionRepository::class)->getMock();
660 $collectionRepository->expects($this->any())
661 ->method(
'findByUid')
662 ->will($this->returnValueMap($collectionMap));
663 $fileCollector = $this->getMockBuilder(FileCollector::class)
664 ->setMethods([
'getFileCollectionRepository'])
666 $fileCollector->expects($this->any())
667 ->method(
'getFileCollectionRepository')
668 ->will($this->returnValue($collectionRepository));
669 $this->subject->expects($this->any())
670 ->method(
'getFileCollector')
671 ->will($this->returnValue($fileCollector));
673 $this->assertSame($expected, $this->subject->render($configuration));
684 'folders' =>
'1:myfolder/',
685 'renderObj' =>
'TEXT',
687 'data' =>
'file:current:name',
688 'wrap' =>
'<p>|</p>',
691 '<p>File 1</p><p>File 2</p><p>File 3</p>',
693 'One folder with begin' => [
695 'folders' =>
'1:myfolder/',
697 'renderObj' =>
'TEXT',
699 'data' =>
'file:current:name',
700 'wrap' =>
'<p>|</p>',
703 '<p>File 2</p><p>File 3</p>',
705 'One folder with begin higher than allowed' => [
707 'folders' =>
'1:myfolder/',
709 'renderObj' =>
'TEXT',
711 'data' =>
'file:current:name',
712 'wrap' =>
'<p>|</p>',
717 'One folder with maxItems' => [
719 'folders' =>
'1:myfolder/',
721 'renderObj' =>
'TEXT',
723 'data' =>
'file:current:name',
724 'wrap' =>
'<p>|</p>',
727 '<p>File 1</p><p>File 2</p>',
729 'One folder with maxItems higher than allowed' => [
731 'folders' =>
'1:myfolder/',
733 'renderObj' =>
'TEXT',
735 'data' =>
'file:current:name',
736 'wrap' =>
'<p>|</p>',
739 '<p>File 1</p><p>File 2</p><p>File 3</p>',
741 'One folder with begin and maxItems' => [
743 'folders' =>
'1:myfolder/',
746 'renderObj' =>
'TEXT',
748 'data' =>
'file:current:name',
749 'wrap' =>
'<p>|</p>',
754 'Multiple folders' => [
756 'folders' =>
'1:myfolder/,2:myfolder/,3:myfolder/',
757 'renderObj' =>
'TEXT',
759 'data' =>
'file:current:name',
760 'wrap' =>
'<p>|</p>',
763 '<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>',
765 'Multiple folders with begin' => [
767 'folders' =>
'1:myfolder/,2:myfolder/,3:myfolder/',
769 'renderObj' =>
'TEXT',
771 'data' =>
'file:current:name',
772 'wrap' =>
'<p>|</p>',
775 '<p>File 4</p><p>File 5</p><p>File 6</p><p>File 7</p><p>File 8</p><p>File 9</p>',
777 'Multiple folders with negative begin' => [
779 'folders' =>
'1:myfolder/,2:myfolder/,3:myfolder/',
781 'renderObj' =>
'TEXT',
783 'data' =>
'file:current:name',
784 'wrap' =>
'<p>|</p>',
787 '<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>',
789 'Multiple folders with maxItems' => [
791 'folders' =>
'1:myfolder/,2:myfolder/,3:myfolder/',
793 'renderObj' =>
'TEXT',
795 'data' =>
'file:current:name',
796 'wrap' =>
'<p>|</p>',
799 '<p>File 1</p><p>File 2</p><p>File 3</p><p>File 4</p><p>File 5</p>',
801 'Multiple folders with negative maxItems' => [
803 'folders' =>
'1:myfolder/,2:myfolder/,3:myfolder/',
805 'renderObj' =>
'TEXT',
807 'data' =>
'file:current:name',
808 'wrap' =>
'<p>|</p>',
813 'Multiple folders with begin and maxItems' => [
815 'folders' =>
'1:myfolder/,2:myfolder/,3:myfolder/',
818 'renderObj' =>
'TEXT',
820 'data' =>
'file:current:name',
821 'wrap' =>
'<p>|</p>',
824 '<p>File 5</p><p>File 6</p><p>File 7</p>',
826 'Multiple folders unsorted' => [
828 'folders' =>
'1:myfolder/,3:myfolder/,2:myfolder/',
829 'renderObj' =>
'TEXT',
831 'data' =>
'file:current:name',
832 'wrap' =>
'<p>|</p>',
835 '<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>',
837 'Multiple folders sorted by name' => [
839 'folders' =>
'3:myfolder/,1:myfolder/,2:myfolder/',
841 'renderObj' =>
'TEXT',
843 'data' =>
'file:current:name',
844 'wrap' =>
'<p>|</p>',
847 '<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>',
849 'Multiple folders recursively' => [
851 'folders' =>
'1:myfolder/',
855 'renderObj' =>
'TEXT',
857 'data' =>
'file:current:name',
858 'wrap' =>
'<p>|</p>',
861 '<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>',
864 'Multiple folders recursively, sorted by name' => [
866 'folders' =>
'1:myfolder/',
871 'renderObj' =>
'TEXT',
873 'data' =>
'file:current:name',
874 'wrap' =>
'<p>|</p>',
877 '<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>',
895 $filesArrayForFolder = [];
896 for ($i = 1; $i < 4; $i++) {
897 $filesArrayForFolder[$i] = [];
898 for ($j = 1; $j < 4; $j++) {
899 $file = $this->createMock(File::class);
900 $file->expects($this->any())
902 ->will($this->returnValue(
'File ' . $fileCount));
903 $file->expects($this->any())
904 ->method(
'hasProperty')
906 ->will($this->returnValue(
true));
907 $file->expects($this->any())
908 ->method(
'getProperty')
910 ->will($this->returnValue(
'File ' . $fileCount));
912 $filesArrayForFolder[$i][] = $file;
916 $folder = $this->createMock(Folder::class);
920 $folders[$i] = $folder;
921 $folderMap[$i] = [
'1:myfolder/mysubfolder-' . $i .
'/', $folder];
923 $folder->expects($this->any())
924 ->method(
'getSubfolders')
925 ->will($this->returnValue($folders));
926 $folderMap[$i] = [
'1:myfolder/', $folder];
929 $folderMap[$i] = [$i .
':myfolder/', $folder];
932 foreach ($folderMap as $i => $folderMapInfo) {
933 if ($i < 3 || !$recursive) {
934 $folderMapInfo[1]->expects($this->any())
936 ->will($this->returnValue($filesArrayForFolder[$i]));
938 $recursiveFiles = array_merge(
939 $filesArrayForFolder[3],
940 $filesArrayForFolder[1],
941 $filesArrayForFolder[2]
943 $folderMapInfo[1]->expects($this->any())
945 ->will($this->returnValue($recursiveFiles));
949 $resourceFactory = $this->createMock(ResourceFactory::class);
950 $resourceFactory->expects($this->any())
951 ->method(
'getFolderObjectFromCombinedIdentifier')
952 ->will($this->returnValueMap($folderMap));
953 $fileCollector = $this->getMockBuilder(FileCollector::class)
954 ->setMethods([
'getResourceFactory'])
956 $fileCollector->expects($this->any())
957 ->method(
'getResourceFactory')
958 ->will($this->returnValue($resourceFactory));
960 $this->subject->expects($this->any())
961 ->method(
'getFileCollector')
962 ->will($this->returnValue($fileCollector));
964 $this->assertSame($expected, $this->subject->render($configuration));