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