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