2 declare(strict_types = 1);
19 use Prophecy\Argument;
55 protected function setUp():
void
59 $fileRepositoryMock = $this->createMock(FileRepository::class);
60 GeneralUtility::setSingletonInstance(
61 FileRepository::class,
64 $cacheManagerProphecy = $this->prophesize(CacheManager::class);
65 $cacheProphecy = $this->prophesize(FrontendInterface::class);
66 $cacheManagerProphecy->getCache(
'cache_runtime')->willReturn($cacheProphecy->reveal());
67 $cacheProphecy->get(Argument::cetera())->willReturn(
false);
68 $cacheProphecy->set(Argument::cetera())->willReturn(
false);
69 GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
84 bool $mockPermissionChecks =
false,
87 array $storageRecord = [],
88 array $mockedMethods = []
90 $permissionMethods = [
91 'assureFileAddPermissions',
92 'checkFolderActionPermission',
93 'checkFileActionPermission',
94 'checkUserActionPermission',
95 'checkFileExtensionPermission',
96 'isWithinFileMountBoundaries',
97 'assureFileRenamePermissions'
100 $overruleArray = [
'configuration' => $configuration];
102 if ($driverObject ===
null) {
103 $driverObject = $this->getMockForAbstractClass(AbstractDriver::class, [],
'',
false);
105 if ($resourceFactory ===
null) {
106 $resourceFactory = $this->createMock(ResourceFactory::class);
108 $mockedMethods[] =
'getResourceFactoryInstance';
109 if ($mockPermissionChecks) {
110 $mockedMethods = array_merge($mockedMethods, $permissionMethods);
112 $mockedMethods[] =
'getIndexer';
114 $this->subject = $this->getMockBuilder(ResourceStorage::class)
115 ->setMethods(array_unique($mockedMethods))
116 ->setConstructorArgs([$driverObject, $storageRecord])
118 $this->subject->expects($this->any())->method(
'getResourceFactoryInstance')->will($this->returnValue($resourceFactory));
119 $this->subject->expects($this->any())->method(
'getIndexer')->will($this->returnValue($this->createMock(Indexer::class)));
120 if ($mockPermissionChecks) {
121 foreach ($permissionMethods as $method) {
122 $this->subject->expects($this->any())->method($method)->will($this->returnValue(
true));
136 $flexFormArray = [
'data' => [
'sDEF' => [
'lDEF' => []]]];
137 foreach ($configuration as $key => $value) {
138 $flexFormArray[
'data'][
'sDEF'][
'lDEF'][$key] = [
'vDEF' => $value];
140 $configuration = GeneralUtility::array2xml($flexFormArray);
141 return $configuration;
155 $driverConfiguration,
157 array $mockedDriverMethods = []
161 if (!isset($driverConfiguration[
'basePath'])) {
165 if ($mockedDriverMethods ===
null) {
170 $driver = $this->getMockBuilder(LocalDriver::class)
171 ->setMethods($mockedDriverMethods)
172 ->setConstructorArgs([$driverConfiguration])
175 if ($storageObject !==
null) {
176 $storageObject->setDriver($driver);
178 $driver->setStorageUid(6);
179 $driver->processConfiguration();
180 $driver->initialize();
204 'only browsable' => [
211 'all capabilities' => [
236 $this->markTestSkipped(
'This test does way to much and is mocked incomplete. Skipped for now.');
238 'is_public' => $capabilities[
'public'],
239 'is_writable' => $capabilities[
'writable'],
240 'is_browsable' => $capabilities[
'browsable'],
245 'pathType' =>
'relative',
246 'basePath' =>
'fileadmin/',
251 $this->
prepareSubject([],
false, $mockedDriver,
null, $storageRecord);
253 $capabilities[
'public'],
254 $this->subject->isPublic(),
255 'Capability "public" is not correctly set.'
258 $capabilities[
'writable'],
259 $this->subject->isWritable(),
260 'Capability "writable" is not correctly set.'
263 $capabilities[
'browsable'],
264 $this->subject->isBrowsable(),
265 'Capability "browsable" is not correctly set.'
275 $this->markTestSkipped(
'This test does way to much and is mocked incomplete. Skipped for now.');
278 $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'fal'][
'defaultFilterCallbacks'],
279 $this->subject->getFileAndFolderNameFilters()
289 $mockedFolder = $this->createMock(Folder::class);
290 $this->expectException(\InvalidArgumentException::class);
291 $this->expectExceptionCode(1319552745);
293 $this->subject->addFile(
'/some/random/file', $mockedFolder);
302 $driver = $this->getMockBuilder(LocalDriver::class)
305 $mockedResourceFactory = $this->createMock(ResourceFactory::class);
307 $subject = $this->getMockBuilder(ResourceStorage::class)
308 ->setMethods([
'isOnline',
'getResourceFactoryInstance'])
309 ->setConstructorArgs([$driver, [
'configuration' => []]])
311 $subject->expects($this->once())->method(
'isOnline')->will($this->returnValue(
false));
312 $subject->expects($this->any())->method(
'getResourceFactoryInstance')->will($this->returnValue($mockedResourceFactory));
314 $sourceFileIdentifier =
'/sourceFile.ext';
317 $this->assertSame($result,
null);
328 'read action on readable/writable folder' => [
330 [
'r' =>
true,
'w' =>
true],
333 'read action on unreadable folder' => [
335 [
'r' =>
false,
'w' =>
true],
338 'write action on read-only folder' => [
340 [
'r' =>
true,
'w' =>
false],
355 array $permissionsFromDriver,
359 $mockedDriver = $this->createMock(LocalDriver::class);
360 $mockedDriver->expects($this->any())->method(
'getPermissions')->will($this->returnValue($permissionsFromDriver));
361 $mockedResourceFactory = $this->createMock(ResourceFactory::class);
363 $mockedFolder = $this->createMock(Folder::class);
366 $subject = $this->getMockBuilder(ResourceStorage::class)
367 ->setMethods([
'isWritable',
'isBrowsable',
'checkUserActionPermission',
'getResourceFactoryInstance'])
368 ->setConstructorArgs([$mockedDriver, []])
370 $subject->expects($this->any())->method(
'isWritable')->will($this->returnValue(
true));
371 $subject->expects($this->any())->method(
'isBrowsable')->will($this->returnValue(
true));
372 $subject->expects($this->any())->method(
'checkUserActionPermission')->will($this->returnValue(
true));
373 $subject->expects($this->any())->method(
'getResourceFactoryInstance')->will($this->returnValue($mockedResourceFactory));
385 $this->assertTrue($this->subject->checkUserActionPermission(
'read',
'folder'));
394 $this->subject->setUserPermissions([
'readFolder' =>
true,
'writeFile' =>
true]);
395 $this->assertTrue($this->subject->checkUserActionPermission(
'read',
'folder'));
404 'all lower cased' => [
405 [
'readFolder' =>
true],
409 'all upper case' => [
410 [
'readFolder' =>
true],
415 [
'readFolder' =>
true],
432 $this->subject->setUserPermissions($permissions);
433 $this->assertTrue($this->subject->checkUserActionPermission($action, $type));
442 $this->subject->setEvaluatePermissions(
true);
443 $this->subject->setUserPermissions([
'readFolder' =>
false]);
444 $this->assertFalse($this->subject->checkUserActionPermission(
'read',
'folder'));
453 $this->subject->setEvaluatePermissions(
true);
454 $this->subject->setUserPermissions([
'readFolder' =>
true]);
455 $this->assertFalse($this->subject->checkUserActionPermission(
'write',
'folder'));
463 $this->
prepareSubject([],
false,
null,
null, [], [
'isWithinProcessingFolder']);
464 $this->subject->setEvaluatePermissions(
true);
465 $this->assertFalse($this->subject->checkFileActionPermission(
'editMeta',
new File([
'identifier' =>
'/foo/bar.jpg'], $this->subject)));
473 $driverMock = $this->getMockForAbstractClass(AbstractDriver::class, [],
'',
false);
474 $this->
prepareSubject([],
false, $driverMock,
null, [], [
'isWithinProcessingFolder']);
476 $fileStub =
new File([
'identifier' =>
'/foo/bar.jpg'], $this->subject);
477 $folderStub =
new Folder($this->subject,
'/foo/',
'foo');
478 $driverMock->expects($this->once())
480 ->with($folderStub->getIdentifier(), $fileStub->getIdentifier())
483 $this->subject->setEvaluatePermissions(
true);
488 'folder' => $folderStub,
491 $this->inject($this->subject,
'fileMounts', $fileMounts);
492 $this->assertTrue($this->subject->checkFileActionPermission(
'editMeta', $fileStub));
500 $driverMock = $this->getMockForAbstractClass(AbstractDriver::class, [],
'',
false);
501 $this->
prepareSubject([],
false, $driverMock,
null, [], [
'isWithinProcessingFolder']);
503 $fileStub =
new File([
'identifier' =>
'/foo/bar.jpg'], $this->subject);
504 $folderStub =
new Folder($this->subject,
'/foo/',
'foo');
505 $driverMock->expects($this->once())
507 ->with($folderStub->getIdentifier(), $fileStub->getIdentifier())
510 $this->subject->setEvaluatePermissions(
true);
515 'folder' => $folderStub,
519 $this->inject($this->subject,
'fileMounts', $fileMounts);
520 $this->assertFalse($this->subject->checkFileActionPermission(
'editMeta', $fileStub));
529 $this->subject->setEvaluatePermissions(
false);
530 $this->assertFalse($this->subject->getEvaluatePermissions());
539 $this->subject->setEvaluatePermissions(
true);
540 $this->assertTrue($this->subject->getEvaluatePermissions());
550 $this->markTestSkipped(
'This test does way to much and is mocked incomplete. Skipped for now.');
552 $driverObject = $this->getMockForAbstractClass(AbstractDriver::class, [],
'',
false);
553 $this->subject = $this->getMockBuilder(ResourceStorage::class)
554 ->setMethods([
'getFileIndexRepository',
'checkFileActionPermission'])
555 ->setConstructorArgs([$driverObject, []])
557 $this->subject->expects($this->any())->method(
'checkFileActionPermission')->will($this->returnValue(
true));
568 'storage' => $fileInfo[
'storage'],
569 'identifier' => $fileInfo[
'identifier'],
570 'tstamp' => $fileInfo[
'mtime'],
571 'crdate' => $fileInfo[
'ctime'],
572 'mime_type' => $fileInfo[
'mimetype'],
573 'size' => $fileInfo[
'size'],
574 'name' => $fileInfo[
'name']
578 $mockedDriver = $this->getMockBuilder(LocalDriver::class)
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->createMock(FileIndexRepository::class);
585 $this->subject->expects($this->any())->method(
'getFileIndexRepository')->will($this->returnValue($indexFileRepositoryMock));
587 $mockedFile = $this->createMock(File::class);
588 $mockedFile->expects($this->any())->method(
'getIdentifier')->will($this->returnValue($fileInfo[
'identifier']));
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)));
595 $indexFileRepositoryMock->expects($this->never())->method(
'update');
596 $this->subject->setFileContents($mockedFile, $this->getUniqueId());
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';
624 $sourceDriver = $this->createMock(LocalDriver::class);
625 $sourceDriver->expects($this->once())->method(
'deleteFile')->with($this->equalTo($sourceFileIdentifier));
627 $sourceStorage =
new ResourceStorage($sourceDriver, [
'configuration' => $configuration]);
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->getMockBuilder(LocalDriver::class)
637 $mockedDriver->expects($this->once())->method(
'getFileInfoByIdentifier')->will($this->returnValue($fileInfoDummy));
638 $mockedDriver->expects($this->once())->method(
'addFile')->with(
641 $this->equalTo(
'file.ext')
642 )->will($this->returnValue(
'/targetFolder/file.ext'));
644 $subject = $this->getMockBuilder(ResourceStorage::class)
645 ->setMethods([
'assureFileMovePermissions'])
646 ->setConstructorArgs([$mockedDriver, [
'configuration' => $configuration]])
658 $this->markTestSkipped(
'This test does way to much and is mocked incomplete. Skipped for now.');
668 $this->subject->addFileMount(
'/mountFolder');
669 $this->assertEquals(1, count($this->subject->getFileMounts()));
670 $this->subject->isWithinFileMountBoundaries($mockedFile);
679 $this->markTestSkipped(
'This test does way to much and is mocked incomplete. Skipped for now.');
682 $mockedDriver->expects($this->once())->method(
'folderExists')->with($this->equalTo(
'/someFolder/'))->will($this->returnValue(
true));
683 $mockedDriver->expects($this->once())->method(
'createFolder')->with($this->equalTo(
'newFolder'))->will($this->returnValue($mockedParentFolder));
685 $this->subject->setDriver($mockedDriver);
686 $this->subject->createFolder(
'newFolder', $mockedParentFolder);
694 $this->expectException(\RuntimeException::class);
695 $this->expectExceptionCode(1325952534);
698 $folderMock = $this->createMock(Folder::class);
700 $mockedDriver = $this->getMockForAbstractClass(AbstractDriver::class);
701 $mockedDriver->expects($this->once())->method(
'isFolderEmpty')->will($this->returnValue(
false));
703 $subject = $this->getAccessibleMock(ResourceStorage::class, [
'checkFolderActionPermission'], [],
'',
false);
704 $subject->expects($this->any())->method(
'checkFolderActionPermission')->will($this->returnValue(
true));
705 $subject->_set(
'driver', $mockedDriver);
715 $this->markTestSkipped(
'This test does way to much and is mocked incomplete. Skipped for now.');
719 $mockedDriver->expects($this->once())->method(
'createFolder')->with(
720 $this->equalTo(
'newFolder'),
721 $this->equalTo(
'/someFolder/')
722 )->will($this->returnValue(
true));
723 $mockedDriver->expects($this->once())->method(
'folderExists')->with($this->equalTo(
'/someFolder/'))->will($this->returnValue(
true));
724 $this->subject->createFolder(
'newFolder', $mockedParentFolder);
733 $this->markTestSkipped(
'This test does way to much and is mocked incomplete. Skipped for now.');
737 $parentFolder = $this->subject->getFolder(
'/someFolder/');
738 $newFolder = $this->subject->createFolder(
'subFolder/secondSubfolder', $parentFolder);
739 $this->assertEquals(
'secondSubfolder', $newFolder->getName());
740 $this->assertFileExists($this->
getUrlInMount(
'/someFolder/subFolder/'));
741 $this->assertFileExists($this->
getUrlInMount(
'/someFolder/subFolder/secondSubfolder/'));
750 $this->markTestSkipped(
'This test does way to much and is mocked incomplete. Skipped for now.');
753 $mockedDriver->expects($this->once())->method(
'getRootLevelFolder')->with()->will($this->returnValue(
'/'));
754 $mockedDriver->expects($this->once())->method(
'createFolder')->with($this->equalTo(
'someFolder'));
755 $this->subject->createFolder(
'someFolder');
764 $this->markTestSkipped(
'This test does way to much and is mocked incomplete. Skipped for now.');
766 'existingFolder' => []
771 $rootFolder = $this->subject->getFolder(
'/');
772 $newFolder = $this->subject->createFolder(
'existingFolder/someFolder', $rootFolder);
773 $this->assertEquals(
'someFolder', $newFolder->getName());
774 $this->assertFileExists($this->
getUrlInMount(
'existingFolder/someFolder'));
782 $this->expectException(\InvalidArgumentException::class);
783 $this->expectExceptionCode(1325689164);
787 $mockedDriver->expects($this->once())->method(
'folderExists')->with($this->equalTo(
'/someFolder/'))->will($this->returnValue(
false));
788 $this->subject->createFolder(
'newFolder', $mockedParentFolder);
797 $mockedDriver->expects($this->once())->method(
'renameFile')->will($this->returnValue(
'bar'));
798 $this->
prepareSubject([],
true, $mockedDriver,
null, [], [
'emitPreFileRenameSignal',
'emitPostFileRenameSignal']);
800 $file =
new File([
'identifier' =>
'foo',
'name' =>
'foo'], $this->subject);
801 $result = $this->subject->renameFile($file,
'bar');
803 $result->updateProperties([
'name' => $result->getIdentifier()]);
804 $this->assertSame(
'bar', $result->getName());
818 $mockedDriver->expects($this->any())->method(
'sanitizeFileName')->will($this->onConsecutiveCalls(
822 $resourceFactory = $this->createMock(ResourceFactory::class);
829 [
'emitPreFileRenameSignal',
'emitPostFileRenameSignal',
'getUniqueName']
831 $resourceFactory->expects($this->once())->method(
'createFolderObject')->will($this->returnValue(
new Folder($this->subject,
'',
'')));
833 $file =
new File([
'identifier' =>
'foo',
'name' =>
'foo'], $this->subject);
834 $this->subject->expects($this->any())->method(
'getUniqueName')->will($this->returnValue(
'bar_01'));
835 $result = $this->subject->renameFile($file,
'bar');
837 $result->updateProperties([
'name' => $result->getIdentifier()]);
838 $this->assertSame(
'bar_01', $result->getName());
851 $this->
prepareSubject([],
true, $mockedDriver,
null, [], [
'emitPreFileRenameSignal',
'emitPostFileRenameSignal']);
853 $file =
new File([
'identifier' =>
'foo',
'name' =>
'foo'], $this->subject);
854 $this->expectException(ExistingTargetFileNameException::class);
868 $mockedDriver->expects($this->any())->method(
'sanitizeFileName')->will($this->returnValue(
'bar'));
869 $resourceFactory = $this->prophesize(ResourceFactory::class);
870 $this->
prepareSubject([],
true, $mockedDriver, $resourceFactory->reveal(), [], [
871 'emitPreFileRenameSignal',
872 'emitPostFileRenameSignal',
876 $this->subject->expects($this->once())->method(
'getPublicUrl')->will($this->returnValue(
'somePath'));
877 $file = $this->prophesize(FileInterface::class);
878 $resourceFactory->getFileObjectFromCombinedIdentifier(Argument::any())->willReturn($file->reveal());
879 $this->subject->expects($this->once())->method(
'replaceFile')->will($this->returnValue($file->reveal()));
881 $file =
new File([
'identifier' =>
'foo',
'name' =>
'foo',
'missing' =>
false], $this->subject);