TYPO3 CMS  TYPO3_8-7
ResourceStorageTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
31 
36 {
40  protected $singletonInstances = [];
41 
45  protected $subject;
46 
47  protected function setUp()
48  {
49  parent::setUp();
50  $this->singletonInstances = GeneralUtility::getSingletonInstances();
52  $fileRepositoryMock = $this->createMock(FileRepository::class);
54  FileRepository::class,
55  $fileRepositoryMock
56  );
57  }
58 
59  protected function tearDown()
60  {
61  GeneralUtility::resetSingletonInstances($this->singletonInstances);
62  parent::tearDown();
63  }
64 
74  protected function prepareSubject(array $configuration, $mockPermissionChecks = false, AbstractDriver $driverObject = null, array $storageRecord = [], array $mockedMethods = [])
75  {
76  $permissionMethods = ['assureFileAddPermissions', 'checkFolderActionPermission', 'checkFileActionPermission', 'checkUserActionPermission', 'checkFileExtensionPermission', 'isWithinFileMountBoundaries', 'assureFileRenamePermissions'];
77  $configuration = $this->convertConfigurationArrayToFlexformXml($configuration);
78  $overruleArray = ['configuration' => $configuration];
79  ArrayUtility::mergeRecursiveWithOverrule($storageRecord, $overruleArray);
80  if ($driverObject == null) {
81  $driverObject = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
82  }
83  if ($mockPermissionChecks) {
84  $mockedMethods = array_merge($mockedMethods, $permissionMethods);
85  }
86  $mockedMethods[] = 'getIndexer';
87 
88  $this->subject = $this->getMockBuilder(ResourceStorage::class)
89  ->setMethods(array_unique($mockedMethods))
90  ->setConstructorArgs([$driverObject, $storageRecord])
91  ->getMock();
92  $this->subject->expects($this->any())->method('getIndexer')->will($this->returnValue($this->createMock(\TYPO3\CMS\Core\Resource\Index\Indexer::class)));
93  if ($mockPermissionChecks) {
94  foreach ($permissionMethods as $method) {
95  $this->subject->expects($this->any())->method($method)->will($this->returnValue(true));
96  }
97  }
98  }
99 
107  protected function convertConfigurationArrayToFlexformXml(array $configuration)
108  {
109  $flexFormArray = ['data' => ['sDEF' => ['lDEF' => []]]];
110  foreach ($configuration as $key => $value) {
111  $flexFormArray['data']['sDEF']['lDEF'][$key] = ['vDEF' => $value];
112  }
113  $configuration = GeneralUtility::array2xml($flexFormArray);
114  return $configuration;
115  }
116 
127  protected function createDriverMock($driverConfiguration, ResourceStorage $storageObject = null, $mockedDriverMethods = [])
128  {
129  $this->initializeVfs();
130 
131  if (!isset($driverConfiguration['basePath'])) {
132  $driverConfiguration['basePath'] = $this->getMountRootUrl();
133  }
134 
135  if ($mockedDriverMethods === null) {
136  $driver = new LocalDriver($driverConfiguration);
137  } else {
138  // We are using the LocalDriver here because PHPUnit can't mock concrete methods in abstract classes, so
139  // when using the AbstractDriver we would be in trouble when wanting to mock away some concrete method
140  $driver = $this->getMockBuilder(LocalDriver::class)
141  ->setMethods($mockedDriverMethods)
142  ->setConstructorArgs([$driverConfiguration])
143  ->getMock();
144  }
145  if ($storageObject !== null) {
146  $storageObject->setDriver($driver);
147  }
148  $driver->setStorageUid(6);
149  $driver->processConfiguration();
150  $driver->initialize();
151  return $driver;
152  }
153 
158  {
159  return [
160  'Permissions evaluated, extension not in allowed list' => [
161  'fileName' => 'foo.txt',
162  'configuration' => ['allow' => 'jpg'],
163  'evaluatePermissions' => true,
164  'isAllowed' => true,
165  ],
166  'Permissions evaluated, extension in deny list' => [
167  'fileName' => 'foo.txt',
168  'configuration' => ['deny' => 'txt'],
169  'evaluatePermissions' => true,
170  'isAllowed' => false,
171  ],
172  'Permissions not evaluated, extension is php' => [
173  'fileName' => 'foo.php',
174  'configuration' => [],
175  'evaluatePermissions' => false,
176  'isAllowed' => false,
177  ],
178  'Permissions evaluated, extension is php' => [
179  'fileName' => 'foo.php',
180  // It is not possible to allow php file extension through configuration
181  'configuration' => ['allow' => 'php'],
182  'evaluatePermissions' => true,
183  'isAllowed' => false,
184  ],
185  ];
186  }
187 
196  public function fileExtensionPermissionIsWorkingCorrectly($fileName, array $configuration, $evaluatePermissions, $isAllowed)
197  {
198  $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']['webspace'] = $configuration;
199  $driverMock = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
200  $subject = $this->getAccessibleMock(ResourceStorage::class, ['dummy'], [$driverMock, []]);
201  $subject->_set('evaluatePermissions', $evaluatePermissions);
202  $this->assertSame($isAllowed, $subject->_call('checkFileExtensionPermission', $fileName));
203  }
204 
208  public function capabilitiesDataProvider()
209  {
210  return [
211  'only public' => [
212  [
213  'public' => true,
214  'writable' => false,
215  'browsable' => false
216  ]
217  ],
218  'only writable' => [
219  [
220  'public' => false,
221  'writable' => true,
222  'browsable' => false
223  ]
224  ],
225  'only browsable' => [
226  [
227  'public' => false,
228  'writable' => false,
229  'browsable' => true
230  ]
231  ],
232  'all capabilities' => [
233  [
234  'public' => true,
235  'writable' => true,
236  'browsable' => true
237  ]
238  ],
239  'none' => [
240  [
241  'public' => false,
242  'writable' => false,
243  'browsable' => false
244  ]
245  ]
246  ];
247  }
248 
254  public function capabilitiesOfStorageObjectAreCorrectlySet(array $capabilities)
255  {
256  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
257  $storageRecord = [
258  'is_public' => $capabilities['public'],
259  'is_writable' => $capabilities['writable'],
260  'is_browsable' => $capabilities['browsable'],
261  'is_online' => true
262  ];
263  $mockedDriver = $this->createDriverMock(
264  [
265  'pathType' => 'relative',
266  'basePath' => 'fileadmin/',
267  ],
268  $this->subject,
269  null
270  );
271  $this->prepareSubject([], false, $mockedDriver, $storageRecord);
272  $this->assertEquals($capabilities['public'], $this->subject->isPublic(), 'Capability "public" is not correctly set.');
273  $this->assertEquals($capabilities['writable'], $this->subject->isWritable(), 'Capability "writable" is not correctly set.');
274  $this->assertEquals($capabilities['browsable'], $this->subject->isBrowsable(), 'Capability "browsable" is not correctly set.');
275  }
276 
282  {
283  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
284  $this->prepareSubject([]);
285  $this->assertEquals($GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['defaultFilterCallbacks'], $this->subject->getFileAndFolderNameFilters());
286  }
287 
291  public function addFileFailsIfFileDoesNotExist()
292  {
294  $mockedFolder = $this->createMock(Folder::class);
295  $this->expectException(\InvalidArgumentException::class);
296  $this->expectExceptionCode(1319552745);
297  $this->prepareSubject([]);
298  $this->subject->addFile('/some/random/file', $mockedFolder);
299  }
300 
304  public function getPublicUrlReturnsNullIfStorageIsNotOnline()
305  {
307  $driver = $this->getMockBuilder(LocalDriver::class)
308  ->setConstructorArgs([['basePath' => $this->getMountRootUrl()]])
309  ->getMock();
311  $subject = $this->getMockBuilder(ResourceStorage::class)
312  ->setMethods(['isOnline'])
313  ->setConstructorArgs([$driver, ['configuration' => []]])
314  ->getMock();
315  $subject->expects($this->once())->method('isOnline')->will($this->returnValue(false));
316 
317  $sourceFileIdentifier = '/sourceFile.ext';
318  $sourceFile = $this->getSimpleFileMock($sourceFileIdentifier);
319  $result = $subject->getPublicUrl($sourceFile);
320  $this->assertSame($result, null);
321  }
322 
329  {
330  return [
331  'read action on readable/writable folder' => [
332  'read',
333  ['r' => true, 'w' => true],
334  true
335  ],
336  'read action on unreadable folder' => [
337  'read',
338  ['r' => false, 'w' => true],
339  false
340  ],
341  'write action on read-only folder' => [
342  'write',
343  ['r' => true, 'w' => false],
344  false
345  ]
346  ];
347  }
348 
356  public function checkFolderPermissionsRespectsFilesystemPermissions($action, $permissionsFromDriver, $expectedResult)
357  {
359  $mockedDriver = $this->createMock(LocalDriver::class);
360  $mockedDriver->expects($this->any())->method('getPermissions')->will($this->returnValue($permissionsFromDriver));
362  $mockedFolder = $this->createMock(Folder::class);
363  // Let all other checks pass
365  $subject = $this->getMockBuilder(ResourceStorage::class)
366  ->setMethods(['isWritable', 'isBrowsable', 'checkUserActionPermission'])
367  ->setConstructorArgs([$mockedDriver, []])
368  ->getMock();
369  $subject->expects($this->any())->method('isWritable')->will($this->returnValue(true));
370  $subject->expects($this->any())->method('isBrowsable')->will($this->returnValue(true));
371  $subject->expects($this->any())->method('checkUserActionPermission')->will($this->returnValue(true));
372  $subject->setDriver($mockedDriver);
373 
374  $this->assertSame($expectedResult, $subject->checkFolderActionPermission($action, $mockedFolder));
375  }
376 
381  {
382  $this->prepareSubject([]);
383  $this->assertTrue($this->subject->checkUserActionPermission('read', 'folder'));
384  }
385 
390  {
391  $this->prepareSubject([]);
392  $this->subject->setUserPermissions(['readFolder' => true, 'writeFile' => true]);
393  $this->assertTrue($this->subject->checkUserActionPermission('read', 'folder'));
394  }
395 
397  {
398  return [
399  'all lower cased' => [
400  ['readFolder' => true],
401  'read',
402  'folder'
403  ],
404  'all upper case' => [
405  ['readFolder' => true],
406  'READ',
407  'FOLDER'
408  ],
409  'mixed case' => [
410  ['readFolder' => true],
411  'ReaD',
412  'FoLdEr'
413  ]
414  ];
415  }
416 
424  public function checkUserActionPermissionAcceptsArbitrarilyCasedArguments(array $permissions, $action, $type)
425  {
426  $this->prepareSubject([]);
427  $this->subject->setUserPermissions($permissions);
428  $this->assertTrue($this->subject->checkUserActionPermission($action, $type));
429  }
430 
435  {
436  $this->prepareSubject([]);
437  $this->subject->setEvaluatePermissions(true);
438  $this->subject->setUserPermissions(['readFolder' => false]);
439  $this->assertFalse($this->subject->checkUserActionPermission('read', 'folder'));
440  }
441 
446  {
447  $this->prepareSubject([]);
448  $this->subject->setEvaluatePermissions(true);
449  $this->subject->setUserPermissions(['readFolder' => true]);
450  $this->assertFalse($this->subject->checkUserActionPermission('write', 'folder'));
451  }
452 
457  {
458  $this->prepareSubject([], false, null, [], ['isWithinProcessingFolder']);
459  $this->subject->setEvaluatePermissions(true);
460  $this->assertFalse($this->subject->checkFileActionPermission('editMeta', new File(['identifier' => '/foo/bar.jpg'], $this->subject)));
461  }
462 
467  {
468  $driverMock = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
469  $this->prepareSubject([], false, $driverMock, [], ['isWithinProcessingFolder']);
470 
471  $fileStub = new File(['identifier' => '/foo/bar.jpg'], $this->subject);
472  $folderStub = new Folder($this->subject, '/foo/', 'foo');
473  $driverMock->expects($this->once())
474  ->method('isWithin')
475  ->with($folderStub->getIdentifier(), $fileStub->getIdentifier())
476  ->willReturn(true);
477 
478  $this->subject->setEvaluatePermissions(true);
479  $fileMounts = [
480  '/foo/' => [
481  'path' => '/foo/',
482  'title' => 'Foo',
483  'folder' => $folderStub,
484  ]
485  ];
486  $this->inject($this->subject, 'fileMounts', $fileMounts);
487  $this->assertTrue($this->subject->checkFileActionPermission('editMeta', $fileStub));
488  }
489 
494  {
495  $driverMock = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
496  $this->prepareSubject([], false, $driverMock, [], ['isWithinProcessingFolder']);
497 
498  $fileStub = new File(['identifier' => '/foo/bar.jpg'], $this->subject);
499  $folderStub = new Folder($this->subject, '/foo/', 'foo');
500  $driverMock->expects($this->once())
501  ->method('isWithin')
502  ->with($folderStub->getIdentifier(), $fileStub->getIdentifier())
503  ->willReturn(true);
504 
505  $this->subject->setEvaluatePermissions(true);
506  $fileMounts = [
507  '/foo/' => [
508  'path' => '/foo/',
509  'title' => 'Foo',
510  'folder' => $folderStub,
511  'read_only' => true,
512  ]
513  ];
514  $this->inject($this->subject, 'fileMounts', $fileMounts);
515  $this->assertFalse($this->subject->checkFileActionPermission('editMeta', $fileStub));
516  }
517 
522  {
523  $this->prepareSubject([]);
524  $this->subject->setEvaluatePermissions(false);
525  $this->assertFalse($this->subject->getEvaluatePermissions());
526  }
527 
532  {
533  $this->prepareSubject([]);
534  $this->subject->setEvaluatePermissions(true);
535  $this->assertTrue($this->subject->getEvaluatePermissions());
536  }
537 
543  public function setFileContentsUpdatesObjectProperties()
544  {
545  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
546  $this->initializeVfs();
547  $driverObject = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
548  $this->subject = $this->getMockBuilder(ResourceStorage::class)
549  ->setMethods(['getFileIndexRepository', 'checkFileActionPermission'])
550  ->setConstructorArgs([$driverObject, []])
551  ->getMock();
552  $this->subject->expects($this->any())->method('checkFileActionPermission')->will($this->returnValue(true));
553  $fileInfo = [
554  'storage' => 'A',
555  'identifier' => 'B',
556  'mtime' => 'C',
557  'ctime' => 'D',
558  'mimetype' => 'E',
559  'size' => 'F',
560  'name' => 'G',
561  ];
562  $newProperties = [
563  'storage' => $fileInfo['storage'],
564  'identifier' => $fileInfo['identifier'],
565  'tstamp' => $fileInfo['mtime'],
566  'crdate' => $fileInfo['ctime'],
567  'mime_type' => $fileInfo['mimetype'],
568  'size' => $fileInfo['size'],
569  'name' => $fileInfo['name']
570  ];
571  $hash = 'asdfg';
573  $mockedDriver = $this->getMockBuilder(LocalDriver::class)
574  ->setConstructorArgs([['basePath' => $this->getMountRootUrl()]])
575  ->getMock();
576  $mockedDriver->expects($this->once())->method('getFileInfoByIdentifier')->will($this->returnValue($fileInfo));
577  $mockedDriver->expects($this->once())->method('hash')->will($this->returnValue($hash));
578  $this->subject->setDriver($mockedDriver);
579  $indexFileRepositoryMock = $this->createMock(FileIndexRepository::class);
580  $this->subject->expects($this->any())->method('getFileIndexRepository')->will($this->returnValue($indexFileRepositoryMock));
582  $mockedFile = $this->createMock(File::class);
583  $mockedFile->expects($this->any())->method('getIdentifier')->will($this->returnValue($fileInfo['identifier']));
584  // called by indexer because the properties are updated
585  $this->subject->expects($this->any())->method('getFileInfoByIdentifier')->will($this->returnValue($newProperties));
586  $mockedFile->expects($this->any())->method('getStorage')->will($this->returnValue($this->subject));
587  $mockedFile->expects($this->any())->method('getProperties')->will($this->returnValue(array_keys($fileInfo)));
588  $mockedFile->expects($this->any())->method('getUpdatedProperties')->will($this->returnValue(array_keys($newProperties)));
589  // do not update directly; that's up to the indexer
590  $indexFileRepositoryMock->expects($this->never())->method('update');
591  $this->subject->setFileContents($mockedFile, $this->getUniqueId());
592  }
593 
599  public function moveFileCallsDriversMethodsWithCorrectArguments()
600  {
601  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
602  $localFilePath = '/path/to/localFile';
603  $sourceFileIdentifier = '/sourceFile.ext';
604  $fileInfoDummy = [
605  'storage' => 'A',
606  'identifier' => 'B',
607  'mtime' => 'C',
608  'ctime' => 'D',
609  'mimetype' => 'E',
610  'size' => 'F',
611  'name' => 'G',
612  ];
613  $this->addToMount([
614  'targetFolder' => []
615  ]);
616  $this->initializeVfs();
617  $targetFolder = $this->getSimpleFolderMock('/targetFolder/');
619  $sourceDriver = $this->createMock(LocalDriver::class);
620  $sourceDriver->expects($this->once())->method('deleteFile')->with($this->equalTo($sourceFileIdentifier));
621  $configuration = $this->convertConfigurationArrayToFlexformXml([]);
622  $sourceStorage = new ResourceStorage($sourceDriver, ['configuration' => $configuration]);
623  $sourceFile = $this->getSimpleFileMock($sourceFileIdentifier);
624  $sourceFile->expects($this->once())->method('getForLocalProcessing')->will($this->returnValue($localFilePath));
625  $sourceFile->expects($this->any())->method('getStorage')->will($this->returnValue($sourceStorage));
626  $sourceFile->expects($this->once())->method('getUpdatedProperties')->will($this->returnValue(array_keys($fileInfoDummy)));
627  $sourceFile->expects($this->once())->method('getProperties')->will($this->returnValue($fileInfoDummy));
629  $mockedDriver = $this->getMockBuilder(LocalDriver::class)
630  ->setConstructorArgs([['basePath' => $this->getMountRootUrl()]])
631  ->getMock();
632  $mockedDriver->expects($this->once())->method('getFileInfoByIdentifier')->will($this->returnValue($fileInfoDummy));
633  $mockedDriver->expects($this->once())->method('addFile')->with($localFilePath, '/targetFolder/', $this->equalTo('file.ext'))->will($this->returnValue('/targetFolder/file.ext'));
635  $subject = $this->getMockBuilder(ResourceStorage::class)
636  ->setMethods(['assureFileMovePermissions'])
637  ->setConstructorArgs([$mockedDriver, ['configuration' => $configuration]])
638  ->getMock();
639  $subject->moveFile($sourceFile, $targetFolder, 'file.ext');
640  }
641 
648  {
649  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
650  $mockedFile = $this->getSimpleFileMock('/mountFolder/file');
651  $this->addToMount([
652  'mountFolder' => [
653  'file' => 'asdfg'
654  ]
655  ]);
656  $mockedDriver = $this->createDriverMock(['basePath' => $this->getMountRootUrl()], null, null);
657  $this->initializeVfs();
658  $this->prepareSubject([], null, $mockedDriver);
659  $this->subject->addFileMount('/mountFolder');
660  $this->assertEquals(1, count($this->subject->getFileMounts()));
661  $this->subject->isWithinFileMountBoundaries($mockedFile);
662  }
663 
669  {
670  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
671  $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
672  $mockedDriver = $this->createDriverMock([]);
673  $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(true));
674  $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('newFolder'))->will($this->returnValue($mockedParentFolder));
675  $this->prepareSubject([], true);
676  $this->subject->setDriver($mockedDriver);
677  $this->subject->createFolder('newFolder', $mockedParentFolder);
678  }
679 
683  public function deleteFolderThrowsExceptionIfFolderIsNotEmptyAndRecursiveDeleteIsDisabled()
684  {
685  $this->expectException(\RuntimeException::class);
686  $this->expectExceptionCode(1325952534);
687 
689  $folderMock = $this->createMock(Folder::class);
691  $mockedDriver = $this->getMockForAbstractClass(AbstractDriver::class);
692  $mockedDriver->expects($this->once())->method('isFolderEmpty')->will($this->returnValue(false));
694  $subject = $this->getAccessibleMock(ResourceStorage::class, ['checkFolderActionPermission'], [], '', false);
695  $subject->expects($this->any())->method('checkFolderActionPermission')->will($this->returnValue(true));
696  $subject->_set('driver', $mockedDriver);
697  $subject->deleteFolder($folderMock, false);
698  }
699 
705  {
706  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
707  $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
708  $this->prepareSubject([], true);
709  $mockedDriver = $this->createDriverMock([], $this->subject);
710  $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('newFolder'), $this->equalTo('/someFolder/'))->will($this->returnValue(true));
711  $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(true));
712  $this->subject->createFolder('newFolder', $mockedParentFolder);
713  }
714 
720  {
721  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
722  $this->addToMount(['someFolder' => []]);
723  $mockedDriver = $this->createDriverMock(['basePath' => $this->getMountRootUrl()], null, null);
724  $this->prepareSubject([], true, $mockedDriver);
725  $parentFolder = $this->subject->getFolder('/someFolder/');
726  $newFolder = $this->subject->createFolder('subFolder/secondSubfolder', $parentFolder);
727  $this->assertEquals('secondSubfolder', $newFolder->getName());
728  $this->assertFileExists($this->getUrlInMount('/someFolder/subFolder/'));
729  $this->assertFileExists($this->getUrlInMount('/someFolder/subFolder/secondSubfolder/'));
730  }
731 
737  {
738  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
739  $this->prepareSubject([], true);
740  $mockedDriver = $this->createDriverMock([], $this->subject);
741  $mockedDriver->expects($this->once())->method('getRootLevelFolder')->with()->will($this->returnValue('/'));
742  $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('someFolder'));
743  $this->subject->createFolder('someFolder');
744  }
745 
751  {
752  $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
753  $this->addToMount([
754  'existingFolder' => []
755  ]);
756  $this->initializeVfs();
757  $mockedDriver = $this->createDriverMock(['basePath' => $this->getMountRootUrl()], null, null);
758  $this->prepareSubject([], true, $mockedDriver);
759  $rootFolder = $this->subject->getFolder('/');
760  $newFolder = $this->subject->createFolder('existingFolder/someFolder', $rootFolder);
761  $this->assertEquals('someFolder', $newFolder->getName());
762  $this->assertFileExists($this->getUrlInMount('existingFolder/someFolder'));
763  }
764 
769  {
770  $this->expectException(\InvalidArgumentException::class);
771  $this->expectExceptionCode(1325689164);
772  $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
773  $this->prepareSubject([], true);
774  $mockedDriver = $this->createDriverMock([], $this->subject);
775  $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(false));
776  $this->subject->createFolder('newFolder', $mockedParentFolder);
777  }
778 
782  public function renameFileRenamesFileAsRequested()
783  {
784  $mockedDriver = $this->createDriverMock([], $this->subject);
785  $mockedDriver->expects($this->once())->method('renameFile')->will($this->returnValue('bar'));
786  $this->prepareSubject([], true, $mockedDriver, [], ['emitPreFileRenameSignal', 'emitPostFileRenameSignal']);
788  $file = new File(['identifier' => 'foo', 'name' => 'foo'], $this->subject);
789  $result = $this->subject->renameFile($file, 'bar');
790  // fake what the indexer does in updateIndexEntry
791  $result->updateProperties(['name' => $result->getIdentifier()]);
792  $this->assertSame('bar', $result->getName());
793  }
794 
798  public function renameFileRenamesWithUniqueNameIfConflictAndConflictModeIsRename()
799  {
800  $mockedDriver = $this->createDriverMock([], $this->subject);
801  $mockedDriver->expects($this->any())->method('renameFile')->will($this->onConsecutiveCalls($this->throwException(new ExistingTargetFileNameException('foo', 1489593090)), 'bar_01'));
802  //$mockedDriver->expects($this->at(1))->method('renameFile')->will($this->returnValue('bar_01'));
803  $mockedDriver->expects($this->any())->method('sanitizeFileName')->will($this->onConsecutiveCalls('bar', 'bar_01'));
804  $this->prepareSubject([], true, $mockedDriver, [], ['emitPreFileRenameSignal', 'emitPostFileRenameSignal', 'getUniqueName']);
806  $file = new File(['identifier' => 'foo', 'name' => 'foo'], $this->subject);
807  $this->subject->expects($this->once())->method('getUniqueName')->will($this->returnValue('bar_01'));
808  $result = $this->subject->renameFile($file, 'bar');
809  // fake what the indexer does in updateIndexEntry
810  $result->updateProperties(['name' => $result->getIdentifier()]);
811  $this->assertSame('bar_01', $result->getName());
812  }
813 
817  public function renameFileThrowsExceptionIfConflictAndConflictModeIsCancel()
818  {
819  $mockedDriver = $this->createDriverMock([], $this->subject);
820  $mockedDriver->expects($this->once())->method('renameFile')->will($this->throwException(new ExistingTargetFileNameException('foo', 1489593099)));
821  $this->prepareSubject([], true, $mockedDriver, [], ['emitPreFileRenameSignal', 'emitPostFileRenameSignal']);
823  $file = new File(['identifier' => 'foo', 'name' => 'foo'], $this->subject);
824  $this->expectException(ExistingTargetFileNameException::class);
825  $this->subject->renameFile($file, 'bar', DuplicationBehavior::CANCEL);
826  }
827 
831  public function renameFileReplacesIfConflictAndConflictModeIsReplace()
832  {
833  $mockedDriver = $this->createDriverMock([], $this->subject);
834  $mockedDriver->expects($this->once())->method('renameFile')->will($this->throwException(new ExistingTargetFileNameException('foo', 1489593098)));
835  $mockedDriver->expects($this->any())->method('sanitizeFileName')->will($this->returnValue('bar'));
836  $this->prepareSubject([], true, $mockedDriver, [], ['emitPreFileRenameSignal', 'emitPostFileRenameSignal', 'replaceFile', 'getPublicUrl', 'getResourceFactoryInstance']);
837  $this->subject->expects($this->once())->method('getPublicUrl')->will($this->returnValue('somePath'));
838  $resourceFactory = $this->prophesize(ResourceFactory::class);
839  $file = $this->prophesize(FileInterface::class);
840  $resourceFactory->getFileObjectFromCombinedIdentifier(Argument::any())->willReturn($file->reveal());
841  $this->subject->expects($this->once())->method('replaceFile')->will($this->returnValue($file->reveal()));
842  $this->subject->expects($this->any())->method('getResourceFactoryInstance')->will(self::returnValue($resourceFactory->reveal()));
844  $file = new File(['identifier' => 'foo', 'name' => 'foo', 'missing' => false], $this->subject);
845  $this->subject->renameFile($file, 'bar', DuplicationBehavior::REPLACE);
846  }
847 }
checkUserActionPermissionAcceptsArbitrarilyCasedArguments(array $permissions, $action, $type)
static array2xml(array $array, $NSprefix='', $level=0, $docTag='phparray', $spaceInd=0, array $options=[], array $stackData=[])
getSimpleFileMock($identifier, $mockedMethods=[])
static setSingletonInstance($className, SingletonInterface $instance)
fileExtensionPermissionIsWorkingCorrectly($fileName, array $configuration, $evaluatePermissions, $isAllowed)
prepareSubject(array $configuration, $mockPermissionChecks=false, AbstractDriver $driverObject=null, array $storageRecord=[], array $mockedMethods=[])
static resetSingletonInstances(array $newSingletonInstances)
getSimpleFolderMock($identifier, $mockedMethods=[])
createDriverMock($driverConfiguration, ResourceStorage $storageObject=null, $mockedDriverMethods=[])
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']