TYPO3 CMS  TYPO3_7-6
ResourceStorageTest.php
Go to the documentation of this file.
1 <?php
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  */
16 
29 
34 {
38  protected $singletonInstances = [];
39 
43  protected $subject;
44 
45  protected function setUp()
46  {
47  parent::setUp();
48  $this->singletonInstances = GeneralUtility::getSingletonInstances();
50  $fileRepositoryMock = $this->getMock(FileRepository::class);
52  FileRepository::class,
53  $fileRepositoryMock
54  );
55  $databaseMock = $this->getMock(DatabaseConnection::class);
56  $databaseMock->expects($this->any())->method('exec_SELECTgetRows')->with('*', 'sys_file_storage', '1=1', '', 'name', '', 'uid')->willReturn([]);
57  $GLOBALS['TYPO3_DB'] = $databaseMock;
58  }
59 
60  protected function tearDown()
61  {
62  GeneralUtility::resetSingletonInstances($this->singletonInstances);
63  parent::tearDown();
64  }
65 
74  protected function prepareSubject(array $configuration, $mockPermissionChecks = false, AbstractDriver $driverObject = null, array $storageRecord = [])
75  {
76  $permissionMethods = ['assureFileAddPermissions', 'checkFolderActionPermission', 'checkFileActionPermission', 'checkUserActionPermission', 'checkFileExtensionPermission', 'isWithinFileMountBoundaries'];
77  $mockedMethods = [];
78  $configuration = $this->convertConfigurationArrayToFlexformXml($configuration);
79  $overruleArray = ['configuration' => $configuration];
80  ArrayUtility::mergeRecursiveWithOverrule($storageRecord, $overruleArray);
81  if ($driverObject == null) {
82  $driverObject = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
83  }
84  if ($mockPermissionChecks) {
85  $mockedMethods = $permissionMethods;
86  }
87  $mockedMethods[] = 'getIndexer';
88 
89  $this->subject = $this->getMock(ResourceStorage::class, $mockedMethods, [$driverObject, $storageRecord]);
90  $this->subject->expects($this->any())->method('getIndexer')->will($this->returnValue($this->getMock(\TYPO3\CMS\Core\Resource\Index\Indexer::class, [], [], '', false)));
91  foreach ($permissionMethods as $method) {
92  $this->subject->expects($this->any())->method($method)->will($this->returnValue(true));
93  }
94  }
95 
103  protected function convertConfigurationArrayToFlexformXml(array $configuration)
104  {
105  $flexFormArray = ['data' => ['sDEF' => ['lDEF' => []]]];
106  foreach ($configuration as $key => $value) {
107  $flexFormArray['data']['sDEF']['lDEF'][$key] = ['vDEF' => $value];
108  }
109  $configuration = GeneralUtility::array2xml($flexFormArray);
110  return $configuration;
111  }
112 
123  protected function createDriverMock($driverConfiguration, ResourceStorage $storageObject = null, $mockedDriverMethods = [])
124  {
125  $this->initializeVfs();
126 
127  if (!isset($driverConfiguration['basePath'])) {
128  $driverConfiguration['basePath'] = $this->getMountRootUrl();
129  }
130 
131  if ($mockedDriverMethods === null) {
132  $driver = new LocalDriver($driverConfiguration);
133  } else {
134  // We are using the LocalDriver here because PHPUnit can't mock concrete methods in abstract classes, so
135  // when using the AbstractDriver we would be in trouble when wanting to mock away some concrete method
136  $driver = $this->getMock(LocalDriver::class, $mockedDriverMethods, [$driverConfiguration]);
137  }
138  if ($storageObject !== null) {
139  $storageObject->setDriver($driver);
140  }
141  $driver->setStorageUid(6);
142  $driver->processConfiguration();
143  $driver->initialize();
144  return $driver;
145  }
146 
151  {
152  return [
153  'Permissions evaluated, extension not in allowed list' => [
154  'fileName' => 'foo.txt',
155  'configuration' => ['allow' => 'jpg'],
156  'evaluatePermissions' => true,
157  'isAllowed' => true,
158  ],
159  'Permissions evaluated, extension in deny list' => [
160  'fileName' => 'foo.txt',
161  'configuration' => ['deny' => 'txt'],
162  'evaluatePermissions' => true,
163  'isAllowed' => false,
164  ],
165  'Permissions not evaluated, extension is php' => [
166  'fileName' => 'foo.php',
167  'configuration' => [],
168  'evaluatePermissions' => false,
169  'isAllowed' => false,
170  ],
171  'Permissions evaluated, extension is php' => [
172  'fileName' => 'foo.php',
173  // It is not possible to allow php file extension through configuration
174  'configuration' => ['allow' => 'php'],
175  'evaluatePermissions' => true,
176  'isAllowed' => false,
177  ],
178  ];
179  }
180 
189  public function fileExtensionPermissionIsWorkingCorrectly($fileName, array $configuration, $evaluatePermissions, $isAllowed)
190  {
191  $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']['webspace'] = $configuration;
192  $driverMock = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
193  $subject = $this->getAccessibleMock(ResourceStorage::class, ['dummy'], [$driverMock, []]);
194  $subject->_set('evaluatePermissions', $evaluatePermissions);
195  $this->assertSame($isAllowed, $subject->_call('checkFileExtensionPermission', $fileName));
196  }
197 
202  {
203  return [
204  'Access to file in ro file mount denied for write request' => [
205  '$fileIdentifier' => '/fooBaz/bar.txt',
206  '$fileMountFolderIdentifier' => '/fooBaz/',
207  '$isFileMountReadOnly' => true,
208  '$checkWriteAccess' => true,
209  '$expectedResult' => false,
210  ],
211  'Access to file in ro file mount allowed for read request' => [
212  '$fileIdentifier' => '/fooBaz/bar.txt',
213  '$fileMountFolderIdentifier' => '/fooBaz/',
214  '$isFileMountReadOnly' => true,
215  '$checkWriteAccess' => false,
216  '$expectedResult' => true,
217  ],
218  'Access to file in rw file mount allowed for write request' => [
219  '$fileIdentifier' => '/fooBaz/bar.txt',
220  '$fileMountFolderIdentifier' => '/fooBaz/',
221  '$isFileMountReadOnly' => false,
222  '$checkWriteAccess' => true,
223  '$expectedResult' => true,
224  ],
225  'Access to file in rw file mount allowed for read request' => [
226  '$fileIdentifier' => '/fooBaz/bar.txt',
227  '$fileMountFolderIdentifier' => '/fooBaz/',
228  '$isFileMountReadOnly' => false,
229  '$checkWriteAccess' => false,
230  '$expectedResult' => true,
231  ],
232  'Access to file not in file mount denied for write request' => [
233  '$fileIdentifier' => '/fooBaz/bar.txt',
234  '$fileMountFolderIdentifier' => '/barBaz/',
235  '$isFileMountReadOnly' => false,
236  '$checkWriteAccess' => true,
237  '$expectedResult' => false,
238  ],
239  'Access to file not in file mount denied for read request' => [
240  '$fileIdentifier' => '/fooBaz/bar.txt',
241  '$fileMountFolderIdentifier' => '/barBaz/',
242  '$isFileMountReadOnly' => false,
243  '$checkWriteAccess' => false,
244  '$expectedResult' => false,
245  ],
246  ];
247  }
248 
259  public function isWithinFileMountBoundariesRespectsReadOnlyFileMounts($fileIdentifier, $fileMountFolderIdentifier, $isFileMountReadOnly, $checkWriteAccess, $expectedResult)
260  {
262  $driverMock = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
263  $driverMock->expects($this->any())
264  ->method('getFolderInfoByIdentifier')
265  ->willReturnCallback(function ($identifier) use ($isFileMountReadOnly) {
266  return [
267  'identifier' => $identifier,
268  'name' => trim($identifier, '/'),
269  ];
270  });
271  $driverMock->expects($this->any())
272  ->method('isWithin')
273  ->willReturnCallback(function ($folderIdentifier, $fileIdentifier) {
274  if ($fileIdentifier === ResourceStorageInterface::DEFAULT_ProcessingFolder . '/') {
275  return false;
276  } else {
277  return strpos($fileIdentifier, $folderIdentifier) === 0;
278  }
279  });
280  $this->prepareSubject([], false, $driverMock);
281  $fileMock = $this->getSimpleFileMock($fileIdentifier);
282  $this->subject->setEvaluatePermissions(true);
283  $this->subject->addFileMount('/' . $this->getUniqueId('random') . '/', ['read_only' => false]);
284  $this->subject->addFileMount($fileMountFolderIdentifier, ['read_only' => $isFileMountReadOnly]);
285  $this->subject->addFileMount('/' . $this->getUniqueId('random') . '/', ['read_only' => false]);
286  $this->assertSame($expectedResult, $this->subject->isWithinFileMountBoundaries($fileMock, $checkWriteAccess));
287  }
288 
292  public function capabilitiesDataProvider()
293  {
294  return [
295  'only public' => [
296  [
297  'public' => true,
298  'writable' => false,
299  'browsable' => false
300  ]
301  ],
302  'only writable' => [
303  [
304  'public' => false,
305  'writable' => true,
306  'browsable' => false
307  ]
308  ],
309  'only browsable' => [
310  [
311  'public' => false,
312  'writable' => false,
313  'browsable' => true
314  ]
315  ],
316  'all capabilities' => [
317  [
318  'public' => true,
319  'writable' => true,
320  'browsable' => true
321  ]
322  ],
323  'none' => [
324  [
325  'public' => false,
326  'writable' => false,
327  'browsable' => false
328  ]
329  ]
330  ];
331  }
332 
338  public function capabilitiesOfStorageObjectAreCorrectlySet(array $capabilities)
339  {
340  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
341  $storageRecord = [
342  'is_public' => $capabilities['public'],
343  'is_writable' => $capabilities['writable'],
344  'is_browsable' => $capabilities['browsable'],
345  'is_online' => true
346  ];
347  $mockedDriver = $this->createDriverMock(
348  [
349  'pathType' => 'relative',
350  'basePath' => 'fileadmin/',
351  ],
352  $this->subject,
353  null
354  );
355  $this->prepareSubject([], false, $mockedDriver, $storageRecord);
356  $this->assertEquals($capabilities['public'], $this->subject->isPublic(), 'Capability "public" is not correctly set.');
357  $this->assertEquals($capabilities['writable'], $this->subject->isWritable(), 'Capability "writable" is not correctly set.');
358  $this->assertEquals($capabilities['browsable'], $this->subject->isBrowsable(), 'Capability "browsable" is not correctly set.');
359  }
360 
366  {
367  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
368  $this->prepareSubject([]);
369  $this->assertEquals($GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['defaultFilterCallbacks'], $this->subject->getFileAndFolderNameFilters());
370  }
371 
375  public function addFileFailsIfFileDoesNotExist()
376  {
378  $mockedFolder = $this->getMock(Folder::class, [], [], '', false);
379  $this->setExpectedException('InvalidArgumentException', '', 1319552745);
380  $this->prepareSubject([]);
381  $this->subject->addFile('/some/random/file', $mockedFolder);
382  }
383 
387  public function getPublicUrlReturnsNullIfStorageIsNotOnline()
388  {
390  $driver = $this->getMock(LocalDriver::class, [], [['basePath' => $this->getMountRootUrl()]]);
392  $subject = $this->getMock(ResourceStorage::class, ['isOnline'], [$driver, ['configuration' => []]]);
393  $subject->expects($this->once())->method('isOnline')->will($this->returnValue(false));
394 
395  $sourceFileIdentifier = '/sourceFile.ext';
396  $sourceFile = $this->getSimpleFileMock($sourceFileIdentifier);
397  $result = $subject->getPublicUrl($sourceFile);
398  $this->assertSame($result, null);
399  }
400 
407  {
408  return [
409  'read action on readable/writable folder' => [
410  'read',
411  ['r' => true, 'w' => true],
412  true
413  ],
414  'read action on unreadable folder' => [
415  'read',
416  ['r' => false, 'w' => true],
417  false
418  ],
419  'write action on read-only folder' => [
420  'write',
421  ['r' => true, 'w' => false],
422  false
423  ]
424  ];
425  }
426 
434  public function checkFolderPermissionsRespectsFilesystemPermissions($action, $permissionsFromDriver, $expectedResult)
435  {
437  $mockedDriver = $this->getMock(LocalDriver::class);
438  $mockedDriver->expects($this->any())->method('getPermissions')->will($this->returnValue($permissionsFromDriver));
440  $mockedFolder = $this->getMock(Folder::class, [], [], '', false);
441  // Let all other checks pass
443  $subject = $this->getMock(ResourceStorage::class, ['isWritable', 'isBrowsable', 'checkUserActionPermission'], [$mockedDriver, []], '', false);
444  $subject->expects($this->any())->method('isWritable')->will($this->returnValue(true));
445  $subject->expects($this->any())->method('isBrowsable')->will($this->returnValue(true));
446  $subject->expects($this->any())->method('checkUserActionPermission')->will($this->returnValue(true));
447  $subject->setDriver($mockedDriver);
448 
449  $this->assertSame($expectedResult, $subject->checkFolderActionPermission($action, $mockedFolder));
450  }
451 
456  {
457  $this->prepareSubject([]);
458  $this->assertTrue($this->subject->checkUserActionPermission('read', 'folder'));
459  }
460 
465  {
466  $this->prepareSubject([]);
467  $this->subject->setUserPermissions(['readFolder' => true, 'writeFile' => true]);
468  $this->assertTrue($this->subject->checkUserActionPermission('read', 'folder'));
469  }
470 
472  {
473  return [
474  'all lower cased' => [
475  ['readFolder' => true],
476  'read',
477  'folder'
478  ],
479  'all upper case' => [
480  ['readFolder' => true],
481  'READ',
482  'FOLDER'
483  ],
484  'mixed case' => [
485  ['readFolder' => true],
486  'ReaD',
487  'FoLdEr'
488  ]
489  ];
490  }
491 
499  public function checkUserActionPermissionAcceptsArbitrarilyCasedArguments(array $permissions, $action, $type)
500  {
501  $this->prepareSubject([]);
502  $this->subject->setUserPermissions($permissions);
503  $this->assertTrue($this->subject->checkUserActionPermission($action, $type));
504  }
505 
510  {
511  $this->prepareSubject([]);
512  $this->subject->setEvaluatePermissions(true);
513  $this->subject->setUserPermissions(['readFolder' => false]);
514  $this->assertFalse($this->subject->checkUserActionPermission('read', 'folder'));
515  }
516 
521  {
522  $this->prepareSubject([]);
523  $this->subject->setEvaluatePermissions(true);
524  $this->subject->setUserPermissions(['readFolder' => true]);
525  $this->assertFalse($this->subject->checkUserActionPermission('write', 'folder'));
526  }
527 
532  {
533  $this->prepareSubject([]);
534  $this->subject->setEvaluatePermissions(false);
535  $this->assertFalse($this->subject->getEvaluatePermissions());
536  }
537 
542  {
543  $this->prepareSubject([]);
544  $this->subject->setEvaluatePermissions(true);
545  $this->assertTrue($this->subject->getEvaluatePermissions());
546  }
547 
553  public function setFileContentsUpdatesObjectProperties()
554  {
555  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
556  $this->initializeVfs();
557  $driverObject = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
558  $this->subject = $this->getMock(ResourceStorage::class, ['getFileIndexRepository', 'checkFileActionPermission'], [$driverObject, []]);
559  $this->subject->expects($this->any())->method('checkFileActionPermission')->will($this->returnValue(true));
560  $fileInfo = [
561  'storage' => 'A',
562  'identifier' => 'B',
563  'mtime' => 'C',
564  'ctime' => 'D',
565  'mimetype' => 'E',
566  'size' => 'F',
567  'name' => 'G',
568  ];
569  $newProperties = [
570  'storage' => $fileInfo['storage'],
571  'identifier' => $fileInfo['identifier'],
572  'tstamp' => $fileInfo['mtime'],
573  'crdate' => $fileInfo['ctime'],
574  'mime_type' => $fileInfo['mimetype'],
575  'size' => $fileInfo['size'],
576  'name' => $fileInfo['name']
577  ];
578  $hash = 'asdfg';
580  $mockedDriver = $this->getMock(LocalDriver::class, [], [['basePath' => $this->getMountRootUrl()]]);
581  $mockedDriver->expects($this->once())->method('getFileInfoByIdentifier')->will($this->returnValue($fileInfo));
582  $mockedDriver->expects($this->once())->method('hash')->will($this->returnValue($hash));
583  $this->subject->setDriver($mockedDriver);
584  $indexFileRepositoryMock = $this->getMock(FileIndexRepository::class);
585  $this->subject->expects($this->any())->method('getFileIndexRepository')->will($this->returnValue($indexFileRepositoryMock));
587  $mockedFile = $this->getMock(File::class, [], [], '', false);
588  $mockedFile->expects($this->any())->method('getIdentifier')->will($this->returnValue($fileInfo['identifier']));
589  // called by indexer because the properties are updated
590  $this->subject->expects($this->any())->method('getFileInfoByIdentifier')->will($this->returnValue($newProperties));
591  $mockedFile->expects($this->any())->method('getStorage')->will($this->returnValue($this->subject));
592  $mockedFile->expects($this->any())->method('getProperties')->will($this->returnValue(array_keys($fileInfo)));
593  $mockedFile->expects($this->any())->method('getUpdatedProperties')->will($this->returnValue(array_keys($newProperties)));
594  // do not update directly; that's up to the indexer
595  $indexFileRepositoryMock->expects($this->never())->method('update');
596  $this->subject->setFileContents($mockedFile, $this->getUniqueId());
597  }
598 
604  public function moveFileCallsDriversMethodsWithCorrectArguments()
605  {
606  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
607  $localFilePath = '/path/to/localFile';
608  $sourceFileIdentifier = '/sourceFile.ext';
609  $fileInfoDummy = [
610  'storage' => 'A',
611  'identifier' => 'B',
612  'mtime' => 'C',
613  'ctime' => 'D',
614  'mimetype' => 'E',
615  'size' => 'F',
616  'name' => 'G',
617  ];
618  $this->addToMount([
619  'targetFolder' => []
620  ]);
621  $this->initializeVfs();
622  $targetFolder = $this->getSimpleFolderMock('/targetFolder/');
624  $sourceDriver = $this->getMock(LocalDriver::class);
625  $sourceDriver->expects($this->once())->method('deleteFile')->with($this->equalTo($sourceFileIdentifier));
626  $configuration = $this->convertConfigurationArrayToFlexformXml([]);
627  $sourceStorage = new ResourceStorage($sourceDriver, ['configuration' => $configuration]);
628  $sourceFile = $this->getSimpleFileMock($sourceFileIdentifier);
629  $sourceFile->expects($this->once())->method('getForLocalProcessing')->will($this->returnValue($localFilePath));
630  $sourceFile->expects($this->any())->method('getStorage')->will($this->returnValue($sourceStorage));
631  $sourceFile->expects($this->once())->method('getUpdatedProperties')->will($this->returnValue(array_keys($fileInfoDummy)));
632  $sourceFile->expects($this->once())->method('getProperties')->will($this->returnValue($fileInfoDummy));
634  $mockedDriver = $this->getMock(LocalDriver::class, [], [['basePath' => $this->getMountRootUrl()]]);
635  $mockedDriver->expects($this->once())->method('getFileInfoByIdentifier')->will($this->returnValue($fileInfoDummy));
636  $mockedDriver->expects($this->once())->method('addFile')->with($localFilePath, '/targetFolder/', $this->equalTo('file.ext'))->will($this->returnValue('/targetFolder/file.ext'));
638  $subject = $this->getMock(ResourceStorage::class, ['assureFileMovePermissions'], [$mockedDriver, ['configuration' => $configuration]]);
639  $subject->moveFile($sourceFile, $targetFolder, 'file.ext');
640  }
641 
648  {
649  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
650  $mockedFile = $this->getSimpleFileMock('/mountFolder/file');
651  $this->addToMount([
652  'mountFolder' => [
653  'file' => 'asdfg'
654  ]
655  ]);
656  $mockedDriver = $this->createDriverMock(['basePath' => $this->getMountRootUrl()], null, null);
657  $this->initializeVfs();
658  $this->prepareSubject([], null, $mockedDriver);
659  $this->subject->addFileMount('/mountFolder');
660  $this->assertEquals(1, count($this->subject->getFileMounts()));
661  $this->subject->isWithinFileMountBoundaries($mockedFile);
662  }
663 
669  {
670  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
671  $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
672  $mockedDriver = $this->createDriverMock([]);
673  $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(true));
674  $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('newFolder'))->will($this->returnValue($mockedParentFolder));
675  $this->prepareSubject([], true);
676  $this->subject->setDriver($mockedDriver);
677  $this->subject->createFolder('newFolder', $mockedParentFolder);
678  }
679 
684  public function deleteFolderThrowsExceptionIfFolderIsNotEmptyAndRecursiveDeleteIsDisabled()
685  {
687  $folderMock = $this->getMock(Folder::class, [], [], '', false);
689  $mockedDriver = $this->getMockForAbstractClass(AbstractDriver::class);
690  $mockedDriver->expects($this->once())->method('isFolderEmpty')->will($this->returnValue(false));
692  $subject = $this->getAccessibleMock(ResourceStorage::class, ['checkFolderActionPermission'], [], '', false);
693  $subject->expects($this->any())->method('checkFolderActionPermission')->will($this->returnValue(true));
694  $subject->_set('driver', $mockedDriver);
695  $subject->deleteFolder($folderMock, false);
696  }
697 
703  {
704  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
705  $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
706  $this->prepareSubject([], true);
707  $mockedDriver = $this->createDriverMock([], $this->subject);
708  $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('newFolder'), $this->equalTo('/someFolder/'))->will($this->returnValue(true));
709  $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(true));
710  $this->subject->createFolder('newFolder', $mockedParentFolder);
711  }
712 
718  {
719  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
720  $this->addToMount(['someFolder' => []]);
721  $mockedDriver = $this->createDriverMock(['basePath' => $this->getMountRootUrl()], null, null);
722  $this->prepareSubject([], true, $mockedDriver);
723  $parentFolder = $this->subject->getFolder('/someFolder/');
724  $newFolder = $this->subject->createFolder('subFolder/secondSubfolder', $parentFolder);
725  $this->assertEquals('secondSubfolder', $newFolder->getName());
726  $this->assertFileExists($this->getUrlInMount('/someFolder/subFolder/'));
727  $this->assertFileExists($this->getUrlInMount('/someFolder/subFolder/secondSubfolder/'));
728  }
729 
735  {
736  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
737  $this->prepareSubject([], true);
738  $mockedDriver = $this->createDriverMock([], $this->subject);
739  $mockedDriver->expects($this->once())->method('getRootLevelFolder')->with()->will($this->returnValue('/'));
740  $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('someFolder'));
741  $this->subject->createFolder('someFolder');
742  }
743 
749  {
750  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
751  $this->addToMount([
752  'existingFolder' => []
753  ]);
754  $this->initializeVfs();
755  $mockedDriver = $this->createDriverMock(['basePath' => $this->getMountRootUrl()], null, null);
756  $this->prepareSubject([], true, $mockedDriver);
757  $rootFolder = $this->subject->getFolder('/');
758  $newFolder = $this->subject->createFolder('existingFolder/someFolder', $rootFolder);
759  $this->assertEquals('someFolder', $newFolder->getName());
760  $this->assertFileExists($this->getUrlInMount('existingFolder/someFolder'));
761  }
762 
767  {
768  $this->setExpectedException('InvalidArgumentException', '', 1325689164);
769  $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
770  $this->prepareSubject([], true);
771  $mockedDriver = $this->createDriverMock([], $this->subject);
772  $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(false));
773  $this->subject->createFolder('newFolder', $mockedParentFolder);
774  }
775 
780  {
781  $this->setExpectedException('InvalidArgumentException', '', 1325842622);
782  $this->prepareSubject([], true);
783  $mockedFile = $this->getSimpleFileMock('/someFile');
784  $this->subject->replaceFile($mockedFile, PATH_site . $this->getUniqueId());
785  }
786 
792  {
793  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
794  $folderIdentifier = $this->getUniqueId();
795  $this->addToMount([
796  $folderIdentifier => []
797  ]);
798  $this->prepareSubject([]);
799 
800  $role = $this->subject->getRole($this->getSimpleFolderMock('/' . $folderIdentifier . '/'));
801 
802  $this->assertSame(FolderInterface::ROLE_DEFAULT, $role);
803  }
804 
808  public function getProcessingRootFolderTest()
809  {
810  $this->prepareSubject([]);
811  $processingFolder = $this->subject->getProcessingFolder();
812 
813  $this->assertInstanceOf(Folder::class, $processingFolder);
814  }
815 
820  {
821  $mockedDriver = $this->createDriverMock(['basePath' => $this->getMountRootUrl()], null, null);
822  $this->prepareSubject([], true, $mockedDriver);
823  $mockedFile = $this->getSimpleFileMock('/someFile');
824 
825  $rootProcessingFolder = $this->subject->getProcessingFolder();
826  $processingFolder = $this->subject->getProcessingFolder($mockedFile);
827 
828  $this->assertInstanceOf(Folder::class, $processingFolder);
829  $this->assertNotEquals($rootProcessingFolder, $processingFolder);
830 
831  for ($i = ResourceStorage::PROCESSING_FOLDER_LEVELS; $i>0; $i--) {
832  $processingFolder = $processingFolder->getParentFolder();
833  }
834  $this->assertEquals($rootProcessingFolder, $processingFolder);
835  }
836 }
checkUserActionPermissionAcceptsArbitrarilyCasedArguments(array $permissions, $action, $type)
static array2xml(array $array, $NSprefix='', $level=0, $docTag='phparray', $spaceInd=0, array $options=[], array $stackData=[])
getSimpleFileMock($identifier, $mockedMethods=[])
static setSingletonInstance($className, SingletonInterface $instance)
prepareSubject(array $configuration, $mockPermissionChecks=false, AbstractDriver $driverObject=null, array $storageRecord=[])
fileExtensionPermissionIsWorkingCorrectly($fileName, array $configuration, $evaluatePermissions, $isAllowed)
static resetSingletonInstances(array $newSingletonInstances)
getSimpleFolderMock($identifier, $mockedMethods=[])
createDriverMock($driverConfiguration, ResourceStorage $storageObject=null, $mockedDriverMethods=[])
$driver
Definition: server.php:36
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']