[TASK] Upgrade to phpunit 5.2
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / ResourceStorageTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Resource;
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
17 use TYPO3\CMS\Core\Database\DatabaseConnection;
18 use TYPO3\CMS\Core\Resource\Driver\AbstractDriver;
19 use TYPO3\CMS\Core\Resource\Driver\LocalDriver;
20 use TYPO3\CMS\Core\Resource\File;
21 use TYPO3\CMS\Core\Resource\FileRepository;
22 use TYPO3\CMS\Core\Resource\Folder;
23 use TYPO3\CMS\Core\Resource\FolderInterface;
24 use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
25 use TYPO3\CMS\Core\Resource\ResourceStorage;
26 use TYPO3\CMS\Core\Resource\ResourceStorageInterface;
27 use TYPO3\CMS\Core\Utility\ArrayUtility;
28 use TYPO3\CMS\Core\Utility\GeneralUtility;
29
30 /**
31 * Test case for ResourceStorage class
32 */
33 class ResourceStorageTest extends BaseTestCase
34 {
35 /**
36 * @var array A backup of registered singleton instances
37 */
38 protected $singletonInstances = array();
39
40 /**
41 * @var ResourceStorage|\PHPUnit_Framework_MockObject_MockObject
42 */
43 protected $subject;
44
45 protected function setUp()
46 {
47 parent::setUp();
48 $this->singletonInstances = GeneralUtility::getSingletonInstances();
49 /** @var FileRepository|\PHPUnit_Framework_MockObject_MockObject $fileRepositoryMock */
50 $fileRepositoryMock = $this->getMock(FileRepository::class);
51 GeneralUtility::setSingletonInstance(
52 FileRepository::class,
53 $fileRepositoryMock
54 );
55 $databaseMock = $this->getMock(DatabaseConnection::class);
56 $databaseMock->expects($this->any())->method('exec_SELECTgetRows')->with('*', 'sys_file_storage', '1=1', '', 'name', '', 'uid')->willReturn(array());
57 $GLOBALS['TYPO3_DB'] = $databaseMock;
58 }
59
60 protected function tearDown()
61 {
62 GeneralUtility::resetSingletonInstances($this->singletonInstances);
63 parent::tearDown();
64 }
65
66 /**
67 * Prepare ResourceStorage
68 *
69 * @param array $configuration
70 * @param bool $mockPermissionChecks
71 * @param AbstractDriver|\PHPUnit_Framework_MockObject_MockObject $driverObject
72 * @param array $storageRecord
73 */
74 protected function prepareSubject(array $configuration, $mockPermissionChecks = false, AbstractDriver $driverObject = null, array $storageRecord = array())
75 {
76 $permissionMethods = array('assureFileAddPermissions', 'checkFolderActionPermission', 'checkFileActionPermission', 'checkUserActionPermission', 'checkFileExtensionPermission', 'isWithinFileMountBoundaries');
77 $mockedMethods = array();
78 $configuration = $this->convertConfigurationArrayToFlexformXml($configuration);
79 $overruleArray = array('configuration' => $configuration);
80 ArrayUtility::mergeRecursiveWithOverrule($storageRecord, $overruleArray);
81 if ($driverObject == null) {
82 $driverObject = $this->getMockForAbstractClass(AbstractDriver::class, array(), '', false);
83 }
84 if ($mockPermissionChecks) {
85 $mockedMethods = $permissionMethods;
86 }
87 $mockedMethods[] = 'getIndexer';
88
89 $this->subject = $this->getMock(ResourceStorage::class, $mockedMethods, array($driverObject, $storageRecord));
90 $this->subject->expects($this->any())->method('getIndexer')->will($this->returnValue($this->getMock(\TYPO3\CMS\Core\Resource\Index\Indexer::class, array(), array(), '', false)));
91 if ($mockPermissionChecks) {
92 foreach ($permissionMethods as $method) {
93 $this->subject->expects($this->any())->method($method)->will($this->returnValue(true));
94 }
95 }
96 }
97
98 /**
99 * Converts a simple configuration array into a FlexForm data structure serialized as XML
100 *
101 * @param array $configuration
102 * @return string
103 * @see GeneralUtility::array2xml()
104 */
105 protected function convertConfigurationArrayToFlexformXml(array $configuration)
106 {
107 $flexFormArray = array('data' => array('sDEF' => array('lDEF' => array())));
108 foreach ($configuration as $key => $value) {
109 $flexFormArray['data']['sDEF']['lDEF'][$key] = array('vDEF' => $value);
110 }
111 $configuration = GeneralUtility::array2xml($flexFormArray);
112 return $configuration;
113 }
114
115 /**
116 * Creates a driver fixture object, optionally using a given mount object.
117 *
118 * IMPORTANT: Call this only after setting up the virtual file system (with the addTo* methods)!
119 *
120 * @param $driverConfiguration
121 * @param ResourceStorage $storageObject
122 * @param array $mockedDriverMethods
123 * @return \TYPO3\CMS\Core\Resource\Driver\LocalDriver|\PHPUnit_Framework_MockObject_MockObject
124 */
125 protected function createDriverMock($driverConfiguration, ResourceStorage $storageObject = null, $mockedDriverMethods = array())
126 {
127 $this->initializeVfs();
128
129 if (!isset($driverConfiguration['basePath'])) {
130 $driverConfiguration['basePath'] = $this->getMountRootUrl();
131 }
132
133 if ($mockedDriverMethods === null) {
134 $driver = new LocalDriver($driverConfiguration);
135 } else {
136 // We are using the LocalDriver here because PHPUnit can't mock concrete methods in abstract classes, so
137 // when using the AbstractDriver we would be in trouble when wanting to mock away some concrete method
138 $driver = $this->getMock(LocalDriver::class, $mockedDriverMethods, array($driverConfiguration));
139 }
140 if ($storageObject !== null) {
141 $storageObject->setDriver($driver);
142 }
143 $driver->setStorageUid(6);
144 $driver->processConfiguration();
145 $driver->initialize();
146 return $driver;
147 }
148
149 /**
150 * @return array
151 */
152 public function isWithinFileMountBoundariesDataProvider()
153 {
154 return array(
155 'Access to file in ro file mount denied for write request' => array(
156 '$fileIdentifier' => '/fooBaz/bar.txt',
157 '$fileMountFolderIdentifier' => '/fooBaz/',
158 '$isFileMountReadOnly' => true,
159 '$checkWriteAccess' => true,
160 '$expectedResult' => false,
161 ),
162 'Access to file in ro file mount allowed for read request' => array(
163 '$fileIdentifier' => '/fooBaz/bar.txt',
164 '$fileMountFolderIdentifier' => '/fooBaz/',
165 '$isFileMountReadOnly' => true,
166 '$checkWriteAccess' => false,
167 '$expectedResult' => true,
168 ),
169 'Access to file in rw file mount allowed for write request' => array(
170 '$fileIdentifier' => '/fooBaz/bar.txt',
171 '$fileMountFolderIdentifier' => '/fooBaz/',
172 '$isFileMountReadOnly' => false,
173 '$checkWriteAccess' => true,
174 '$expectedResult' => true,
175 ),
176 'Access to file in rw file mount allowed for read request' => array(
177 '$fileIdentifier' => '/fooBaz/bar.txt',
178 '$fileMountFolderIdentifier' => '/fooBaz/',
179 '$isFileMountReadOnly' => false,
180 '$checkWriteAccess' => false,
181 '$expectedResult' => true,
182 ),
183 'Access to file not in file mount denied for write request' => array(
184 '$fileIdentifier' => '/fooBaz/bar.txt',
185 '$fileMountFolderIdentifier' => '/barBaz/',
186 '$isFileMountReadOnly' => false,
187 '$checkWriteAccess' => true,
188 '$expectedResult' => false,
189 ),
190 'Access to file not in file mount denied for read request' => array(
191 '$fileIdentifier' => '/fooBaz/bar.txt',
192 '$fileMountFolderIdentifier' => '/barBaz/',
193 '$isFileMountReadOnly' => false,
194 '$checkWriteAccess' => false,
195 '$expectedResult' => false,
196 ),
197 );
198 }
199
200 /**
201 * @param string $fileIdentifier
202 * @param string $fileMountFolderIdentifier
203 * @param bool $isFileMountReadOnly
204 * @param bool $checkWriteAccess
205 * @param bool $expectedResult
206 * @throws \TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException
207 * @test
208 * @dataProvider isWithinFileMountBoundariesDataProvider
209 */
210 public function isWithinFileMountBoundariesRespectsReadOnlyFileMounts($fileIdentifier, $fileMountFolderIdentifier, $isFileMountReadOnly, $checkWriteAccess, $expectedResult)
211 {
212 /** @var AbstractDriver|\PHPUnit_Framework_MockObject_MockObject $driverMock */
213 $driverMock = $this->getMockForAbstractClass(AbstractDriver::class, array(), '', false);
214 $driverMock->expects($this->any())
215 ->method('getFolderInfoByIdentifier')
216 ->willReturnCallback(function ($identifier) use ($isFileMountReadOnly) {
217 return array(
218 'identifier' => $identifier,
219 'name' => trim($identifier, '/'),
220 );
221 });
222 $driverMock->expects($this->any())
223 ->method('isWithin')
224 ->willReturnCallback(function ($folderIdentifier, $fileIdentifier) {
225 if ($fileIdentifier === ResourceStorageInterface::DEFAULT_ProcessingFolder . '/') {
226 return false;
227 } else {
228 return strpos($fileIdentifier, $folderIdentifier) === 0;
229 }
230 });
231 $this->prepareSubject(array(), false, $driverMock);
232 $fileMock = $this->getSimpleFileMock($fileIdentifier);
233 $this->subject->setEvaluatePermissions(true);
234 $this->subject->addFileMount('/' . $this->getUniqueId('random') . '/', array('read_only' => false));
235 $this->subject->addFileMount($fileMountFolderIdentifier, array('read_only' => $isFileMountReadOnly));
236 $this->subject->addFileMount('/' . $this->getUniqueId('random') . '/', array('read_only' => false));
237 $this->assertSame($expectedResult, $this->subject->isWithinFileMountBoundaries($fileMock, $checkWriteAccess));
238 }
239
240 /**
241 * @return array
242 */
243 public function capabilitiesDataProvider()
244 {
245 return array(
246 'only public' => array(
247 array(
248 'public' => true,
249 'writable' => false,
250 'browsable' => false
251 )
252 ),
253 'only writable' => array(
254 array(
255 'public' => false,
256 'writable' => true,
257 'browsable' => false
258 )
259 ),
260 'only browsable' => array(
261 array(
262 'public' => false,
263 'writable' => false,
264 'browsable' => true
265 )
266 ),
267 'all capabilities' => array(
268 array(
269 'public' => true,
270 'writable' => true,
271 'browsable' => true
272 )
273 ),
274 'none' => array(
275 array(
276 'public' => false,
277 'writable' => false,
278 'browsable' => false
279 )
280 )
281 );
282 }
283
284 /**
285 * @test
286 * @dataProvider capabilitiesDataProvider
287 * @TODO: Rewrite or move to functional suite
288 */
289 public function capabilitiesOfStorageObjectAreCorrectlySet(array $capabilities)
290 {
291 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
292 $storageRecord = array(
293 'is_public' => $capabilities['public'],
294 'is_writable' => $capabilities['writable'],
295 'is_browsable' => $capabilities['browsable'],
296 'is_online' => true
297 );
298 $mockedDriver = $this->createDriverMock(
299 array(
300 'pathType' => 'relative',
301 'basePath' => 'fileadmin/',
302 ),
303 $this->subject,
304 null
305 );
306 $this->prepareSubject(array(), false, $mockedDriver, $storageRecord);
307 $this->assertEquals($capabilities['public'], $this->subject->isPublic(), 'Capability "public" is not correctly set.');
308 $this->assertEquals($capabilities['writable'], $this->subject->isWritable(), 'Capability "writable" is not correctly set.');
309 $this->assertEquals($capabilities['browsable'], $this->subject->isBrowsable(), 'Capability "browsable" is not correctly set.');
310 }
311
312 /**
313 * @test
314 * @TODO: Rewrite or move to functional suite
315 */
316 public function fileAndFolderListFiltersAreInitializedWithDefaultFilters()
317 {
318 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
319 $this->prepareSubject(array());
320 $this->assertEquals($GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['defaultFilterCallbacks'], $this->subject->getFileAndFolderNameFilters());
321 }
322
323 /**
324 * @test
325 */
326 public function addFileFailsIfFileDoesNotExist()
327 {
328 /** @var Folder|\PHPUnit_Framework_MockObject_MockObject $mockedFolder */
329 $mockedFolder = $this->getMock(Folder::class, array(), array(), '', false);
330 $this->setExpectedException('InvalidArgumentException', '', 1319552745);
331 $this->prepareSubject(array());
332 $this->subject->addFile('/some/random/file', $mockedFolder);
333 }
334
335 /**
336 * @test
337 */
338 public function getPublicUrlReturnsNullIfStorageIsNotOnline()
339 {
340 /** @var $driver LocalDriver|\PHPUnit_Framework_MockObject_MockObject */
341 $driver = $this->getMock(LocalDriver::class, array(), array(array('basePath' => $this->getMountRootUrl())));
342 /** @var $subject ResourceStorage|\PHPUnit_Framework_MockObject_MockObject */
343 $subject = $this->getMock(ResourceStorage::class, array('isOnline'), array($driver, array('configuration' => array())));
344 $subject->expects($this->once())->method('isOnline')->will($this->returnValue(false));
345
346 $sourceFileIdentifier = '/sourceFile.ext';
347 $sourceFile = $this->getSimpleFileMock($sourceFileIdentifier);
348 $result = $subject->getPublicUrl($sourceFile);
349 $this->assertSame($result, null);
350 }
351
352 /**
353 * Data provider for checkFolderPermissionsRespectsFilesystemPermissions
354 *
355 * @return array
356 */
357 public function checkFolderPermissionsFilesystemPermissionsDataProvider()
358 {
359 return array(
360 'read action on readable/writable folder' => array(
361 'read',
362 array('r' => true, 'w' => true),
363 true
364 ),
365 'read action on unreadable folder' => array(
366 'read',
367 array('r' => false, 'w' => true),
368 false
369 ),
370 'write action on read-only folder' => array(
371 'write',
372 array('r' => true, 'w' => false),
373 false
374 )
375 );
376 }
377
378 /**
379 * @test
380 * @dataProvider checkFolderPermissionsFilesystemPermissionsDataProvider
381 * @param string $action 'read' or 'write'
382 * @param array $permissionsFromDriver The permissions as returned from the driver
383 * @param bool $expectedResult
384 */
385 public function checkFolderPermissionsRespectsFilesystemPermissions($action, $permissionsFromDriver, $expectedResult)
386 {
387 /** @var $mockedDriver LocalDriver|\PHPUnit_Framework_MockObject_MockObject */
388 $mockedDriver = $this->getMock(LocalDriver::class);
389 $mockedDriver->expects($this->any())->method('getPermissions')->will($this->returnValue($permissionsFromDriver));
390 /** @var $mockedFolder Folder|\PHPUnit_Framework_MockObject_MockObject */
391 $mockedFolder = $this->getMock(Folder::class, array(), array(), '', false);
392 // Let all other checks pass
393 /** @var $subject ResourceStorage|\PHPUnit_Framework_MockObject_MockObject */
394 $subject = $this->getMock(ResourceStorage::class, array('isWritable', 'isBrowsable', 'checkUserActionPermission'), array($mockedDriver, array()), '', false);
395 $subject->expects($this->any())->method('isWritable')->will($this->returnValue(true));
396 $subject->expects($this->any())->method('isBrowsable')->will($this->returnValue(true));
397 $subject->expects($this->any())->method('checkUserActionPermission')->will($this->returnValue(true));
398 $subject->setDriver($mockedDriver);
399
400 $this->assertSame($expectedResult, $subject->checkFolderActionPermission($action, $mockedFolder));
401 }
402
403 /**
404 * @test
405 */
406 public function checkUserActionPermissionsAlwaysReturnsTrueIfNoUserPermissionsAreSet()
407 {
408 $this->prepareSubject(array());
409 $this->assertTrue($this->subject->checkUserActionPermission('read', 'folder'));
410 }
411
412 /**
413 * @test
414 */
415 public function checkUserActionPermissionReturnsFalseIfPermissionIsSetToZero()
416 {
417 $this->prepareSubject(array());
418 $this->subject->setUserPermissions(array('readFolder' => true, 'writeFile' => true));
419 $this->assertTrue($this->subject->checkUserActionPermission('read', 'folder'));
420 }
421
422 public function checkUserActionPermission_arbitraryPermissionDataProvider()
423 {
424 return array(
425 'all lower cased' => array(
426 array('readFolder' => true),
427 'read',
428 'folder'
429 ),
430 'all upper case' => array(
431 array('readFolder' => true),
432 'READ',
433 'FOLDER'
434 ),
435 'mixed case' => array(
436 array('readFolder' => true),
437 'ReaD',
438 'FoLdEr'
439 )
440 );
441 }
442
443 /**
444 * @param array $permissions
445 * @param string $action
446 * @param string $type
447 * @test
448 * @dataProvider checkUserActionPermission_arbitraryPermissionDataProvider
449 */
450 public function checkUserActionPermissionAcceptsArbitrarilyCasedArguments(array $permissions, $action, $type)
451 {
452 $this->prepareSubject(array());
453 $this->subject->setUserPermissions($permissions);
454 $this->assertTrue($this->subject->checkUserActionPermission($action, $type));
455 }
456
457 /**
458 * @test
459 */
460 public function userActionIsDisallowedIfPermissionIsSetToFalse()
461 {
462 $this->prepareSubject(array());
463 $this->subject->setEvaluatePermissions(true);
464 $this->subject->setUserPermissions(array('readFolder' => false));
465 $this->assertFalse($this->subject->checkUserActionPermission('read', 'folder'));
466 }
467
468 /**
469 * @test
470 */
471 public function userActionIsDisallowedIfPermissionIsNotSet()
472 {
473 $this->prepareSubject(array());
474 $this->subject->setEvaluatePermissions(true);
475 $this->subject->setUserPermissions(array('readFolder' => true));
476 $this->assertFalse($this->subject->checkUserActionPermission('write', 'folder'));
477 }
478
479 /**
480 * @test
481 */
482 public function getEvaluatePermissionsWhenSetFalse()
483 {
484 $this->prepareSubject(array());
485 $this->subject->setEvaluatePermissions(false);
486 $this->assertFalse($this->subject->getEvaluatePermissions());
487 }
488
489 /**
490 * @test
491 */
492 public function getEvaluatePermissionsWhenSetTrue()
493 {
494 $this->prepareSubject(array());
495 $this->subject->setEvaluatePermissions(true);
496 $this->assertTrue($this->subject->getEvaluatePermissions());
497 }
498
499 /**
500 * @test
501 * @group integration
502 * @TODO: Rewrite or move to functional suite
503 */
504 public function setFileContentsUpdatesObjectProperties()
505 {
506 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
507 $this->initializeVfs();
508 $driverObject = $this->getMockForAbstractClass(AbstractDriver::class, array(), '', false);
509 $this->subject = $this->getMock(ResourceStorage::class, array('getFileIndexRepository', 'checkFileActionPermission'), array($driverObject, array()));
510 $this->subject->expects($this->any())->method('checkFileActionPermission')->will($this->returnValue(true));
511 $fileInfo = array(
512 'storage' => 'A',
513 'identifier' => 'B',
514 'mtime' => 'C',
515 'ctime' => 'D',
516 'mimetype' => 'E',
517 'size' => 'F',
518 'name' => 'G',
519 );
520 $newProperties = array(
521 'storage' => $fileInfo['storage'],
522 'identifier' => $fileInfo['identifier'],
523 'tstamp' => $fileInfo['mtime'],
524 'crdate' => $fileInfo['ctime'],
525 'mime_type' => $fileInfo['mimetype'],
526 'size' => $fileInfo['size'],
527 'name' => $fileInfo['name']
528 );
529 $hash = 'asdfg';
530 /** @var $mockedDriver LocalDriver|\PHPUnit_Framework_MockObject_MockObject */
531 $mockedDriver = $this->getMock(LocalDriver::class, array(), array(array('basePath' => $this->getMountRootUrl())));
532 $mockedDriver->expects($this->once())->method('getFileInfoByIdentifier')->will($this->returnValue($fileInfo));
533 $mockedDriver->expects($this->once())->method('hash')->will($this->returnValue($hash));
534 $this->subject->setDriver($mockedDriver);
535 $indexFileRepositoryMock = $this->getMock(FileIndexRepository::class);
536 $this->subject->expects($this->any())->method('getFileIndexRepository')->will($this->returnValue($indexFileRepositoryMock));
537 /** @var $mockedFile File|\PHPUnit_Framework_MockObject_MockObject */
538 $mockedFile = $this->getMock(File::class, array(), array(), '', false);
539 $mockedFile->expects($this->any())->method('getIdentifier')->will($this->returnValue($fileInfo['identifier']));
540 // called by indexer because the properties are updated
541 $this->subject->expects($this->any())->method('getFileInfoByIdentifier')->will($this->returnValue($newProperties));
542 $mockedFile->expects($this->any())->method('getStorage')->will($this->returnValue($this->subject));
543 $mockedFile->expects($this->any())->method('getProperties')->will($this->returnValue(array_keys($fileInfo)));
544 $mockedFile->expects($this->any())->method('getUpdatedProperties')->will($this->returnValue(array_keys($newProperties)));
545 // do not update directly; that's up to the indexer
546 $indexFileRepositoryMock->expects($this->never())->method('update');
547 $this->subject->setFileContents($mockedFile, $this->getUniqueId());
548 }
549
550 /**
551 * @test
552 * @group integration
553 * @TODO: Rewrite or move to functional suite
554 */
555 public function moveFileCallsDriversMethodsWithCorrectArguments()
556 {
557 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
558 $localFilePath = '/path/to/localFile';
559 $sourceFileIdentifier = '/sourceFile.ext';
560 $fileInfoDummy = array(
561 'storage' => 'A',
562 'identifier' => 'B',
563 'mtime' => 'C',
564 'ctime' => 'D',
565 'mimetype' => 'E',
566 'size' => 'F',
567 'name' => 'G',
568 );
569 $this->addToMount(array(
570 'targetFolder' => array()
571 ));
572 $this->initializeVfs();
573 $targetFolder = $this->getSimpleFolderMock('/targetFolder/');
574 /** @var $sourceDriver LocalDriver|\PHPUnit_Framework_MockObject_MockObject */
575 $sourceDriver = $this->getMock(LocalDriver::class);
576 $sourceDriver->expects($this->once())->method('deleteFile')->with($this->equalTo($sourceFileIdentifier));
577 $configuration = $this->convertConfigurationArrayToFlexformXml(array());
578 $sourceStorage = new ResourceStorage($sourceDriver, array('configuration' => $configuration));
579 $sourceFile = $this->getSimpleFileMock($sourceFileIdentifier);
580 $sourceFile->expects($this->once())->method('getForLocalProcessing')->will($this->returnValue($localFilePath));
581 $sourceFile->expects($this->any())->method('getStorage')->will($this->returnValue($sourceStorage));
582 $sourceFile->expects($this->once())->method('getUpdatedProperties')->will($this->returnValue(array_keys($fileInfoDummy)));
583 $sourceFile->expects($this->once())->method('getProperties')->will($this->returnValue($fileInfoDummy));
584 /** @var $mockedDriver \TYPO3\CMS\Core\Resource\Driver\LocalDriver|\PHPUnit_Framework_MockObject_MockObject */
585 $mockedDriver = $this->getMock(LocalDriver::class, array(), array(array('basePath' => $this->getMountRootUrl())));
586 $mockedDriver->expects($this->once())->method('getFileInfoByIdentifier')->will($this->returnValue($fileInfoDummy));
587 $mockedDriver->expects($this->once())->method('addFile')->with($localFilePath, '/targetFolder/', $this->equalTo('file.ext'))->will($this->returnValue('/targetFolder/file.ext'));
588 /** @var $subject ResourceStorage */
589 $subject = $this->getMock(ResourceStorage::class, array('assureFileMovePermissions'), array($mockedDriver, array('configuration' => $configuration)));
590 $subject->moveFile($sourceFile, $targetFolder, 'file.ext');
591 }
592
593 /**
594 * @test
595 * @group integration
596 * @TODO: Rewrite or move to functional suite
597 */
598 public function storageUsesInjectedFilemountsToCheckForMountBoundaries()
599 {
600 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
601 $mockedFile = $this->getSimpleFileMock('/mountFolder/file');
602 $this->addToMount(array(
603 'mountFolder' => array(
604 'file' => 'asdfg'
605 )
606 ));
607 $mockedDriver = $this->createDriverMock(array('basePath' => $this->getMountRootUrl()), null, null);
608 $this->initializeVfs();
609 $this->prepareSubject(array(), null, $mockedDriver);
610 $this->subject->addFileMount('/mountFolder');
611 $this->assertEquals(1, count($this->subject->getFileMounts()));
612 $this->subject->isWithinFileMountBoundaries($mockedFile);
613 }
614
615 /**
616 * @test
617 * @TODO: Rewrite or move to functional suite
618 */
619 public function createFolderChecksIfParentFolderExistsBeforeCreatingFolder()
620 {
621 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
622 $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
623 $mockedDriver = $this->createDriverMock(array());
624 $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(true));
625 $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('newFolder'))->will($this->returnValue($mockedParentFolder));
626 $this->prepareSubject(array(), true);
627 $this->subject->setDriver($mockedDriver);
628 $this->subject->createFolder('newFolder', $mockedParentFolder);
629 }
630
631 /**
632 * @test
633 * @expectedException \RuntimeException
634 */
635 public function deleteFolderThrowsExceptionIfFolderIsNotEmptyAndRecursiveDeleteIsDisabled()
636 {
637 /** @var \TYPO3\CMS\Core\Resource\Folder|\PHPUnit_Framework_MockObject_MockObject $folderMock */
638 $folderMock = $this->getMock(Folder::class, array(), array(), '', false);
639 /** @var $mockedDriver \TYPO3\CMS\Core\Resource\Driver\AbstractDriver|\PHPUnit_Framework_MockObject_MockObject */
640 $mockedDriver = $this->getMockForAbstractClass(AbstractDriver::class);
641 $mockedDriver->expects($this->once())->method('isFolderEmpty')->will($this->returnValue(false));
642 /** @var $subject ResourceStorage|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
643 $subject = $this->getAccessibleMock(ResourceStorage::class, array('checkFolderActionPermission'), array(), '', false);
644 $subject->expects($this->any())->method('checkFolderActionPermission')->will($this->returnValue(true));
645 $subject->_set('driver', $mockedDriver);
646 $subject->deleteFolder($folderMock, false);
647 }
648
649 /**
650 * @test
651 * @TODO: Rewrite or move to functional suite
652 */
653 public function createFolderCallsDriverForFolderCreation()
654 {
655 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
656 $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
657 $this->prepareSubject(array(), true);
658 $mockedDriver = $this->createDriverMock(array(), $this->subject);
659 $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('newFolder'), $this->equalTo('/someFolder/'))->will($this->returnValue(true));
660 $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(true));
661 $this->subject->createFolder('newFolder', $mockedParentFolder);
662 }
663
664 /**
665 * @test
666 * @TODO: Rewrite or move to functional suite
667 */
668 public function createFolderCanRecursivelyCreateFolders()
669 {
670 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
671 $this->addToMount(array('someFolder' => array()));
672 $mockedDriver = $this->createDriverMock(array('basePath' => $this->getMountRootUrl()), null, null);
673 $this->prepareSubject(array(), true, $mockedDriver);
674 $parentFolder = $this->subject->getFolder('/someFolder/');
675 $newFolder = $this->subject->createFolder('subFolder/secondSubfolder', $parentFolder);
676 $this->assertEquals('secondSubfolder', $newFolder->getName());
677 $this->assertFileExists($this->getUrlInMount('/someFolder/subFolder/'));
678 $this->assertFileExists($this->getUrlInMount('/someFolder/subFolder/secondSubfolder/'));
679 }
680
681 /**
682 * @test
683 * @TODO: Rewrite or move to functional suite
684 */
685 public function createFolderUsesRootFolderAsParentFolderIfNotGiven()
686 {
687 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
688 $this->prepareSubject(array(), true);
689 $mockedDriver = $this->createDriverMock(array(), $this->subject);
690 $mockedDriver->expects($this->once())->method('getRootLevelFolder')->with()->will($this->returnValue('/'));
691 $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('someFolder'));
692 $this->subject->createFolder('someFolder');
693 }
694
695 /**
696 * @test
697 * @TODO: Rewrite or move to functional suite
698 */
699 public function createFolderCreatesNestedStructureEvenIfPartsAlreadyExist()
700 {
701 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
702 $this->addToMount(array(
703 'existingFolder' => array()
704 ));
705 $this->initializeVfs();
706 $mockedDriver = $this->createDriverMock(array('basePath' => $this->getMountRootUrl()), null, null);
707 $this->prepareSubject(array(), true, $mockedDriver);
708 $rootFolder = $this->subject->getFolder('/');
709 $newFolder = $this->subject->createFolder('existingFolder/someFolder', $rootFolder);
710 $this->assertEquals('someFolder', $newFolder->getName());
711 $this->assertFileExists($this->getUrlInMount('existingFolder/someFolder'));
712 }
713
714 /**
715 * @test
716 */
717 public function createFolderThrowsExceptionIfParentFolderDoesNotExist()
718 {
719 $this->setExpectedException('InvalidArgumentException', '', 1325689164);
720 $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
721 $this->prepareSubject(array(), true);
722 $mockedDriver = $this->createDriverMock(array(), $this->subject);
723 $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(false));
724 $this->subject->createFolder('newFolder', $mockedParentFolder);
725 }
726
727 /**
728 * @test
729 */
730 public function replaceFileFailsIfLocalFileDoesNotExist()
731 {
732 $this->setExpectedException('InvalidArgumentException', '', 1325842622);
733 $this->prepareSubject(array(), true);
734 $mockedFile = $this->getSimpleFileMock('/someFile');
735 $this->subject->replaceFile($mockedFile, PATH_site . $this->getUniqueId());
736 }
737
738 /**
739 * @test
740 * @TODO: Rewrite or move to functional suite
741 */
742 public function getRoleReturnsDefaultForRegularFolders()
743 {
744 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
745 $folderIdentifier = $this->getUniqueId();
746 $this->addToMount(array(
747 $folderIdentifier => array()
748 ));
749 $this->prepareSubject(array());
750
751 $role = $this->subject->getRole($this->getSimpleFolderMock('/' . $folderIdentifier . '/'));
752
753 $this->assertSame(FolderInterface::ROLE_DEFAULT, $role);
754 }
755 }