TYPO3  7.6
FilesContentObjectTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\ContentObject;
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 
34 class FilesContentObjectTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
35 {
39  protected $subject = null;
40 
44  protected $tsfe = null;
45 
49  protected function setUp()
50  {
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;
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(array(
64  'FILES' => FilesContentObject::class,
65  'TEXT' => TextContentObject::class,
66  ));
67  $this->subject = $this->getMock(FilesContentObject::class, array('getFileCollector'), array($contentObjectRenderer));
68  }
69 
74  {
75  return array(
76  'One file reference' => array(
77  array(
78  'references' => '1',
79  'renderObj' => 'TEXT',
80  'renderObj.' => array(
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' => array(
88  array(
89  'references' => '1',
90  'begin' => '1',
91  'renderObj' => 'TEXT',
92  'renderObj.' => array(
93  'data' => 'file:current:name',
94  'wrap' => '<p>|</p>',
95  ),
96  ),
97  '',
98  ),
99  'One file reference with maxItems higher than allowed' => array(
100  array(
101  'references' => '1',
102  'maxItems' => '2',
103  'renderObj' => 'TEXT',
104  'renderObj.' => array(
105  'data' => 'file:current:name',
106  'wrap' => '<p>|</p>',
107  ),
108  ),
109  '<p>File 1</p>',
110  ),
111  'Multiple file references' => array(
112  array(
113  'references' => '1,2,3',
114  'renderObj' => 'TEXT',
115  'renderObj.' => array(
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' => array(
123  array(
124  'references' => '1,2,3',
125  'begin' => '1',
126  'renderObj' => 'TEXT',
127  'renderObj.' => array(
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' => array(
135  array(
136  'references' => '1,2,3',
137  'begin' => '-1',
138  'renderObj' => 'TEXT',
139  'renderObj.' => array(
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' => array(
147  array(
148  'references' => '1,2,3',
149  'maxItems' => '2',
150  'renderObj' => 'TEXT',
151  'renderObj.' => array(
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' => array(
159  array(
160  'references' => '1,2,3',
161  'maxItems' => '-2',
162  'renderObj' => 'TEXT',
163  'renderObj.' => array(
164  'data' => 'file:current:name',
165  'wrap' => '<p>|</p>',
166  ),
167  ),
168  '',
169  ),
170  'Multiple file references with begin and maxItems' => array(
171  array(
172  'references' => '1,2,3',
173  'begin' => '1',
174  'maxItems' => '1',
175  'renderObj' => 'TEXT',
176  'renderObj.' => array(
177  'data' => 'file:current:name',
178  'wrap' => '<p>|</p>',
179  ),
180  ),
181  '<p>File 2</p>',
182  ),
183  'Multiple file references unsorted' => array(
184  array(
185  'references' => '1,3,2',
186  'renderObj' => 'TEXT',
187  'renderObj.' => array(
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' => array(
195  array(
196  'references' => '3,1,2',
197  'sorting' => 'name',
198  'renderObj' => 'TEXT',
199  'renderObj.' => array(
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 = array();
216  for ($i = 1; $i < 4; $i++) {
217  $fileReference = $this->getMock(FileReference::class, array(), array(), '', 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[] = array($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, array('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 array(
255  'One file' => array(
256  array(
257  'files' => '1',
258  'renderObj' => 'TEXT',
259  'renderObj.' => array(
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' => array(
267  array(
268  'files' => '1',
269  'begin' => '1',
270  'renderObj' => 'TEXT',
271  'renderObj.' => array(
272  'data' => 'file:current:name',
273  'wrap' => '<p>|</p>',
274  ),
275  ),
276  '',
277  ),
278  'One file with maxItems higher than allowed' => array(
279  array(
280  'files' => '1',
281  'maxItems' => '2',
282  'renderObj' => 'TEXT',
283  'renderObj.' => array(
284  'data' => 'file:current:name',
285  'wrap' => '<p>|</p>',
286  ),
287  ),
288  '<p>File 1</p>',
289  ),
290  'Multiple files' => array(
291  array(
292  'files' => '1,2,3',
293  'renderObj' => 'TEXT',
294  'renderObj.' => array(
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' => array(
302  array(
303  'files' => '1,2,3',
304  'begin' => '1',
305  'renderObj' => 'TEXT',
306  'renderObj.' => array(
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' => array(
314  array(
315  'files' => '1,2,3',
316  'begin' => '-1',
317  'renderObj' => 'TEXT',
318  'renderObj.' => array(
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' => array(
326  array(
327  'files' => '1,2,3',
328  'maxItems' => '2',
329  'renderObj' => 'TEXT',
330  'renderObj.' => array(
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' => array(
338  array(
339  'files' => '1,2,3',
340  'maxItems' => '-2',
341  'renderObj' => 'TEXT',
342  'renderObj.' => array(
343  'data' => 'file:current:name',
344  'wrap' => '<p>|</p>',
345  ),
346  ),
347  '',
348  ),
349  'Multiple files with begin and maxItems' => array(
350  array(
351  'files' => '1,2,3',
352  'begin' => '1',
353  'maxItems' => '1',
354  'renderObj' => 'TEXT',
355  'renderObj.' => array(
356  'data' => 'file:current:name',
357  'wrap' => '<p>|</p>',
358  ),
359  ),
360  '<p>File 2</p>',
361  ),
362  'Multiple files unsorted' => array(
363  array(
364  'files' => '1,3,2',
365  'renderObj' => 'TEXT',
366  'renderObj.' => array(
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' => array(
374  array(
375  'files' => '3,1,2',
376  'sorting' => 'name',
377  'renderObj' => 'TEXT',
378  'renderObj.' => array(
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 = array();
395  for ($i = 1; $i < 4; $i++) {
396  $file = $this->getMock(File::class, array(), array(), '', 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[] = array($i, array(), $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, array('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 array(
434  'One collection' => array(
435  array(
436  'collections' => '1',
437  'renderObj' => 'TEXT',
438  'renderObj.' => array(
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' => array(
446  array(
447  'collections' => '1',
448  'begin' => '1',
449  'renderObj' => 'TEXT',
450  'renderObj.' => array(
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' => array(
458  array(
459  'collections' => '1',
460  'begin' => '3',
461  'renderObj' => 'TEXT',
462  'renderObj.' => array(
463  'data' => 'file:current:name',
464  'wrap' => '<p>|</p>',
465  ),
466  ),
467  '',
468  ),
469  'One collection with maxItems' => array(
470  array(
471  'collections' => '1',
472  'maxItems' => '2',
473  'renderObj' => 'TEXT',
474  'renderObj.' => array(
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' => array(
482  array(
483  'collections' => '1',
484  'maxItems' => '4',
485  'renderObj' => 'TEXT',
486  'renderObj.' => array(
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' => array(
494  array(
495  'collections' => '1',
496  'begin' => '1',
497  'maxItems' => '1',
498  'renderObj' => 'TEXT',
499  'renderObj.' => array(
500  'data' => 'file:current:name',
501  'wrap' => '<p>|</p>',
502  ),
503  ),
504  '<p>File 2</p>',
505  ),
506  'Multiple collections' => array(
507  array(
508  'collections' => '1,2,3',
509  'renderObj' => 'TEXT',
510  'renderObj.' => array(
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' => array(
518  array(
519  'collections' => '1,2,3',
520  'begin' => '3',
521  'renderObj' => 'TEXT',
522  'renderObj.' => array(
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' => array(
530  array(
531  'collections' => '1,2,3',
532  'begin' => '-3',
533  'renderObj' => 'TEXT',
534  'renderObj.' => array(
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' => array(
542  array(
543  'collections' => '1,2,3',
544  'maxItems' => '5',
545  'renderObj' => 'TEXT',
546  'renderObj.' => array(
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' => array(
554  array(
555  'collections' => '1,2,3',
556  'maxItems' => '-5',
557  'renderObj' => 'TEXT',
558  'renderObj.' => array(
559  'data' => 'file:current:name',
560  'wrap' => '<p>|</p>',
561  ),
562  ),
563  '',
564  ),
565  'Multiple collections with begin and maxItems' => array(
566  array(
567  'collections' => '1,2,3',
568  'begin' => '4',
569  'maxItems' => '3',
570  'renderObj' => 'TEXT',
571  'renderObj.' => array(
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' => array(
579  array(
580  'collections' => '1,3,2',
581  'renderObj' => 'TEXT',
582  'renderObj.' => array(
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' => array(
590  array(
591  'collections' => '3,1,2',
592  'sorting' => 'name',
593  'renderObj' => 'TEXT',
594  'renderObj.' => array(
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 = array();
611  $fileCount = 1;
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())
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, array(), array(), '', false);
633  $collection->expects($this->any())
634  ->method('getItems')
635  ->will($this->returnValue($fileReferenceArray));
636 
637  $collectionMap[] = array($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, 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));
651 
652  $this->assertSame($expected, $this->subject->render($configuration));
653  }
654 
659  {
660  return array(
661  'One folder' => array(
662  array(
663  'folders' => '1:myfolder/',
664  'renderObj' => 'TEXT',
665  'renderObj.' => array(
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' => array(
673  array(
674  'folders' => '1:myfolder/',
675  'begin' => '1',
676  'renderObj' => 'TEXT',
677  'renderObj.' => array(
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' => array(
685  array(
686  'folders' => '1:myfolder/',
687  'begin' => '3',
688  'renderObj' => 'TEXT',
689  'renderObj.' => array(
690  'data' => 'file:current:name',
691  'wrap' => '<p>|</p>',
692  ),
693  ),
694  '',
695  ),
696  'One folder with maxItems' => array(
697  array(
698  'folders' => '1:myfolder/',
699  'maxItems' => '2',
700  'renderObj' => 'TEXT',
701  'renderObj.' => array(
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' => array(
709  array(
710  'folders' => '1:myfolder/',
711  'maxItems' => '4',
712  'renderObj' => 'TEXT',
713  'renderObj.' => array(
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' => array(
721  array(
722  'folders' => '1:myfolder/',
723  'begin' => '1',
724  'maxItems' => '1',
725  'renderObj' => 'TEXT',
726  'renderObj.' => array(
727  'data' => 'file:current:name',
728  'wrap' => '<p>|</p>',
729  ),
730  ),
731  '<p>File 2</p>',
732  ),
733  'Multiple folders' => array(
734  array(
735  'folders' => '1:myfolder/,2:myfolder/,3:myfolder/',
736  'renderObj' => 'TEXT',
737  'renderObj.' => array(
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' => array(
745  array(
746  'folders' => '1:myfolder/,2:myfolder/,3:myfolder/',
747  'begin' => '3',
748  'renderObj' => 'TEXT',
749  'renderObj.' => array(
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' => array(
757  array(
758  'folders' => '1:myfolder/,2:myfolder/,3:myfolder/',
759  'begin' => '-3',
760  'renderObj' => 'TEXT',
761  'renderObj.' => array(
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' => array(
769  array(
770  'folders' => '1:myfolder/,2:myfolder/,3:myfolder/',
771  'maxItems' => '5',
772  'renderObj' => 'TEXT',
773  'renderObj.' => array(
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' => array(
781  array(
782  'folders' => '1:myfolder/,2:myfolder/,3:myfolder/',
783  'maxItems' => '-5',
784  'renderObj' => 'TEXT',
785  'renderObj.' => array(
786  'data' => 'file:current:name',
787  'wrap' => '<p>|</p>',
788  ),
789  ),
790  '',
791  ),
792  'Multiple folders with begin and maxItems' => array(
793  array(
794  'folders' => '1:myfolder/,2:myfolder/,3:myfolder/',
795  'begin' => '4',
796  'maxItems' => '3',
797  'renderObj' => 'TEXT',
798  'renderObj.' => array(
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' => array(
806  array(
807  'folders' => '1:myfolder/,3:myfolder/,2:myfolder/',
808  'renderObj' => 'TEXT',
809  'renderObj.' => array(
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' => array(
817  array(
818  'folders' => '3:myfolder/,1:myfolder/,2:myfolder/',
819  'sorting' => 'name',
820  'renderObj' => 'TEXT',
821  'renderObj.' => array(
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' => array(
829  array(
830  'folders' => '1:myfolder/',
831  'folders.' => array(
832  'recursive' => '1'
833  ),
834  'renderObj' => 'TEXT',
835  'renderObj.' => array(
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' => array(
844  array(
845  'folders' => '1:myfolder/',
846  'folders.' => array(
847  'recursive' => '1'
848  ),
849  'sorting' => 'name',
850  'renderObj' => 'TEXT',
851  'renderObj.' => array(
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 = array();
869  $folders = array();
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, array(), array(), '', false);
893 
894  if ($recursive) {
895  if ($i < 3) {
896  $folders[$i] = $folder;
897  $folderMap[$i] = array('1:myfolder/mysubfolder-' . $i . '/', $folder);
898  } else {
899  $folder->expects($this->any())
900  ->method('getSubfolders')
901  ->will($this->returnValue($folders));
902  $folderMap[$i] = array('1:myfolder/', $folder);
903  }
904  } else {
905  $folderMap[$i] = array($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, array('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 }