2 namespace TYPO3\CMS\Frontend\Tests\Unit\ContentObject;
51 $templateService = $this->getMock(TemplateService::class, array(
'getFileName',
'linkData'));
52 $this->tsfe = $this->getMock(TypoScriptFrontendController::class, array(
'dummy'), array(),
'',
false);
53 $this->tsfe->tmpl = $templateService;
54 $this->tsfe->config = array();
55 $this->tsfe->page = array();
56 $sysPageMock = $this->getMock(PageRepository::class, array(
'getRawRecord'));
57 $this->tsfe->sys_page = $sysPageMock;
60 $GLOBALS[
'TSFE']->renderCharset =
'utf-8';
63 $contentObjectRenderer->setContentObjectClassMap(array(
64 'FILES' => FilesContentObject::class,
65 'TEXT' => TextContentObject::class,
67 $this->subject = $this->getMock(FilesContentObject::class, array(
'getFileCollector'), array($contentObjectRenderer));
76 'One file reference' => array(
79 'renderObj' =>
'TEXT',
80 'renderObj.' => array(
81 'data' =>
'file:current:name',
87 'One file reference with begin higher than allowed' => array(
91 'renderObj' =>
'TEXT',
92 'renderObj.' => array(
93 'data' =>
'file:current:name',
99 'One file reference with maxItems higher than allowed' => array(
103 'renderObj' =>
'TEXT',
104 'renderObj.' => array(
105 'data' =>
'file:current:name',
106 'wrap' =>
'<p>|</p>',
111 'Multiple file references' => array(
113 'references' =>
'1,2,3',
114 'renderObj' =>
'TEXT',
115 'renderObj.' => array(
116 'data' =>
'file:current:name',
117 'wrap' =>
'<p>|</p>',
120 '<p>File 1</p><p>File 2</p><p>File 3</p>',
122 'Multiple file references with begin' => array(
124 'references' =>
'1,2,3',
126 'renderObj' =>
'TEXT',
127 'renderObj.' => array(
128 'data' =>
'file:current:name',
129 'wrap' =>
'<p>|</p>',
132 '<p>File 2</p><p>File 3</p>',
134 'Multiple file references with negative begin' => array(
136 'references' =>
'1,2,3',
138 'renderObj' =>
'TEXT',
139 'renderObj.' => array(
140 'data' =>
'file:current:name',
141 'wrap' =>
'<p>|</p>',
144 '<p>File 1</p><p>File 2</p><p>File 3</p>',
146 'Multiple file references with maxItems' => array(
148 'references' =>
'1,2,3',
150 'renderObj' =>
'TEXT',
151 'renderObj.' => array(
152 'data' =>
'file:current:name',
153 'wrap' =>
'<p>|</p>',
156 '<p>File 1</p><p>File 2</p>',
158 'Multiple file references with negative maxItems' => array(
160 'references' =>
'1,2,3',
162 'renderObj' =>
'TEXT',
163 'renderObj.' => array(
164 'data' =>
'file:current:name',
165 'wrap' =>
'<p>|</p>',
170 'Multiple file references with begin and maxItems' => array(
172 'references' =>
'1,2,3',
175 'renderObj' =>
'TEXT',
176 'renderObj.' => array(
177 'data' =>
'file:current:name',
178 'wrap' =>
'<p>|</p>',
183 'Multiple file references unsorted' => array(
185 'references' =>
'1,3,2',
186 'renderObj' =>
'TEXT',
187 'renderObj.' => array(
188 'data' =>
'file:current:name',
189 'wrap' =>
'<p>|</p>',
192 '<p>File 1</p><p>File 3</p><p>File 2</p>',
194 'Multiple file references sorted by name' => array(
196 'references' =>
'3,1,2',
198 'renderObj' =>
'TEXT',
199 'renderObj.' => array(
200 'data' =>
'file:current:name',
201 'wrap' =>
'<p>|</p>',
204 '<p>File 1</p><p>File 2</p><p>File 3</p>',
215 $fileReferenceMap = array();
216 for ($i = 1; $i < 4; $i++) {
217 $fileReference = $this->getMock(FileReference::class, array(), array(),
'',
false);
218 $fileReference->expects($this->any())
220 ->will($this->returnValue(
'File ' . $i));
221 $fileReference->expects($this->any())
222 ->method(
'hasProperty')
224 ->will($this->returnValue(
true));
225 $fileReference->expects($this->any())
226 ->method(
'getProperty')
228 ->will($this->returnValue(
'File ' . $i));
230 $fileReferenceMap[] = array($i, $fileReference);
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, array(
'getFileRepository'));
238 $fileCollector->expects($this->any())
239 ->method(
'getFileRepository')
240 ->will($this->returnValue($fileRepository));
242 $this->subject->expects($this->any())
243 ->method(
'getFileCollector')
244 ->will($this->returnValue($fileCollector));
246 $this->assertSame($expected, $this->subject->render($configuration));
258 'renderObj' =>
'TEXT',
259 'renderObj.' => array(
260 'data' =>
'file:current:name',
261 'wrap' =>
'<p>|</p>',
266 'One file with begin higher than allowed' => array(
270 'renderObj' =>
'TEXT',
271 'renderObj.' => array(
272 'data' =>
'file:current:name',
273 'wrap' =>
'<p>|</p>',
278 'One file with maxItems higher than allowed' => array(
282 'renderObj' =>
'TEXT',
283 'renderObj.' => array(
284 'data' =>
'file:current:name',
285 'wrap' =>
'<p>|</p>',
290 'Multiple files' => array(
293 'renderObj' =>
'TEXT',
294 'renderObj.' => array(
295 'data' =>
'file:current:name',
296 'wrap' =>
'<p>|</p>',
299 '<p>File 1</p><p>File 2</p><p>File 3</p>',
301 'Multiple files with begin' => array(
305 'renderObj' =>
'TEXT',
306 'renderObj.' => array(
307 'data' =>
'file:current:name',
308 'wrap' =>
'<p>|</p>',
311 '<p>File 2</p><p>File 3</p>',
313 'Multiple files with negative begin' => array(
317 'renderObj' =>
'TEXT',
318 'renderObj.' => array(
319 'data' =>
'file:current:name',
320 'wrap' =>
'<p>|</p>',
323 '<p>File 1</p><p>File 2</p><p>File 3</p>',
325 'Multiple files with maxItems' => array(
329 'renderObj' =>
'TEXT',
330 'renderObj.' => array(
331 'data' =>
'file:current:name',
332 'wrap' =>
'<p>|</p>',
335 '<p>File 1</p><p>File 2</p>',
337 'Multiple files with negative maxItems' => array(
341 'renderObj' =>
'TEXT',
342 'renderObj.' => array(
343 'data' =>
'file:current:name',
344 'wrap' =>
'<p>|</p>',
349 'Multiple files with begin and maxItems' => array(
354 'renderObj' =>
'TEXT',
355 'renderObj.' => array(
356 'data' =>
'file:current:name',
357 'wrap' =>
'<p>|</p>',
362 'Multiple files unsorted' => array(
365 'renderObj' =>
'TEXT',
366 'renderObj.' => array(
367 'data' =>
'file:current:name',
368 'wrap' =>
'<p>|</p>',
371 '<p>File 1</p><p>File 3</p><p>File 2</p>',
373 'Multiple files sorted by name' => array(
377 'renderObj' =>
'TEXT',
378 'renderObj.' => array(
379 'data' =>
'file:current:name',
380 'wrap' =>
'<p>|</p>',
383 '<p>File 1</p><p>File 2</p><p>File 3</p>',
395 for ($i = 1; $i < 4; $i++) {
396 $file = $this->getMock(File::class, array(), array(),
'',
false);
397 $file->expects($this->any())
399 ->will($this->returnValue(
'File ' . $i));
400 $file->expects($this->any())
401 ->method(
'hasProperty')
403 ->will($this->returnValue(
true));
404 $file->expects($this->any())
405 ->method(
'getProperty')
407 ->will($this->returnValue(
'File ' . $i));
409 $fileMap[] = array($i, array(), $file);
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, array(
'getResourceFactory'));
417 $fileCollector->expects($this->any())
418 ->method(
'getResourceFactory')
419 ->will($this->returnValue($resourceFactory));
421 $this->subject->expects($this->any())
422 ->method(
'getFileCollector')
423 ->will($this->returnValue($fileCollector));
425 $this->assertSame($expected, $this->subject->render($configuration));
434 'One collection' => array(
436 'collections' =>
'1',
437 'renderObj' =>
'TEXT',
438 'renderObj.' => array(
439 'data' =>
'file:current:name',
440 'wrap' =>
'<p>|</p>',
443 '<p>File 1</p><p>File 2</p><p>File 3</p>',
445 'One collection with begin' => array(
447 'collections' =>
'1',
449 'renderObj' =>
'TEXT',
450 'renderObj.' => array(
451 'data' =>
'file:current:name',
452 'wrap' =>
'<p>|</p>',
455 '<p>File 2</p><p>File 3</p>',
457 'One collection with begin higher than allowed' => array(
459 'collections' =>
'1',
461 'renderObj' =>
'TEXT',
462 'renderObj.' => array(
463 'data' =>
'file:current:name',
464 'wrap' =>
'<p>|</p>',
469 'One collection with maxItems' => array(
471 'collections' =>
'1',
473 'renderObj' =>
'TEXT',
474 'renderObj.' => array(
475 'data' =>
'file:current:name',
476 'wrap' =>
'<p>|</p>',
479 '<p>File 1</p><p>File 2</p>',
481 'One collection with maxItems higher than allowed' => array(
483 'collections' =>
'1',
485 'renderObj' =>
'TEXT',
486 'renderObj.' => array(
487 'data' =>
'file:current:name',
488 'wrap' =>
'<p>|</p>',
491 '<p>File 1</p><p>File 2</p><p>File 3</p>',
493 'One collections with begin and maxItems' => array(
495 'collections' =>
'1',
498 'renderObj' =>
'TEXT',
499 'renderObj.' => array(
500 'data' =>
'file:current:name',
501 'wrap' =>
'<p>|</p>',
506 'Multiple collections' => array(
508 'collections' =>
'1,2,3',
509 'renderObj' =>
'TEXT',
510 'renderObj.' => array(
511 'data' =>
'file:current:name',
512 'wrap' =>
'<p>|</p>',
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>',
517 'Multiple collections with begin' => array(
519 'collections' =>
'1,2,3',
521 'renderObj' =>
'TEXT',
522 'renderObj.' => array(
523 'data' =>
'file:current:name',
524 'wrap' =>
'<p>|</p>',
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>',
529 'Multiple collections with negative begin' => array(
531 'collections' =>
'1,2,3',
533 'renderObj' =>
'TEXT',
534 'renderObj.' => array(
535 'data' =>
'file:current:name',
536 'wrap' =>
'<p>|</p>',
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>',
541 'Multiple collections with maxItems' => array(
543 'collections' =>
'1,2,3',
545 'renderObj' =>
'TEXT',
546 'renderObj.' => array(
547 'data' =>
'file:current:name',
548 'wrap' =>
'<p>|</p>',
551 '<p>File 1</p><p>File 2</p><p>File 3</p><p>File 4</p><p>File 5</p>',
553 'Multiple collections with negative maxItems' => array(
555 'collections' =>
'1,2,3',
557 'renderObj' =>
'TEXT',
558 'renderObj.' => array(
559 'data' =>
'file:current:name',
560 'wrap' =>
'<p>|</p>',
565 'Multiple collections with begin and maxItems' => array(
567 'collections' =>
'1,2,3',
570 'renderObj' =>
'TEXT',
571 'renderObj.' => array(
572 'data' =>
'file:current:name',
573 'wrap' =>
'<p>|</p>',
576 '<p>File 5</p><p>File 6</p><p>File 7</p>',
578 'Multiple collections unsorted' => array(
580 'collections' =>
'1,3,2',
581 'renderObj' =>
'TEXT',
582 'renderObj.' => array(
583 'data' =>
'file:current:name',
584 'wrap' =>
'<p>|</p>',
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>',
589 'Multiple collections sorted by name' => array(
591 'collections' =>
'3,1,2',
593 'renderObj' =>
'TEXT',
594 'renderObj.' => array(
595 'data' =>
'file:current:name',
596 'wrap' =>
'<p>|</p>',
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>',
610 $collectionMap = array();
612 for ($i = 1; $i < 4; $i++) {
613 $fileReferenceArray = array();
614 for ($j = 1; $j < 4; $j++) {
615 $fileReference = $this->getMock(FileReference::class, array(), array(),
'',
false);
616 $fileReference->expects($this->any())
618 ->will($this->returnValue(
'File ' . $fileCount));
619 $fileReference->expects($this->any())
620 ->method(
'hasProperty')
622 ->will($this->returnValue(
true));
623 $fileReference->expects($this->any())
624 ->method(
'getProperty')
626 ->will($this->returnValue(
'File ' . $fileCount));
628 $fileReferenceArray[] = $fileReference;
632 $collection = $this->getMock(StaticFileCollection::class, array(), array(),
'',
false);
633 $collection->expects($this->any())
635 ->will($this->returnValue($fileReferenceArray));
637 $collectionMap[] = array($i, $collection);
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, array(
'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));
652 $this->assertSame($expected, $this->subject->render($configuration));
661 'One folder' => array(
663 'folders' =>
'1:myfolder/',
664 'renderObj' =>
'TEXT',
665 'renderObj.' => array(
666 'data' =>
'file:current:name',
667 'wrap' =>
'<p>|</p>',
670 '<p>File 1</p><p>File 2</p><p>File 3</p>',
672 'One folder with begin' => array(
674 'folders' =>
'1:myfolder/',
676 'renderObj' =>
'TEXT',
677 'renderObj.' => array(
678 'data' =>
'file:current:name',
679 'wrap' =>
'<p>|</p>',
682 '<p>File 2</p><p>File 3</p>',
684 'One folder with begin higher than allowed' => array(
686 'folders' =>
'1:myfolder/',
688 'renderObj' =>
'TEXT',
689 'renderObj.' => array(
690 'data' =>
'file:current:name',
691 'wrap' =>
'<p>|</p>',
696 'One folder with maxItems' => array(
698 'folders' =>
'1:myfolder/',
700 'renderObj' =>
'TEXT',
701 'renderObj.' => array(
702 'data' =>
'file:current:name',
703 'wrap' =>
'<p>|</p>',
706 '<p>File 1</p><p>File 2</p>',
708 'One folder with maxItems higher than allowed' => array(
710 'folders' =>
'1:myfolder/',
712 'renderObj' =>
'TEXT',
713 'renderObj.' => array(
714 'data' =>
'file:current:name',
715 'wrap' =>
'<p>|</p>',
718 '<p>File 1</p><p>File 2</p><p>File 3</p>',
720 'One folder with begin and maxItems' => array(
722 'folders' =>
'1:myfolder/',
725 'renderObj' =>
'TEXT',
726 'renderObj.' => array(
727 'data' =>
'file:current:name',
728 'wrap' =>
'<p>|</p>',
733 'Multiple folders' => array(
735 'folders' =>
'1:myfolder/,2:myfolder/,3:myfolder/',
736 'renderObj' =>
'TEXT',
737 'renderObj.' => array(
738 'data' =>
'file:current:name',
739 'wrap' =>
'<p>|</p>',
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>',
744 'Multiple folders with begin' => array(
746 'folders' =>
'1:myfolder/,2:myfolder/,3:myfolder/',
748 'renderObj' =>
'TEXT',
749 'renderObj.' => array(
750 'data' =>
'file:current:name',
751 'wrap' =>
'<p>|</p>',
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>',
756 'Multiple folders with negative begin' => array(
758 'folders' =>
'1:myfolder/,2:myfolder/,3:myfolder/',
760 'renderObj' =>
'TEXT',
761 'renderObj.' => array(
762 'data' =>
'file:current:name',
763 'wrap' =>
'<p>|</p>',
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>',
768 'Multiple folders with maxItems' => array(
770 'folders' =>
'1:myfolder/,2:myfolder/,3:myfolder/',
772 'renderObj' =>
'TEXT',
773 'renderObj.' => array(
774 'data' =>
'file:current:name',
775 'wrap' =>
'<p>|</p>',
778 '<p>File 1</p><p>File 2</p><p>File 3</p><p>File 4</p><p>File 5</p>',
780 'Multiple folders with negative maxItems' => array(
782 'folders' =>
'1:myfolder/,2:myfolder/,3:myfolder/',
784 'renderObj' =>
'TEXT',
785 'renderObj.' => array(
786 'data' =>
'file:current:name',
787 'wrap' =>
'<p>|</p>',
792 'Multiple folders with begin and maxItems' => array(
794 'folders' =>
'1:myfolder/,2:myfolder/,3:myfolder/',
797 'renderObj' =>
'TEXT',
798 'renderObj.' => array(
799 'data' =>
'file:current:name',
800 'wrap' =>
'<p>|</p>',
803 '<p>File 5</p><p>File 6</p><p>File 7</p>',
805 'Multiple folders unsorted' => array(
807 'folders' =>
'1:myfolder/,3:myfolder/,2:myfolder/',
808 'renderObj' =>
'TEXT',
809 'renderObj.' => array(
810 'data' =>
'file:current:name',
811 'wrap' =>
'<p>|</p>',
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>',
816 'Multiple folders sorted by name' => array(
818 'folders' =>
'3:myfolder/,1:myfolder/,2:myfolder/',
820 'renderObj' =>
'TEXT',
821 'renderObj.' => array(
822 'data' =>
'file:current:name',
823 'wrap' =>
'<p>|</p>',
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>',
828 'Multiple folders recursively' => array(
830 'folders' =>
'1:myfolder/',
834 'renderObj' =>
'TEXT',
835 'renderObj.' => array(
836 'data' =>
'file:current:name',
837 'wrap' =>
'<p>|</p>',
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>',
843 'Multiple folders recursively, sorted by name' => array(
845 'folders' =>
'1:myfolder/',
850 'renderObj' =>
'TEXT',
851 'renderObj.' => array(
852 'data' =>
'file:current:name',
853 'wrap' =>
'<p>|</p>',
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>',
868 $folderMap = array();
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())
878 ->will($this->returnValue(
'File ' . $fileCount));
879 $file->expects($this->any())
880 ->method(
'hasProperty')
882 ->will($this->returnValue(
true));
883 $file->expects($this->any())
884 ->method(
'getProperty')
886 ->will($this->returnValue(
'File ' . $fileCount));
888 $filesArrayForFolder[$i][] = $file;
892 $folder = $this->getMock(Folder::class, array(), array(),
'',
false);
896 $folders[$i] = $folder;
897 $folderMap[$i] = array(
'1:myfolder/mysubfolder-' . $i .
'/', $folder);
899 $folder->expects($this->any())
900 ->method(
'getSubfolders')
901 ->will($this->returnValue($folders));
902 $folderMap[$i] = array(
'1:myfolder/', $folder);
905 $folderMap[$i] = array($i .
':myfolder/', $folder);
908 foreach ($folderMap as $i => $folderMapInfo) {
909 if ($i < 3 || !$recursive) {
910 $folderMapInfo[1]->expects($this->any())
912 ->will($this->returnValue($filesArrayForFolder[$i]));
914 $recursiveFiles = array_merge($filesArrayForFolder[3], $filesArrayForFolder[1], $filesArrayForFolder[2]);
915 $folderMapInfo[1]->expects($this->any())
917 ->will($this->returnValue($recursiveFiles));
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, array(
'getResourceFactory'));
926 $fileCollector->expects($this->any())
927 ->method(
'getResourceFactory')
928 ->will($this->returnValue($resourceFactory));
930 $this->subject->expects($this->any())
931 ->method(
'getFileCollector')
932 ->will($this->returnValue($fileCollector));
934 $this->assertSame($expected, $this->subject->render($configuration));