‪TYPO3CMS  9.5
ResourceStorageTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
19 use Prophecy\Argument;
36 
41 {
45  protected ‪$resetSingletonInstances = true;
46 
50  protected ‪$subject;
51 
55  protected function ‪setUp(): void
56  {
57  parent::setUp();
59  $fileRepositoryMock = $this->createMock(FileRepository::class);
60  GeneralUtility::setSingletonInstance(
61  FileRepository::class,
62  $fileRepositoryMock
63  );
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());
70  }
71 
82  protected function ‪prepareSubject(
83  array $configuration,
84  bool $mockPermissionChecks = false,
85  ‪AbstractDriver $driverObject = null,
86  ‪ResourceFactory $resourceFactory = null,
87  array $storageRecord = [],
88  array $mockedMethods = []
89  ): void {
90  $permissionMethods = [
91  'assureFileAddPermissions',
92  'checkFolderActionPermission',
93  'checkFileActionPermission',
94  'checkUserActionPermission',
95  'checkFileExtensionPermission',
96  'isWithinFileMountBoundaries',
97  'assureFileRenamePermissions'
98  ];
99  $configuration = $this->‪convertConfigurationArrayToFlexformXml($configuration);
100  $overruleArray = ['configuration' => $configuration];
101  ‪ArrayUtility::mergeRecursiveWithOverrule($storageRecord, $overruleArray);
102  if ($driverObject === null) {
103  $driverObject = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
104  }
105  if ($resourceFactory === null) {
106  $resourceFactory = $this->createMock(ResourceFactory::class);
107  }
108  $mockedMethods[] = 'getResourceFactoryInstance';
109  if ($mockPermissionChecks) {
110  $mockedMethods = array_merge($mockedMethods, $permissionMethods);
111  }
112  $mockedMethods[] = 'getIndexer';
113 
114  $this->subject = $this->getMockBuilder(ResourceStorage::class)
115  ->setMethods(array_unique($mockedMethods))
116  ->setConstructorArgs([$driverObject, $storageRecord])
117  ->getMock();
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));
123  }
124  }
125  }
126 
134  protected function ‪convertConfigurationArrayToFlexformXml(array $configuration): string
135  {
136  $flexFormArray = ['data' => ['sDEF' => ['lDEF' => []]]];
137  foreach ($configuration as $key => $value) {
138  $flexFormArray['data']['sDEF']['lDEF'][$key] = ['vDEF' => $value];
139  }
140  $configuration = GeneralUtility::array2xml($flexFormArray);
141  return $configuration;
142  }
143 
154  protected function ‪createDriverMock(
155  $driverConfiguration,
156  ‪ResourceStorage $storageObject = null,
157  array $mockedDriverMethods = []
158  ) {
159  $this->‪initializeVfs();
160 
161  if (!isset($driverConfiguration['basePath'])) {
162  $driverConfiguration['basePath'] = $this->‪getMountRootUrl();
163  }
164 
165  if ($mockedDriverMethods === null) {
166  $driver = new ‪LocalDriver($driverConfiguration);
167  } else {
168  // We are using the LocalDriver here because PHPUnit can't mock concrete methods in abstract classes, so
169  // when using the AbstractDriver we would be in trouble when wanting to mock away some concrete method
170  $driver = $this->getMockBuilder(LocalDriver::class)
171  ->setMethods($mockedDriverMethods)
172  ->setConstructorArgs([$driverConfiguration])
173  ->getMock();
174  }
175  if ($storageObject !== null) {
176  $storageObject->setDriver($driver);
177  }
178  $driver->setStorageUid(6);
179  $driver->processConfiguration();
180  $driver->initialize();
181  return $driver;
182  }
183 
187  public function ‪capabilitiesDataProvider(): array
188  {
189  return [
190  'only public' => [
191  [
192  'public' => true,
193  'writable' => false,
194  'browsable' => false
195  ]
196  ],
197  'only writable' => [
198  [
199  'public' => false,
200  'writable' => true,
201  'browsable' => false
202  ]
203  ],
204  'only browsable' => [
205  [
206  'public' => false,
207  'writable' => false,
208  'browsable' => true
209  ]
210  ],
211  'all capabilities' => [
212  [
213  'public' => true,
214  'writable' => true,
215  'browsable' => true
216  ]
217  ],
218  'none' => [
219  [
220  'public' => false,
221  'writable' => false,
222  'browsable' => false
223  ]
224  ]
225  ];
226  }
227 
234  public function ‪capabilitiesOfStorageObjectAreCorrectlySet(array $capabilities): void
235  {
236  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
237  $storageRecord = [
238  'is_public' => $capabilities['public'],
239  'is_writable' => $capabilities['writable'],
240  'is_browsable' => $capabilities['browsable'],
241  'is_online' => true
242  ];
243  $mockedDriver = $this->‪createDriverMock(
244  [
245  'pathType' => 'relative',
246  'basePath' => 'fileadmin/',
247  ],
248  $this->subject,
249  null
250  );
251  $this->‪prepareSubject([], false, $mockedDriver, null, $storageRecord);
252  $this->assertEquals(
253  $capabilities['public'],
254  $this->subject->isPublic(),
255  'Capability "public" is not correctly set.'
256  );
257  $this->assertEquals(
258  $capabilities['writable'],
259  $this->subject->isWritable(),
260  'Capability "writable" is not correctly set.'
261  );
262  $this->assertEquals(
263  $capabilities['browsable'],
264  $this->subject->isBrowsable(),
265  'Capability "browsable" is not correctly set.'
266  );
267  }
268 
274  {
275  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
276  $this->‪prepareSubject([]);
277  $this->assertEquals(
278  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['defaultFilterCallbacks'],
279  $this->subject->getFileAndFolderNameFilters()
280  );
281  }
282 
286  public function ‪addFileFailsIfFileDoesNotExist(): void
287  {
289  $mockedFolder = $this->createMock(Folder::class);
290  $this->expectException(\InvalidArgumentException::class);
291  $this->expectExceptionCode(1319552745);
292  $this->‪prepareSubject([]);
293  $this->subject->addFile('/some/random/file', $mockedFolder);
294  }
295 
299  public function ‪getPublicUrlReturnsNullIfStorageIsNotOnline(): void
300  {
302  $driver = $this->getMockBuilder(LocalDriver::class)
303  ->setConstructorArgs([['basePath' => $this->‪getMountRootUrl()]])
304  ->getMock();
305  $mockedResourceFactory = $this->createMock(ResourceFactory::class);
307  ‪$subject = $this->getMockBuilder(ResourceStorage::class)
308  ->setMethods(['isOnline', 'getResourceFactoryInstance'])
309  ->setConstructorArgs([$driver, ['configuration' => []]])
310  ->getMock();
311  ‪$subject->expects($this->once())->method('isOnline')->will($this->returnValue(false));
312  ‪$subject->expects($this->any())->method('getResourceFactoryInstance')->will($this->returnValue($mockedResourceFactory));
313 
314  $sourceFileIdentifier = '/sourceFile.ext';
315  $sourceFile = $this->‪getSimpleFileMock($sourceFileIdentifier);
316  $result = ‪$subject->‪getPublicUrl($sourceFile);
317  $this->assertSame($result, null);
318  }
319 
326  {
327  return [
328  'read action on readable/writable folder' => [
329  'read',
330  ['r' => true, 'w' => true],
331  true
332  ],
333  'read action on unreadable folder' => [
334  'read',
335  ['r' => false, 'w' => true],
336  false
337  ],
338  'write action on read-only folder' => [
339  'write',
340  ['r' => true, 'w' => false],
341  false
342  ]
343  ];
344  }
345 
354  string $action,
355  array $permissionsFromDriver,
356  bool $expectedResult
357  ): void {
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);
364  // Let all other checks pass
366  ‪$subject = $this->getMockBuilder(ResourceStorage::class)
367  ->setMethods(['isWritable', 'isBrowsable', 'checkUserActionPermission', 'getResourceFactoryInstance'])
368  ->setConstructorArgs([$mockedDriver, []])
369  ->getMock();
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));
374  ‪$subject->‪setDriver($mockedDriver);
375 
376  $this->assertSame($expectedResult, ‪$subject->‪checkFolderActionPermission($action, $mockedFolder));
377  }
378 
383  {
384  $this->‪prepareSubject([]);
385  $this->assertTrue($this->subject->checkUserActionPermission('read', 'folder'));
386  }
387 
392  {
393  $this->‪prepareSubject([]);
394  $this->subject->setUserPermissions(['readFolder' => true, 'writeFile' => true]);
395  $this->assertTrue($this->subject->checkUserActionPermission('read', 'folder'));
396  }
397 
402  {
403  return [
404  'all lower cased' => [
405  ['readFolder' => true],
406  'read',
407  'folder'
408  ],
409  'all upper case' => [
410  ['readFolder' => true],
411  'READ',
412  'FOLDER'
413  ],
414  'mixed case' => [
415  ['readFolder' => true],
416  'ReaD',
417  'FoLdEr'
418  ]
419  ];
420  }
421 
429  public function ‪checkUserActionPermissionAcceptsArbitrarilyCasedArguments(array $permissions, string $action, string $type): void
430  {
431  $this->‪prepareSubject([]);
432  $this->subject->setUserPermissions($permissions);
433  $this->assertTrue($this->subject->checkUserActionPermission($action, $type));
434  }
435 
440  {
441  $this->‪prepareSubject([]);
442  $this->subject->setEvaluatePermissions(true);
443  $this->subject->setUserPermissions(['readFolder' => false]);
444  $this->assertFalse($this->subject->checkUserActionPermission('read', 'folder'));
445  }
446 
450  public function ‪userActionIsDisallowedIfPermissionIsNotSet(): void
451  {
452  $this->‪prepareSubject([]);
453  $this->subject->setEvaluatePermissions(true);
454  $this->subject->setUserPermissions(['readFolder' => true]);
455  $this->assertFalse($this->subject->checkUserActionPermission('write', 'folder'));
456  }
457 
462  {
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)));
466  }
467 
471  public function ‪metaDataEditIsAllowedWhenWhenInFileMount(): void
472  {
473  $driverMock = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
474  $this->‪prepareSubject([], false, $driverMock, null, [], ['isWithinProcessingFolder']);
475 
476  $fileStub = new ‪File(['identifier' => '/foo/bar.jpg'], $this->subject);
477  $folderStub = new ‪Folder($this->subject, '/foo/', 'foo');
478  $driverMock->expects($this->once())
479  ->method('isWithin')
480  ->with($folderStub->getIdentifier(), $fileStub->getIdentifier())
481  ->willReturn(true);
482 
483  $this->subject->setEvaluatePermissions(true);
484  $fileMounts = [
485  '/foo/' => [
486  'path' => '/foo/',
487  'title' => 'Foo',
488  'folder' => $folderStub,
489  ]
490  ];
491  $this->inject($this->subject, 'fileMounts', $fileMounts);
492  $this->assertTrue($this->subject->checkFileActionPermission('editMeta', $fileStub));
493  }
494 
499  {
500  $driverMock = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
501  $this->‪prepareSubject([], false, $driverMock, null, [], ['isWithinProcessingFolder']);
502 
503  $fileStub = new ‪File(['identifier' => '/foo/bar.jpg'], $this->subject);
504  $folderStub = new ‪Folder($this->subject, '/foo/', 'foo');
505  $driverMock->expects($this->once())
506  ->method('isWithin')
507  ->with($folderStub->getIdentifier(), $fileStub->getIdentifier())
508  ->willReturn(true);
509 
510  $this->subject->setEvaluatePermissions(true);
511  $fileMounts = [
512  '/foo/' => [
513  'path' => '/foo/',
514  'title' => 'Foo',
515  'folder' => $folderStub,
516  'read_only' => true,
517  ]
518  ];
519  $this->inject($this->subject, 'fileMounts', $fileMounts);
520  $this->assertFalse($this->subject->checkFileActionPermission('editMeta', $fileStub));
521  }
522 
526  public function ‪getEvaluatePermissionsWhenSetFalse(): void
527  {
528  $this->‪prepareSubject([]);
529  $this->subject->setEvaluatePermissions(false);
530  $this->assertFalse($this->subject->getEvaluatePermissions());
531  }
532 
536  public function ‪getEvaluatePermissionsWhenSetTrue(): void
537  {
538  $this->‪prepareSubject([]);
539  $this->subject->setEvaluatePermissions(true);
540  $this->assertTrue($this->subject->getEvaluatePermissions());
541  }
542 
548  public function ‪setFileContentsUpdatesObjectProperties(): void
549  {
550  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
551  $this->‪initializeVfs();
552  $driverObject = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
553  $this->subject = $this->getMockBuilder(ResourceStorage::class)
554  ->setMethods(['getFileIndexRepository', 'checkFileActionPermission'])
555  ->setConstructorArgs([$driverObject, []])
556  ->getMock();
557  $this->subject->expects($this->any())->method('checkFileActionPermission')->will($this->returnValue(true));
558  $fileInfo = [
559  'storage' => 'A',
560  'identifier' => 'B',
561  'mtime' => 'C',
562  'ctime' => 'D',
563  'mimetype' => 'E',
564  'size' => 'F',
565  'name' => 'G',
566  ];
567  $newProperties = [
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']
575  ];
576  $hash = 'asdfg';
578  $mockedDriver = $this->getMockBuilder(LocalDriver::class)
579  ->setConstructorArgs([['basePath' => $this->‪getMountRootUrl()]])
580  ->getMock();
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']));
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 
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->createMock(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->getMockBuilder(LocalDriver::class)
635  ->setConstructorArgs([['basePath' => $this->‪getMountRootUrl()]])
636  ->getMock();
637  $mockedDriver->expects($this->once())->method('getFileInfoByIdentifier')->will($this->returnValue($fileInfoDummy));
638  $mockedDriver->expects($this->once())->method('addFile')->with(
639  $localFilePath,
640  '/targetFolder/',
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]])
647  ->getMock();
648  ‪$subject->‪moveFile($sourceFile, $targetFolder, 'file.ext');
649  }
650 
657  {
658  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
659  $mockedFile = $this->‪getSimpleFileMock('/mountFolder/file');
660  $this->‪addToMount([
661  'mountFolder' => [
662  'file' => 'asdfg'
663  ]
664  ]);
665  $mockedDriver = $this->‪createDriverMock(['basePath' => $this->‪getMountRootUrl()], null, null);
666  $this->‪initializeVfs();
667  $this->‪prepareSubject([], null, $mockedDriver);
668  $this->subject->addFileMount('/mountFolder');
669  $this->assertEquals(1, count($this->subject->getFileMounts()));
670  $this->subject->isWithinFileMountBoundaries($mockedFile);
671  }
672 
678  {
679  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
680  $mockedParentFolder = $this->‪getSimpleFolderMock('/someFolder/');
681  $mockedDriver = $this->‪createDriverMock([]);
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));
684  $this->‪prepareSubject([], true);
685  $this->subject->setDriver($mockedDriver);
686  $this->subject->createFolder('newFolder', $mockedParentFolder);
687  }
688 
693  {
694  $this->expectException(\RuntimeException::class);
695  $this->expectExceptionCode(1325952534);
696 
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);
706  ‪$subject->‪deleteFolder($folderMock, false);
707  }
708 
713  public function ‪createFolderCallsDriverForFolderCreation(): void
714  {
715  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
716  $mockedParentFolder = $this->‪getSimpleFolderMock('/someFolder/');
717  $this->‪prepareSubject([], true);
718  $mockedDriver = $this->‪createDriverMock([], $this->subject);
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);
725  }
726 
731  public function ‪createFolderCanRecursivelyCreateFolders(): void
732  {
733  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
734  $this->‪addToMount(['someFolder' => []]);
735  $mockedDriver = $this->‪createDriverMock(['basePath' => $this->‪getMountRootUrl()], null, null);
736  $this->‪prepareSubject([], true, $mockedDriver);
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/'));
742  }
743 
749  {
750  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
751  $this->‪prepareSubject([], true);
752  $mockedDriver = $this->‪createDriverMock([], $this->subject);
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');
756  }
757 
763  {
764  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
765  $this->‪addToMount([
766  'existingFolder' => []
767  ]);
768  $this->‪initializeVfs();
769  $mockedDriver = $this->‪createDriverMock(['basePath' => $this->‪getMountRootUrl()], null, null);
770  $this->‪prepareSubject([], true, $mockedDriver);
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'));
775  }
776 
781  {
782  $this->expectException(\InvalidArgumentException::class);
783  $this->expectExceptionCode(1325689164);
784  $mockedParentFolder = $this->‪getSimpleFolderMock('/someFolder/');
785  $this->‪prepareSubject([], true);
786  $mockedDriver = $this->‪createDriverMock([], $this->subject);
787  $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(false));
788  $this->subject->createFolder('newFolder', $mockedParentFolder);
789  }
790 
794  public function ‪renameFileRenamesFileAsRequested(): void
795  {
796  $mockedDriver = $this->‪createDriverMock([], $this->subject);
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');
802  // fake what the indexer does in updateIndexEntry
803  $result->updateProperties(['name' => $result->getIdentifier()]);
804  $this->assertSame('bar', $result->getName());
805  }
806 
811  {
812  $mockedDriver = $this->‪createDriverMock([], $this->subject);
813  $mockedDriver->expects($this->any())->method('renameFile')->will($this->onConsecutiveCalls($this->throwException(new ‪ExistingTargetFileNameException(
814  'foo',
815  1489593090
816  )), 'bar_01'));
817  //$mockedDriver->expects($this->at(1))->method('renameFile')->will($this->returnValue('bar_01'));
818  $mockedDriver->expects($this->any())->method('sanitizeFileName')->will($this->onConsecutiveCalls(
819  'bar',
820  'bar_01'
821  ));
822  $resourceFactory = $this->createMock(ResourceFactory::class);
823  $this->‪prepareSubject(
824  [],
825  true,
826  $mockedDriver,
827  $resourceFactory,
828  [],
829  ['emitPreFileRenameSignal', 'emitPostFileRenameSignal', 'getUniqueName']
830  );
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');
836  // fake what the indexer does in updateIndexEntry
837  $result->updateProperties(['name' => $result->getIdentifier()]);
838  $this->assertSame('bar_01', $result->getName());
839  }
840 
845  {
846  $mockedDriver = $this->‪createDriverMock([], $this->subject);
847  $mockedDriver->expects($this->once())->method('renameFile')->will($this->throwException(new ‪ExistingTargetFileNameException(
848  'foo',
849  1489593099
850  )));
851  $this->‪prepareSubject([], true, $mockedDriver, null, [], ['emitPreFileRenameSignal', 'emitPostFileRenameSignal']);
853  $file = new ‪File(['identifier' => 'foo', 'name' => 'foo'], $this->subject);
854  $this->expectException(ExistingTargetFileNameException::class);
855  $this->subject->renameFile($file, 'bar', ‪DuplicationBehavior::CANCEL);
856  }
857 
862  {
863  $mockedDriver = $this->‪createDriverMock([], $this->subject);
864  $mockedDriver->expects($this->once())->method('renameFile')->will($this->throwException(new ‪ExistingTargetFileNameException(
865  'foo',
866  1489593098
867  )));
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',
873  'replaceFile',
874  'getPublicUrl',
875  ]);
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);
882  $this->subject->renameFile($file, 'bar', ‪DuplicationBehavior::REPLACE);
883  }
884 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\renameFileRenamesFileAsRequested
‪renameFileRenamesFileAsRequested()
Definition: ResourceStorageTest.php:792
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\checkFolderPermissionsRespectsFilesystemPermissions
‪checkFolderPermissionsRespectsFilesystemPermissions(string $action, array $permissionsFromDriver, bool $expectedResult)
Definition: ResourceStorageTest.php:351
‪TYPO3\CMS\Core\Resource\ResourceStorage\deleteFolder
‪bool deleteFolder($folderObject, $deleteRecursively=false)
Definition: ResourceStorage.php:2286
‪TYPO3\CMS\Core\Resource\Index\FileIndexRepository
Definition: FileIndexRepository.php:41
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\$subject
‪ResourceStorage PHPUnit_Framework_MockObject_MockObject $subject
Definition: ResourceStorageTest.php:48
‪TYPO3\CMS\Core\Resource\DuplicationBehavior
Definition: DuplicationBehavior.php:23
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\capabilitiesOfStorageObjectAreCorrectlySet
‪capabilitiesOfStorageObjectAreCorrectlySet(array $capabilities)
Definition: ResourceStorageTest.php:232
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\checkUserActionPermissionReturnsFalseIfPermissionIsSetToZero
‪checkUserActionPermissionReturnsFalseIfPermissionIsSetToZero()
Definition: ResourceStorageTest.php:389
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\capabilitiesDataProvider
‪array capabilitiesDataProvider()
Definition: ResourceStorageTest.php:185
‪TYPO3\CMS\Core\Resource\DuplicationBehavior\CANCEL
‪const CANCEL
Definition: DuplicationBehavior.php:45
‪TYPO3\CMS\Core\Resource\ResourceStorage\getPublicUrl
‪string null getPublicUrl(ResourceInterface $resourceObject, $relativeToCurrentScript=false)
Definition: ResourceStorage.php:1317
‪TYPO3\CMS\Core\Resource\FileInterface
Definition: FileInterface.php:21
‪TYPO3\CMS\Core\Resource\ResourceStorage\setDriver
‪ResourceStorage setDriver(Driver\DriverInterface $driver)
Definition: ResourceStorage.php:240
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\checkUserActionPermissionsAlwaysReturnsTrueIfNoUserPermissionsAreSet
‪checkUserActionPermissionsAlwaysReturnsTrueIfNoUserPermissionsAreSet()
Definition: ResourceStorageTest.php:380
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\setFileContentsUpdatesObjectProperties
‪setFileContentsUpdatesObjectProperties()
Definition: ResourceStorageTest.php:546
‪TYPO3\CMS\Core\Resource\Driver\LocalDriver
Definition: LocalDriver.php:33
‪TYPO3\CMS\Core\Resource\Index\Indexer
Definition: Indexer.php:33
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\renameFileThrowsExceptionIfConflictAndConflictModeIsCancel
‪renameFileThrowsExceptionIfConflictAndConflictModeIsCancel()
Definition: ResourceStorageTest.php:842
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:3
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase
Definition: BaseTestCase.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\userActionIsDisallowedIfPermissionIsSetToFalse
‪userActionIsDisallowedIfPermissionIsSetToFalse()
Definition: ResourceStorageTest.php:437
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\fileAndFolderListFiltersAreInitializedWithDefaultFilters
‪fileAndFolderListFiltersAreInitializedWithDefaultFilters()
Definition: ResourceStorageTest.php:271
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\renameFileReplacesIfConflictAndConflictModeIsReplace
‪renameFileReplacesIfConflictAndConflictModeIsReplace()
Definition: ResourceStorageTest.php:859
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\deleteFolderThrowsExceptionIfFolderIsNotEmptyAndRecursiveDeleteIsDisabled
‪deleteFolderThrowsExceptionIfFolderIsNotEmptyAndRecursiveDeleteIsDisabled()
Definition: ResourceStorageTest.php:690
‪TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException
Definition: ExistingTargetFileNameException.php:21
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\metaDataEditIsNotAllowedWhenWhenNoFileMountsAreSet
‪metaDataEditIsNotAllowedWhenWhenNoFileMountsAreSet()
Definition: ResourceStorageTest.php:459
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\renameFileRenamesWithUniqueNameIfConflictAndConflictModeIsRename
‪renameFileRenamesWithUniqueNameIfConflictAndConflictModeIsRename()
Definition: ResourceStorageTest.php:808
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\getPublicUrlReturnsNullIfStorageIsNotOnline
‪getPublicUrlReturnsNullIfStorageIsNotOnline()
Definition: ResourceStorageTest.php:297
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\metaDataEditIsNotAllowedWhenWhenInReadOnlyFileMount
‪metaDataEditIsNotAllowedWhenWhenInReadOnlyFileMount()
Definition: ResourceStorageTest.php:496
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest
Definition: ResourceStorageTest.php:41
‪TYPO3\CMS\Core\Resource\ResourceStorage\checkFolderActionPermission
‪bool checkFolderActionPermission($action, Folder $folder=null)
Definition: ResourceStorage.php:707
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\convertConfigurationArrayToFlexformXml
‪string convertConfigurationArrayToFlexformXml(array $configuration)
Definition: ResourceStorageTest.php:132
‪TYPO3\CMS\Core\Resource\ResourceStorage\moveFile
‪FileInterface moveFile($file, $targetFolder, $targetFileName=null, $conflictMode=DuplicationBehavior::RENAME)
Definition: ResourceStorage.php:1924
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\getEvaluatePermissionsWhenSetTrue
‪getEvaluatePermissionsWhenSetTrue()
Definition: ResourceStorageTest.php:534
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\moveFileCallsDriversMethodsWithCorrectArguments
‪moveFileCallsDriversMethodsWithCorrectArguments()
Definition: ResourceStorageTest.php:602
‪TYPO3\CMS\Core\Resource\FileRepository
Definition: FileRepository.php:32
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\createFolderChecksIfParentFolderExistsBeforeCreatingFolder
‪createFolderChecksIfParentFolderExistsBeforeCreatingFolder()
Definition: ResourceStorageTest.php:675
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\createFolderThrowsExceptionIfParentFolderDoesNotExist
‪createFolderThrowsExceptionIfParentFolderDoesNotExist()
Definition: ResourceStorageTest.php:778
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:34
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ResourceStorageTest.php:44
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:23
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\getMountRootUrl
‪getMountRootUrl()
Definition: BaseTestCase.php:43
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\getSimpleFileMock
‪TYPO3 CMS Core Resource File PHPUnit_Framework_MockObject_MockObject getSimpleFileMock($identifier, $mockedMethods=[])
Definition: BaseTestCase.php:134
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\checkUserActionPermission_arbitraryPermissionDataProvider
‪array checkUserActionPermission_arbitraryPermissionDataProvider()
Definition: ResourceStorageTest.php:399
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\getUrlInMount
‪string getUrlInMount($path)
Definition: BaseTestCase.php:74
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\storageUsesInjectedFilemountsToCheckForMountBoundaries
‪storageUsesInjectedFilemountsToCheckForMountBoundaries()
Definition: ResourceStorageTest.php:654
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\getSimpleFolderMock
‪TYPO3 CMS Core Resource Folder getSimpleFolderMock($identifier, $mockedMethods=[])
Definition: BaseTestCase.php:146
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\createFolderCreatesNestedStructureEvenIfPartsAlreadyExist
‪createFolderCreatesNestedStructureEvenIfPartsAlreadyExist()
Definition: ResourceStorageTest.php:760
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:21
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\createFolderUsesRootFolderAsParentFolderIfNotGiven
‪createFolderUsesRootFolderAsParentFolderIfNotGiven()
Definition: ResourceStorageTest.php:746
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:74
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\checkUserActionPermissionAcceptsArbitrarilyCasedArguments
‪checkUserActionPermissionAcceptsArbitrarilyCasedArguments(array $permissions, string $action, string $type)
Definition: ResourceStorageTest.php:427
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪$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:80
‪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:152
‪TYPO3\CMS\Core\Resource\DuplicationBehavior\REPLACE
‪const REPLACE
Definition: DuplicationBehavior.php:38
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\addFileFailsIfFileDoesNotExist
‪addFileFailsIfFileDoesNotExist()
Definition: ResourceStorageTest.php:284
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\metaDataEditIsAllowedWhenWhenInFileMount
‪metaDataEditIsAllowedWhenWhenInFileMount()
Definition: ResourceStorageTest.php:469
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\getEvaluatePermissionsWhenSetFalse
‪getEvaluatePermissionsWhenSetFalse()
Definition: ResourceStorageTest.php:524
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\createFolderCallsDriverForFolderCreation
‪createFolderCallsDriverForFolderCreation()
Definition: ResourceStorageTest.php:711
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\checkFolderPermissionsFilesystemPermissionsDataProvider
‪array checkFolderPermissionsFilesystemPermissionsDataProvider()
Definition: ResourceStorageTest.php:323
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\userActionIsDisallowedIfPermissionIsNotSet
‪userActionIsDisallowedIfPermissionIsNotSet()
Definition: ResourceStorageTest.php:448
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\setUp
‪setUp()
Definition: ResourceStorageTest.php:53
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver
Definition: AbstractDriver.php:23
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceStorageTest\createFolderCanRecursivelyCreateFolders
‪createFolderCanRecursivelyCreateFolders()
Definition: ResourceStorageTest.php:729
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\addToMount
‪addToMount(array $dirStructure)
Definition: BaseTestCase.php:63
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\initializeVfs
‪initializeVfs()
Definition: BaseTestCase.php:53