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