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