Ejemplo n.º 1
0
 /**
  * @test
  * @dataProvider renderReturnsFilesForFoldersDataProvider
  */
 public function renderReturnsFilesForFolders($configuration, $expected)
 {
     $folderMap = array();
     $fileCount = 1;
     for ($i = 1; $i < 4; $i++) {
         $fileArray = array();
         for ($j = 1; $j < 4; $j++) {
             $file = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, array(), array(), '', FALSE);
             $file->expects($this->any())->method('getName')->will($this->returnValue('File ' . $fileCount));
             $file->expects($this->any())->method('hasProperty')->with('name')->will($this->returnValue(TRUE));
             $file->expects($this->any())->method('getProperty')->with('name')->will($this->returnValue('File ' . $fileCount));
             $fileArray[] = $file;
             $fileCount++;
         }
         $folder = $this->getMock(\TYPO3\CMS\Core\Resource\Folder::class, array(), array(), '', FALSE);
         $folder->expects($this->any())->method('getFiles')->will($this->returnValue($fileArray));
         $folderMap[] = array($i . ':myfolder/', $folder);
     }
     $resourceFactory = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceFactory::class);
     $resourceFactory->expects($this->any())->method('getFolderObjectFromCombinedIdentifier')->will($this->returnValueMap($folderMap));
     $fileCollector = $this->getMock(FileCollector::class, array('getResourceFactory'));
     $fileCollector->expects($this->any())->method('getResourceFactory')->will($this->returnValue($resourceFactory));
     $this->subject->expects($this->any())->method('getFileCollector')->will($this->returnValue($fileCollector));
     $this->assertSame($expected, $this->subject->render($configuration));
 }
 /**
  * @test
  * @dataProvider renderReturnsFilesForFoldersDataProvider
  */
 public function renderReturnsFilesForFolders($configuration, $expected, $recursive = false)
 {
     $folderMap = array();
     $folders = array();
     $fileCount = 1;
     $filesArrayForFolder = [];
     for ($i = 1; $i < 4; $i++) {
         $filesArrayForFolder[$i] = [];
         for ($j = 1; $j < 4; $j++) {
             $file = $this->getMock(File::class, [], [], '', false);
             $file->expects($this->any())->method('getName')->will($this->returnValue('File ' . $fileCount));
             $file->expects($this->any())->method('hasProperty')->with('name')->will($this->returnValue(true));
             $file->expects($this->any())->method('getProperty')->with('name')->will($this->returnValue('File ' . $fileCount));
             $filesArrayForFolder[$i][] = $file;
             $fileCount++;
         }
         $folder = $this->getMock(Folder::class, array(), array(), '', false);
         if ($recursive) {
             if ($i < 3) {
                 $folders[$i] = $folder;
                 $folderMap[$i] = array('1:myfolder/mysubfolder-' . $i . '/', $folder);
             } else {
                 $folder->expects($this->any())->method('getSubfolders')->will($this->returnValue($folders));
                 $folderMap[$i] = array('1:myfolder/', $folder);
             }
         } else {
             $folderMap[$i] = array($i . ':myfolder/', $folder);
         }
     }
     foreach ($folderMap as $i => $folderMapInfo) {
         if ($i < 3 || !$recursive) {
             $folderMapInfo[1]->expects($this->any())->method('getFiles')->will($this->returnValue($filesArrayForFolder[$i]));
         } else {
             $recursiveFiles = array_merge($filesArrayForFolder[3], $filesArrayForFolder[1], $filesArrayForFolder[2]);
             $folderMapInfo[1]->expects($this->any())->method('getFiles')->will($this->returnValue($recursiveFiles));
         }
     }
     $resourceFactory = $this->getMock(ResourceFactory::class);
     $resourceFactory->expects($this->any())->method('getFolderObjectFromCombinedIdentifier')->will($this->returnValueMap($folderMap));
     $fileCollector = $this->getMock(FileCollector::class, array('getResourceFactory'));
     $fileCollector->expects($this->any())->method('getResourceFactory')->will($this->returnValue($resourceFactory));
     $this->subject->expects($this->any())->method('getFileCollector')->will($this->returnValue($fileCollector));
     $this->assertSame($expected, $this->subject->render($configuration));
 }