‪TYPO3CMS  10.4
ResourceStorageTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Prophecy\Argument;
21 use Psr\EventDispatcher\EventDispatcherInterface;
39 
44 {
48  protected ‪$resetSingletonInstances = true;
49 
53  protected ‪$subject;
54 
58  protected ‪$eventDispatcher;
59 
63  protected function ‪setUp(): void
64  {
65  parent::setUp();
67  $fileRepositoryMock = $this->createMock(FileRepository::class);
68  GeneralUtility::setSingletonInstance(
69  FileRepository::class,
70  $fileRepositoryMock
71  );
72  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
73  $cacheProphecy = $this->prophesize(FrontendInterface::class);
74  $cacheManagerProphecy->getCache('runtime')->willReturn($cacheProphecy->reveal());
75  $cacheProphecy->get(Argument::cetera())->willReturn(false);
76  $cacheProphecy->set(Argument::cetera())->willReturn(false);
77  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
78  ‪$eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
79  ‪$eventDispatcher->dispatch(Argument::cetera())->willReturnArgument(0);
80  $this->eventDispatcher = ‪$eventDispatcher->reveal();
81  }
82 
93  protected function ‪prepareSubject(
94  array $configuration,
95  bool $mockPermissionChecks = false,
96  ‪AbstractDriver $driverObject = null,
97  ‪ResourceFactory $resourceFactory = null,
98  array $storageRecord = [],
99  array $mockedMethods = []
100  ): void {
101  $permissionMethods = [
102  'assureFileAddPermissions',
103  'checkFolderActionPermission',
104  'checkFileActionPermission',
105  'checkUserActionPermission',
106  'checkFileExtensionPermission',
107  'isWithinFileMountBoundaries',
108  'assureFileRenamePermissions'
109  ];
110  $configuration = $this->‪convertConfigurationArrayToFlexformXml($configuration);
111  $overruleArray = ['configuration' => $configuration];
112  ‪ArrayUtility::mergeRecursiveWithOverrule($storageRecord, $overruleArray);
113  if ($driverObject === null) {
114  $driverObject = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
115  }
116  if ($resourceFactory === null) {
117  $resourceFactory = $this->createMock(ResourceFactory::class);
118  }
119  $mockedMethods[] = 'getResourceFactoryInstance';
120  if ($mockPermissionChecks) {
121  $mockedMethods = array_merge($mockedMethods, $permissionMethods);
122  }
123  $mockedMethods[] = 'getIndexer';
124 
125  $this->subject = $this->getMockBuilder(ResourceStorage::class)
126  ->setMethods(array_unique($mockedMethods))
127  ->setConstructorArgs([$driverObject, $storageRecord, $this->eventDispatcher])
128  ->getMock();
129  $this->subject->expects(self::any())->method('getResourceFactoryInstance')->willReturn($resourceFactory);
130  $this->subject->expects(self::any())->method('getIndexer')->willReturn($this->createMock(Indexer::class));
131  if ($mockPermissionChecks) {
132  foreach ($permissionMethods as $method) {
133  $this->subject->expects(self::any())->method($method)->willReturn(true);
134  }
135  }
136  }
137 
145  protected function ‪convertConfigurationArrayToFlexformXml(array $configuration): string
146  {
147  $flexFormArray = ['data' => ['sDEF' => ['lDEF' => []]]];
148  foreach ($configuration as $key => $value) {
149  $flexFormArray['data']['sDEF']['lDEF'][$key] = ['vDEF' => $value];
150  }
151  $configuration = GeneralUtility::array2xml($flexFormArray);
152  return $configuration;
153  }
154 
165  protected function ‪createDriverMock(
166  $driverConfiguration,
167  ‪ResourceStorage $storageObject = null,
168  array $mockedDriverMethods = []
169  ) {
170  $this->‪initializeVfs();
171 
172  if (!isset($driverConfiguration['basePath'])) {
173  $driverConfiguration['basePath'] = $this->‪getMountRootUrl();
174  }
175 
176  if ($mockedDriverMethods === null) {
177  $driver = new ‪LocalDriver($driverConfiguration);
178  } else {
179  // We are using the LocalDriver here because PHPUnit can't mock concrete methods in abstract classes, so
180  // when using the AbstractDriver we would be in trouble when wanting to mock away some concrete method
181  $driver = $this->getMockBuilder(LocalDriver::class)
182  ->setMethods($mockedDriverMethods)
183  ->setConstructorArgs([$driverConfiguration])
184  ->getMock();
185  }
186  if ($storageObject !== null) {
187  $storageObject->setDriver($driver);
188  }
189  $driver->setStorageUid(6);
190  $driver->processConfiguration();
191  $driver->initialize();
192  return $driver;
193  }
194 
198  public function ‪capabilitiesDataProvider(): array
199  {
200  return [
201  'only public' => [
202  [
203  'public' => true,
204  'writable' => false,
205  'browsable' => false
206  ]
207  ],
208  'only writable' => [
209  [
210  'public' => false,
211  'writable' => true,
212  'browsable' => false
213  ]
214  ],
215  'only browsable' => [
216  [
217  'public' => false,
218  'writable' => false,
219  'browsable' => true
220  ]
221  ],
222  'all capabilities' => [
223  [
224  'public' => true,
225  'writable' => true,
226  'browsable' => true
227  ]
228  ],
229  'none' => [
230  [
231  'public' => false,
232  'writable' => false,
233  'browsable' => false
234  ]
235  ]
236  ];
237  }
238 
245  public function ‪capabilitiesOfStorageObjectAreCorrectlySet(array $capabilities): void
246  {
247  self::markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
248  $storageRecord = [
249  'is_public' => $capabilities['public'],
250  'is_writable' => $capabilities['writable'],
251  'is_browsable' => $capabilities['browsable'],
252  'is_online' => true
253  ];
254  $mockedDriver = $this->‪createDriverMock(
255  [
256  'pathType' => 'relative',
257  'basePath' => 'fileadmin/',
258  ],
259  $this->subject,
260  null
261  );
262  $this->‪prepareSubject([], false, $mockedDriver, null, $storageRecord);
263  self::assertEquals(
264  $capabilities['public'],
265  $this->subject->isPublic(),
266  'Capability "public" is not correctly set.'
267  );
268  self::assertEquals(
269  $capabilities['writable'],
270  $this->subject->isWritable(),
271  'Capability "writable" is not correctly set.'
272  );
273  self::assertEquals(
274  $capabilities['browsable'],
275  $this->subject->isBrowsable(),
276  'Capability "browsable" is not correctly set.'
277  );
278  }
279 
285  {
286  self::markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
287  $this->‪prepareSubject([]);
288  self::assertEquals(
289  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['defaultFilterCallbacks'],
290  $this->subject->getFileAndFolderNameFilters()
291  );
292  }
293 
297  public function ‪addFileFailsIfFileDoesNotExist(): void
298  {
300  $mockedFolder = $this->createMock(Folder::class);
301  $this->expectException(\InvalidArgumentException::class);
302  $this->expectExceptionCode(1319552745);
303  $this->‪prepareSubject([]);
304  $this->subject->addFile('/some/random/file', $mockedFolder);
305  }
306 
310  public function ‪getPublicUrlReturnsNullIfStorageIsNotOnline(): void
311  {
313  $driver = $this->getMockBuilder(LocalDriver::class)
314  ->setConstructorArgs([['basePath' => $this->‪getMountRootUrl()]])
315  ->getMock();
316  $mockedResourceFactory = $this->createMock(ResourceFactory::class);
318  ‪$subject = $this->getMockBuilder(ResourceStorage::class)
319  ->setMethods(['isOnline', 'getResourceFactoryInstance'])
320  ->setConstructorArgs([$driver, ['configuration' => []], $this->eventDispatcher])
321  ->getMock();
322  ‪$subject->expects(self::once())->method('isOnline')->willReturn(false);
323  ‪$subject->expects(self::any())->method('getResourceFactoryInstance')->willReturn($mockedResourceFactory);
324 
325  $sourceFileIdentifier = '/sourceFile.ext';
326  $sourceFile = $this->‪getSimpleFileMock($sourceFileIdentifier);
327  $result = ‪$subject->‪getPublicUrl($sourceFile);
328  self::assertSame($result, null);
329  }
330 
337  {
338  return [
339  'read action on readable/writable folder' => [
340  'read',
341  ['r' => true, 'w' => true],
342  true
343  ],
344  'read action on unreadable folder' => [
345  'read',
346  ['r' => false, 'w' => true],
347  false
348  ],
349  'write action on read-only folder' => [
350  'write',
351  ['r' => true, 'w' => false],
352  false
353  ]
354  ];
355  }
356 
365  string $action,
366  array $permissionsFromDriver,
367  bool $expectedResult
368  ): void {
370  $mockedDriver = $this->createMock(LocalDriver::class);
371  $mockedDriver->expects(self::any())->method('getPermissions')->willReturn($permissionsFromDriver);
372  $mockedResourceFactory = $this->createMock(ResourceFactory::class);
374  $mockedFolder = $this->createMock(Folder::class);
375  // Let all other checks pass
377  ‪$subject = $this->getMockBuilder(ResourceStorage::class)
378  ->setMethods(['isWritable', 'isBrowsable', 'checkUserActionPermission', 'getResourceFactoryInstance'])
379  ->setConstructorArgs([$mockedDriver, [], $this->eventDispatcher])
380  ->getMock();
381  ‪$subject->expects(self::any())->method('isWritable')->willReturn(true);
382  ‪$subject->expects(self::any())->method('isBrowsable')->willReturn(true);
383  ‪$subject->expects(self::any())->method('checkUserActionPermission')->willReturn(true);
384  ‪$subject->expects(self::any())->method('getResourceFactoryInstance')->willReturn($mockedResourceFactory);
385  ‪$subject->‪setDriver($mockedDriver);
386 
387  self::assertSame($expectedResult, ‪$subject->‪checkFolderActionPermission($action, $mockedFolder));
388  }
389 
394  {
395  $this->‪prepareSubject([]);
396  self::assertTrue($this->subject->checkUserActionPermission('read', 'folder'));
397  }
398 
403  {
404  $this->‪prepareSubject([]);
405  $this->subject->setUserPermissions(['readFolder' => true, 'writeFile' => true]);
406  self::assertTrue($this->subject->checkUserActionPermission('read', 'folder'));
407  }
408 
413  {
414  return [
415  'all lower cased' => [
416  ['readFolder' => true],
417  'read',
418  'folder'
419  ],
420  'all upper case' => [
421  ['readFolder' => true],
422  'READ',
423  'FOLDER'
424  ],
425  'mixed case' => [
426  ['readFolder' => true],
427  'ReaD',
428  'FoLdEr'
429  ]
430  ];
431  }
432 
440  public function ‪checkUserActionPermissionAcceptsArbitrarilyCasedArguments(array $permissions, string $action, string $type): void
441  {
442  $this->‪prepareSubject([]);
443  $this->subject->setUserPermissions($permissions);
444  self::assertTrue($this->subject->checkUserActionPermission($action, $type));
445  }
446 
451  {
452  $this->‪prepareSubject([]);
453  $this->subject->setEvaluatePermissions(true);
454  $this->subject->setUserPermissions(['readFolder' => false]);
455  self::assertFalse($this->subject->checkUserActionPermission('read', 'folder'));
456  }
457 
461  public function ‪userActionIsDisallowedIfPermissionIsNotSet(): void
462  {
463  $this->‪prepareSubject([]);
464  $this->subject->setEvaluatePermissions(true);
465  $this->subject->setUserPermissions(['readFolder' => true]);
466  self::assertFalse($this->subject->checkUserActionPermission('write', 'folder'));
467  }
468 
473  {
474  $this->‪prepareSubject([], false, null, null, [], ['isWithinProcessingFolder']);
475  $this->subject->setEvaluatePermissions(true);
476  self::assertFalse($this->subject->checkFileActionPermission('editMeta', new ‪File(['identifier' => '/foo/bar.jpg'], $this->subject)));
477  }
478 
482  public function ‪metaDataEditIsAllowedWhenWhenInFileMount(): void
483  {
484  $driverMock = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
485  $resourceFactory = $this->prophesize(ResourceFactory::class);
486  $this->‪prepareSubject([], false, $driverMock, $resourceFactory->reveal(), [], ['isWithinProcessingFolder']);
487 
488  $folderStub = new ‪Folder($this->subject, '/foo/', 'foo');
489  $resourceFactory->createFolderObject(Argument::cetera())->willReturn($folderStub);
490  $fileStub = new ‪File(['identifier' => '/foo/bar.jpg', 'name' => 'bar.jpg'], $this->subject);
491  $driverMock->expects(self::once())
492  ->method('isWithin')
493  ->with($folderStub->getIdentifier(), $fileStub->getIdentifier())
494  ->willReturn(true);
495  $driverMock->expects(self::once())
496  ->method('getFolderInfoByIdentifier')
497  ->with($folderStub->getIdentifier())
498  ->willReturn(['identifier' => $folderStub->getIdentifier(), 'name' => $folderStub->getName()]);
499 
500  $this->subject->setEvaluatePermissions(true);
501  $this->subject->addFileMount('/foo/', [
502  'path' => '/foo/',
503  'title' => 'Foo',
504  'folder' => $folderStub,
505  ]);
506  self::assertTrue($this->subject->checkFileActionPermission('editMeta', $fileStub));
507  }
508 
513  {
514  $driverMock = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
515  $resourceFactory = $this->prophesize(ResourceFactory::class);
516  $this->‪prepareSubject([], false, $driverMock, $resourceFactory->reveal(), [], ['isWithinProcessingFolder']);
517 
518  $fileStub = new ‪File(['identifier' => '/foo/bar.jpg', 'name' => 'bar.jpg'], $this->subject);
519  $folderStub = new ‪Folder($this->subject, '/foo/', 'foo');
520  $resourceFactory->createFolderObject(Argument::cetera())->willReturn($folderStub);
521  $driverMock->expects(self::once())
522  ->method('isWithin')
523  ->with($folderStub->getIdentifier(), $fileStub->getIdentifier())
524  ->willReturn(true);
525  $driverMock->expects(self::once())
526  ->method('getFolderInfoByIdentifier')
527  ->with($folderStub->getIdentifier())
528  ->willReturn(['identifier' => $folderStub->getIdentifier(), 'name' => $folderStub->getName()]);
529 
530  $this->subject->setEvaluatePermissions(true);
531  $this->subject->addFileMount('/foo/', [
532  'path' => '/foo/',
533  'title' => 'Foo',
534  'folder' => $folderStub,
535  'read_only' => true,
536  ]);
537  self::assertFalse($this->subject->checkFileActionPermission('editMeta', $fileStub));
538  }
539 
543  public function ‪getEvaluatePermissionsWhenSetFalse(): void
544  {
545  $this->‪prepareSubject([]);
546  $this->subject->setEvaluatePermissions(false);
547  self::assertFalse($this->subject->getEvaluatePermissions());
548  }
549 
553  public function ‪getEvaluatePermissionsWhenSetTrue(): void
554  {
555  $this->‪prepareSubject([]);
556  $this->subject->setEvaluatePermissions(true);
557  self::assertTrue($this->subject->getEvaluatePermissions());
558  }
559 
565  public function ‪setFileContentsUpdatesObjectProperties(): void
566  {
567  self::markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
568  $this->‪initializeVfs();
569  $driverObject = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
570  $this->subject = $this->getMockBuilder(ResourceStorage::class)
571  ->setMethods(['getFileIndexRepository', 'checkFileActionPermission'])
572  ->setConstructorArgs([$driverObject, [], $this->eventDispatcher])
573  ->getMock();
574  $this->subject->expects(self::any())->method('checkFileActionPermission')->willReturn(true);
575  $fileInfo = [
576  'storage' => 'A',
577  'identifier' => 'B',
578  'mtime' => 'C',
579  'ctime' => 'D',
580  'mimetype' => 'E',
581  'size' => 'F',
582  'name' => 'G',
583  ];
584  $newProperties = [
585  'storage' => $fileInfo['storage'],
586  'identifier' => $fileInfo['identifier'],
587  'tstamp' => $fileInfo['mtime'],
588  'crdate' => $fileInfo['ctime'],
589  'mime_type' => $fileInfo['mimetype'],
590  'size' => $fileInfo['size'],
591  'name' => $fileInfo['name']
592  ];
593  $hash = 'asdfg';
595  $mockedDriver = $this->getMockBuilder(LocalDriver::class)
596  ->setConstructorArgs([['basePath' => $this->‪getMountRootUrl()]])
597  ->getMock();
598  $mockedDriver->expects(self::once())->method('getFileInfoByIdentifier')->willReturn($fileInfo);
599  $mockedDriver->expects(self::once())->method('hash')->willReturn($hash);
600  $this->subject->setDriver($mockedDriver);
601  $indexFileRepositoryMock = $this->createMock(FileIndexRepository::class);
602  $this->subject->expects(self::any())->method('getFileIndexRepository')->willReturn($indexFileRepositoryMock);
604  $mockedFile = $this->createMock(File::class);
605  $mockedFile->expects(self::any())->method('getIdentifier')->willReturn($fileInfo['identifier']);
606  // called by indexer because the properties are updated
607  $this->subject->expects(self::any())->method('getFileInfoByIdentifier')->willReturn($newProperties);
608  $mockedFile->expects(self::any())->method('getStorage')->willReturn($this->subject);
609  $mockedFile->expects(self::any())->method('getProperties')->willReturn(array_keys($fileInfo));
610  $mockedFile->expects(self::any())->method('getUpdatedProperties')->willReturn(array_keys($newProperties));
611  // do not update directly; that's up to the indexer
612  $indexFileRepositoryMock->expects(self::never())->method('update');
613  $this->subject->setFileContents($mockedFile, ‪StringUtility::getUniqueId('content_'));
614  }
615 
622  {
623  self::markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
624  $localFilePath = '/path/to/localFile';
625  $sourceFileIdentifier = '/sourceFile.ext';
626  $fileInfoDummy = [
627  'storage' => 'A',
628  'identifier' => 'B',
629  'mtime' => 'C',
630  'ctime' => 'D',
631  'mimetype' => 'E',
632  'size' => 'F',
633  'name' => 'G',
634  ];
635  $this->‪addToMount([
636  'targetFolder' => []
637  ]);
638  $this->‪initializeVfs();
639  $targetFolder = $this->‪getSimpleFolderMock('/targetFolder/');
641  $sourceDriver = $this->createMock(LocalDriver::class);
642  $sourceDriver->expects(self::once())->method('deleteFile')->with(self::equalTo($sourceFileIdentifier));
643  $configuration = $this->‪convertConfigurationArrayToFlexformXml([]);
644  $sourceStorage = new ‪ResourceStorage($sourceDriver, ['configuration' => $configuration]);
645  $sourceFile = $this->‪getSimpleFileMock($sourceFileIdentifier);
646  $sourceFile->expects(self::once())->method('getForLocalProcessing')->willReturn($localFilePath);
647  $sourceFile->expects(self::any())->method('getStorage')->willReturn($sourceStorage);
648  $sourceFile->expects(self::once())->method('getUpdatedProperties')->willReturn(array_keys($fileInfoDummy));
649  $sourceFile->expects(self::once())->method('getProperties')->willReturn($fileInfoDummy);
651  $mockedDriver = $this->getMockBuilder(LocalDriver::class)
652  ->setConstructorArgs([['basePath' => $this->‪getMountRootUrl()]])
653  ->getMock();
654  $mockedDriver->expects(self::once())->method('getFileInfoByIdentifier')->willReturn($fileInfoDummy);
655  $mockedDriver->expects(self::once())->method('addFile')->with(
656  $localFilePath,
657  '/targetFolder/',
658  self::equalTo('file.ext')
659  )->willReturn('/targetFolder/file.ext');
661  ‪$subject = $this->getMockBuilder(ResourceStorage::class)
662  ->setMethods(['assureFileMovePermissions'])
663  ->setConstructorArgs([$mockedDriver, ['configuration' => $configuration], $this->eventDispatcher])
664  ->getMock();
665  ‪$subject->‪moveFile($sourceFile, $targetFolder, 'file.ext');
666  }
667 
674  {
675  self::markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
676  $mockedFile = $this->‪getSimpleFileMock('/mountFolder/file');
677  $this->‪addToMount([
678  'mountFolder' => [
679  'file' => 'asdfg'
680  ]
681  ]);
682  $mockedDriver = $this->‪createDriverMock(['basePath' => $this->‪getMountRootUrl()], null, null);
683  $this->‪initializeVfs();
684  $this->‪prepareSubject([], null, $mockedDriver);
685  $this->subject->addFileMount('/mountFolder');
686  self::assertEquals(1, count($this->subject->getFileMounts()));
687  $this->subject->isWithinFileMountBoundaries($mockedFile);
688  }
689 
695  {
696  self::markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
697  $mockedParentFolder = $this->‪getSimpleFolderMock('/someFolder/');
698  $mockedDriver = $this->‪createDriverMock([]);
699  $mockedDriver->expects(self::once())->method('folderExists')->with(self::equalTo('/someFolder/'))->willReturn(true);
700  $mockedDriver->expects(self::once())->method('createFolder')->with(self::equalTo('newFolder'))->willReturn($mockedParentFolder);
701  $this->‪prepareSubject([], true);
702  $this->subject->setDriver($mockedDriver);
703  $this->subject->createFolder('newFolder', $mockedParentFolder);
704  }
705 
710  {
711  $this->expectException(\RuntimeException::class);
712  $this->expectExceptionCode(1325952534);
713 
715  $folderMock = $this->createMock(Folder::class);
717  $mockedDriver = $this->getMockForAbstractClass(AbstractDriver::class);
718  $mockedDriver->expects(self::once())->method('isFolderEmpty')->willReturn(false);
720  ‪$subject = $this->getAccessibleMock(ResourceStorage::class, ['checkFolderActionPermission'], [], '', false);
721  ‪$subject->expects(self::any())->method('checkFolderActionPermission')->willReturn(true);
722  ‪$subject->_set('driver', $mockedDriver);
723  ‪$subject->‪deleteFolder($folderMock, false);
724  }
725 
730  public function ‪createFolderCallsDriverForFolderCreation(): void
731  {
732  self::markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
733  $mockedParentFolder = $this->‪getSimpleFolderMock('/someFolder/');
734  $this->‪prepareSubject([], true);
735  $mockedDriver = $this->‪createDriverMock([], $this->subject);
736  $mockedDriver->expects(self::once())->method('createFolder')->with(
737  self::equalTo('newFolder'),
738  self::equalTo('/someFolder/')
739  )->willReturn(true);
740  $mockedDriver->expects(self::once())->method('folderExists')->with(self::equalTo('/someFolder/'))->willReturn(true);
741  $this->subject->createFolder('newFolder', $mockedParentFolder);
742  }
743 
748  public function ‪createFolderCanRecursivelyCreateFolders(): void
749  {
750  self::markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
751  $this->‪addToMount(['someFolder' => []]);
752  $mockedDriver = $this->‪createDriverMock(['basePath' => $this->‪getMountRootUrl()], null, null);
753  $this->‪prepareSubject([], true, $mockedDriver);
754  $parentFolder = $this->subject->getFolder('/someFolder/');
755  $newFolder = $this->subject->createFolder('subFolder/secondSubfolder', $parentFolder);
756  self::assertEquals('secondSubfolder', $newFolder->getName());
757  self::assertFileExists($this->‪getUrlInMount('/someFolder/subFolder/'));
758  self::assertFileExists($this->‪getUrlInMount('/someFolder/subFolder/secondSubfolder/'));
759  }
760 
766  {
767  self::markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
768  $this->‪prepareSubject([], true);
769  $mockedDriver = $this->‪createDriverMock([], $this->subject);
770  $mockedDriver->expects(self::once())->method('getRootLevelFolder')->with()->willReturn('/');
771  $mockedDriver->expects(self::once())->method('createFolder')->with(self::equalTo('someFolder'));
772  $this->subject->createFolder('someFolder');
773  }
774 
780  {
781  self::markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
782  $this->‪addToMount([
783  'existingFolder' => []
784  ]);
785  $this->‪initializeVfs();
786  $mockedDriver = $this->‪createDriverMock(['basePath' => $this->‪getMountRootUrl()], null, null);
787  $this->‪prepareSubject([], true, $mockedDriver);
788  $rootFolder = $this->subject->getFolder('/');
789  $newFolder = $this->subject->createFolder('existingFolder/someFolder', $rootFolder);
790  self::assertEquals('someFolder', $newFolder->getName());
791  self::assertFileExists($this->‪getUrlInMount('existingFolder/someFolder'));
792  }
793 
798  {
799  $this->expectException(\InvalidArgumentException::class);
800  $this->expectExceptionCode(1325689164);
801  $mockedParentFolder = $this->‪getSimpleFolderMock('/someFolder/');
802  $this->‪prepareSubject([], true);
803  $mockedDriver = $this->‪createDriverMock([], $this->subject);
804  $mockedDriver->expects(self::once())->method('folderExists')->with(self::equalTo('/someFolder/'))->willReturn(false);
805  $this->subject->createFolder('newFolder', $mockedParentFolder);
806  }
807 
811  public function ‪renameFileRenamesFileAsRequested(): void
812  {
813  $mockedDriver = $this->‪createDriverMock([], $this->subject);
814  $mockedDriver->expects(self::once())->method('renameFile')->willReturn('bar');
815  $this->‪prepareSubject([], true, $mockedDriver, null);
817  $file = new ‪File(['identifier' => 'foo', 'name' => 'foo'], $this->subject);
818  $result = $this->subject->renameFile($file, 'bar');
819  // fake what the indexer does in updateIndexEntry
820  $result->updateProperties(['name' => $result->getIdentifier()]);
821  self::assertSame('bar', $result->getName());
822  }
823 
828  {
829  $mockedDriver = $this->‪createDriverMock([], $this->subject);
830  $mockedDriver->expects(self::any())->method('renameFile')->will(self::onConsecutiveCalls(self::throwException(new ‪ExistingTargetFileNameException(
831  'foo',
832  1489593090
833  )), 'bar_01'));
834  $mockedDriver->expects(self::any())->method('sanitizeFileName')->will(self::onConsecutiveCalls(
835  'bar',
836  'bar_01'
837  ));
838  $resourceFactory = $this->createMock(ResourceFactory::class);
839  $this->‪prepareSubject(
840  [],
841  true,
842  $mockedDriver,
843  $resourceFactory,
844  [],
845  ['getUniqueName']
846  );
847  $resourceFactory->expects(self::once())->method('createFolderObject')->willReturn(new ‪Folder($this->subject, '', ''));
849  $file = new ‪File(['identifier' => 'foo', 'name' => 'foo'], $this->subject);
850  $this->subject->expects(self::any())->method('getUniqueName')->willReturn('bar_01');
851  $result = $this->subject->renameFile($file, 'bar');
852  // fake what the indexer does in updateIndexEntry
853  $result->updateProperties(['name' => $result->getIdentifier()]);
854  self::assertSame('bar_01', $result->getName());
855  }
856 
861  {
862  $mockedDriver = $this->‪createDriverMock([], $this->subject);
863  $mockedDriver->expects(self::once())->method('renameFile')->will(self::throwException(new ‪ExistingTargetFileNameException(
864  'foo',
865  1489593099
866  )));
867  $this->‪prepareSubject([], true, $mockedDriver);
869  $file = new ‪File(['identifier' => 'foo', 'name' => 'foo'], $this->subject);
870  $this->expectException(ExistingTargetFileNameException::class);
871  $this->subject->renameFile($file, 'bar', ‪DuplicationBehavior::CANCEL);
872  }
873 
878  {
879  $mockedDriver = $this->‪createDriverMock([], $this->subject);
880  $mockedDriver->expects(self::once())->method('renameFile')->will(self::throwException(new ‪ExistingTargetFileNameException(
881  'foo',
882  1489593098
883  )));
884  $mockedDriver->expects(self::any())->method('sanitizeFileName')->willReturn('bar');
885  $resourceFactory = $this->prophesize(ResourceFactory::class);
886  $this->‪prepareSubject([], true, $mockedDriver, $resourceFactory->reveal(), [], [
887  'replaceFile',
888  'getPublicUrl',
889  ]);
890  $this->subject->expects(self::once())->method('getPublicUrl')->willReturn('somePath');
891  $file = $this->prophesize(FileInterface::class);
892  $resourceFactory->getFileObjectFromCombinedIdentifier(Argument::any())->willReturn($file->reveal());
893  $this->subject->expects(self::once())->method('replaceFile')->willReturn($file->reveal());
895  $file = new ‪File(['identifier' => 'foo', 'name' => 'foo', 'missing' => false], $this->subject);
896  $this->subject->renameFile($file, 'bar', ‪DuplicationBehavior::REPLACE);
897  }
898 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\renameFileRenamesFileAsRequested
‪renameFileRenamesFileAsRequested()
Definition: ResourceStorageTest.php:808
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\checkFolderPermissionsRespectsFilesystemPermissions
‪checkFolderPermissionsRespectsFilesystemPermissions(string $action, array $permissionsFromDriver, bool $expectedResult)
Definition: ResourceStorageTest.php:361
‪TYPO3\CMS\Core\Resource\ResourceStorage\deleteFolder
‪bool deleteFolder($folderObject, $deleteRecursively=false)
Definition: ResourceStorage.php:2357
‪TYPO3\CMS\Core\Resource\Index\FileIndexRepository
Definition: FileIndexRepository.php:45
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\createDriverMock
‪TYPO3 CMS Core Resource Driver LocalDriver PHPUnit Framework MockObject MockObject createDriverMock( $driverConfiguration, ResourceStorage $storageObject=null, array $mockedDriverMethods=[])
Definition: ResourceStorageTest.php:162
‪TYPO3\CMS\Core\Resource\DuplicationBehavior
Definition: DuplicationBehavior.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\capabilitiesOfStorageObjectAreCorrectlySet
‪capabilitiesOfStorageObjectAreCorrectlySet(array $capabilities)
Definition: ResourceStorageTest.php:242
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\checkUserActionPermissionReturnsFalseIfPermissionIsSetToZero
‪checkUserActionPermissionReturnsFalseIfPermissionIsSetToZero()
Definition: ResourceStorageTest.php:399
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\capabilitiesDataProvider
‪array capabilitiesDataProvider()
Definition: ResourceStorageTest.php:195
‪TYPO3\CMS\Core\Resource\DuplicationBehavior\CANCEL
‪const CANCEL
Definition: DuplicationBehavior.php:46
‪TYPO3\CMS\Core\Resource\ResourceStorage\getPublicUrl
‪string null getPublicUrl(ResourceInterface $resourceObject, $relativeToCurrentScript=false)
Definition: ResourceStorage.php:1369
‪TYPO3\CMS\Core\Resource\FileInterface
Definition: FileInterface.php:22
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\checkUserActionPermissionsAlwaysReturnsTrueIfNoUserPermissionsAreSet
‪checkUserActionPermissionsAlwaysReturnsTrueIfNoUserPermissionsAreSet()
Definition: ResourceStorageTest.php:390
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\setFileContentsUpdatesObjectProperties
‪setFileContentsUpdatesObjectProperties()
Definition: ResourceStorageTest.php:562
‪TYPO3\CMS\Core\Resource\Driver\LocalDriver
Definition: LocalDriver.php:41
‪TYPO3\CMS\Core\Resource\Index\Indexer
Definition: Indexer.php:34
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\renameFileThrowsExceptionIfConflictAndConflictModeIsCancel
‪renameFileThrowsExceptionIfConflictAndConflictModeIsCancel()
Definition: ResourceStorageTest.php:857
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase
Definition: BaseTestCase.php:29
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\userActionIsDisallowedIfPermissionIsSetToFalse
‪userActionIsDisallowedIfPermissionIsSetToFalse()
Definition: ResourceStorageTest.php:447
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\fileAndFolderListFiltersAreInitializedWithDefaultFilters
‪fileAndFolderListFiltersAreInitializedWithDefaultFilters()
Definition: ResourceStorageTest.php:281
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\renameFileReplacesIfConflictAndConflictModeIsReplace
‪renameFileReplacesIfConflictAndConflictModeIsReplace()
Definition: ResourceStorageTest.php:874
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\deleteFolderThrowsExceptionIfFolderIsNotEmptyAndRecursiveDeleteIsDisabled
‪deleteFolderThrowsExceptionIfFolderIsNotEmptyAndRecursiveDeleteIsDisabled()
Definition: ResourceStorageTest.php:706
‪TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException
Definition: ExistingTargetFileNameException.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\metaDataEditIsNotAllowedWhenWhenNoFileMountsAreSet
‪metaDataEditIsNotAllowedWhenWhenNoFileMountsAreSet()
Definition: ResourceStorageTest.php:469
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:654
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\renameFileRenamesWithUniqueNameIfConflictAndConflictModeIsRename
‪renameFileRenamesWithUniqueNameIfConflictAndConflictModeIsRename()
Definition: ResourceStorageTest.php:824
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\getPublicUrlReturnsNullIfStorageIsNotOnline
‪getPublicUrlReturnsNullIfStorageIsNotOnline()
Definition: ResourceStorageTest.php:307
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\metaDataEditIsNotAllowedWhenWhenInReadOnlyFileMount
‪metaDataEditIsNotAllowedWhenWhenInReadOnlyFileMount()
Definition: ResourceStorageTest.php:509
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest
Definition: ResourceStorageTest.php:44
‪TYPO3\CMS\Core\Resource\ResourceStorage\checkFolderActionPermission
‪bool checkFolderActionPermission($action, Folder $folder=null)
Definition: ResourceStorage.php:760
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\convertConfigurationArrayToFlexformXml
‪string convertConfigurationArrayToFlexformXml(array $configuration)
Definition: ResourceStorageTest.php:142
‪TYPO3\CMS\Core\Resource\ResourceStorage\moveFile
‪FileInterface moveFile($file, $targetFolder, $targetFileName=null, $conflictMode=DuplicationBehavior::RENAME)
Definition: ResourceStorage.php:1971
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\getEvaluatePermissionsWhenSetTrue
‪getEvaluatePermissionsWhenSetTrue()
Definition: ResourceStorageTest.php:550
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\moveFileCallsDriversMethodsWithCorrectArguments
‪moveFileCallsDriversMethodsWithCorrectArguments()
Definition: ResourceStorageTest.php:618
‪TYPO3\CMS\Core\Resource\FileRepository
Definition: FileRepository.php:33
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\createFolderChecksIfParentFolderExistsBeforeCreatingFolder
‪createFolderChecksIfParentFolderExistsBeforeCreatingFolder()
Definition: ResourceStorageTest.php:691
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\createFolderThrowsExceptionIfParentFolderDoesNotExist
‪createFolderThrowsExceptionIfParentFolderDoesNotExist()
Definition: ResourceStorageTest.php:794
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ResourceStorageTest.php:47
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\getMountRootUrl
‪getMountRootUrl()
Definition: BaseTestCase.php:48
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\$subject
‪ResourceStorage PHPUnit Framework MockObject MockObject $subject
Definition: ResourceStorageTest.php:51
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\checkUserActionPermission_arbitraryPermissionDataProvider
‪array checkUserActionPermission_arbitraryPermissionDataProvider()
Definition: ResourceStorageTest.php:409
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\getUrlInMount
‪string getUrlInMount($path)
Definition: BaseTestCase.php:79
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\storageUsesInjectedFilemountsToCheckForMountBoundaries
‪storageUsesInjectedFilemountsToCheckForMountBoundaries()
Definition: ResourceStorageTest.php:670
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\getSimpleFolderMock
‪TYPO3 CMS Core Resource Folder getSimpleFolderMock($identifier, $mockedMethods=[])
Definition: BaseTestCase.php:151
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\createFolderCreatesNestedStructureEvenIfPartsAlreadyExist
‪createFolderCreatesNestedStructureEvenIfPartsAlreadyExist()
Definition: ResourceStorageTest.php:776
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\createFolderUsesRootFolderAsParentFolderIfNotGiven
‪createFolderUsesRootFolderAsParentFolderIfNotGiven()
Definition: ResourceStorageTest.php:762
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:122
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:92
‪TYPO3\CMS\Core\Resource\ResourceStorage\setDriver
‪ResourceStorage setDriver(DriverInterface $driver)
Definition: ResourceStorage.php:290
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\checkUserActionPermissionAcceptsArbitrarilyCasedArguments
‪checkUserActionPermissionAcceptsArbitrarilyCasedArguments(array $permissions, string $action, string $type)
Definition: ResourceStorageTest.php:437
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\prepareSubject
‪prepareSubject(array $configuration, bool $mockPermissionChecks=false, AbstractDriver $driverObject=null, ResourceFactory $resourceFactory=null, array $storageRecord=[], array $mockedMethods=[])
Definition: ResourceStorageTest.php:90
‪TYPO3\CMS\Core\Resource\DuplicationBehavior\REPLACE
‪const REPLACE
Definition: DuplicationBehavior.php:39
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\addFileFailsIfFileDoesNotExist
‪addFileFailsIfFileDoesNotExist()
Definition: ResourceStorageTest.php:294
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\metaDataEditIsAllowedWhenWhenInFileMount
‪metaDataEditIsAllowedWhenWhenInFileMount()
Definition: ResourceStorageTest.php:479
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\getEvaluatePermissionsWhenSetFalse
‪getEvaluatePermissionsWhenSetFalse()
Definition: ResourceStorageTest.php:540
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\$eventDispatcher
‪EventDispatcherInterface $eventDispatcher
Definition: ResourceStorageTest.php:55
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\createFolderCallsDriverForFolderCreation
‪createFolderCallsDriverForFolderCreation()
Definition: ResourceStorageTest.php:727
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\checkFolderPermissionsFilesystemPermissionsDataProvider
‪array checkFolderPermissionsFilesystemPermissionsDataProvider()
Definition: ResourceStorageTest.php:333
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\userActionIsDisallowedIfPermissionIsNotSet
‪userActionIsDisallowedIfPermissionIsNotSet()
Definition: ResourceStorageTest.php:458
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\setUp
‪setUp()
Definition: ResourceStorageTest.php:60
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver
Definition: AbstractDriver.php:25
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\getSimpleFileMock
‪TYPO3 CMS Core Resource File PHPUnit Framework MockObject MockObject getSimpleFileMock($identifier, $mockedMethods=[])
Definition: BaseTestCase.php:139
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\createFolderCanRecursivelyCreateFolders
‪createFolderCanRecursivelyCreateFolders()
Definition: ResourceStorageTest.php:745
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\addToMount
‪addToMount(array $dirStructure)
Definition: BaseTestCase.php:68
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\initializeVfs
‪initializeVfs()
Definition: BaseTestCase.php:58