[TASK] Add ResourceStorage getEvaluatePermissions()
[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 */
362 public function getEvaluatePermissionsWhenSetFalse() {
363 $this->prepareFixture(array());
364 $this->fixture->setEvaluatePermissions(FALSE);
365 $this->assertFalse($this->fixture->getEvaluatePermissions());
366 }
367
368 /**
369 * @test
370 */
371 public function getEvaluatePermissionsWhenSetTrue() {
372 $this->prepareFixture(array());
373 $this->fixture->setEvaluatePermissions(TRUE);
374 $this->assertTrue($this->fixture->getEvaluatePermissions());
375 }
376
377 /**
378 * @test
379 * @group integration
380 * @TODO: Rewrite or move to functional suite
381 */
382 public function setFileContentsUpdatesObjectProperties() {
383 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
384 $this->initializeVfs();
385 $driverObject = $this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', array(), '', FALSE);
386 $this->fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('getFileIndexRepository', 'checkFileActionPermission'), array($driverObject, array()));
387 $this->fixture->expects($this->any())->method('checkFileActionPermission')->will($this->returnValue(TRUE));
388 $fileInfo = array(
389 'storage' => 'A',
390 'identifier' => 'B',
391 'mtime' => 'C',
392 'ctime' => 'D',
393 'mimetype' => 'E',
394 'size' => 'F',
395 'name' => 'G',
396 );
397 $newProperties = array(
398 'storage' => $fileInfo['storage'],
399 'identifier' => $fileInfo['identifier'],
400 'tstamp' => $fileInfo['mtime'],
401 'crdate' => $fileInfo['ctime'],
402 'mime_type' => $fileInfo['mimetype'],
403 'size' => $fileInfo['size'],
404 'name' => $fileInfo['name']
405 );
406 $hash = 'asdfg';
407 $driver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\LocalDriver', array(), array(array('basePath' => $this->getMountRootUrl())));
408 $driver->expects($this->once())->method('getFileInfoByIdentifier')->will($this->returnValue($fileInfo));
409 $driver->expects($this->once())->method('hash')->will($this->returnValue($hash));
410 $this->fixture->setDriver($driver);
411 $indexFileRepositoryMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository');
412 $this->fixture->expects($this->any())->method('getFileIndexRepository')->will($this->returnValue($indexFileRepositoryMock));
413 $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
414 $mockedFile->expects($this->any())->method('getIdentifier')->will($this->returnValue($fileInfo['identifier']));
415 // called by indexer because the properties are updated
416 $this->fixture->expects($this->any())->method('getFileInfoByIdentifier')->will($this->returnValue($newProperties));
417 $mockedFile->expects($this->any())->method('getStorage')->will($this->returnValue($this->fixture));
418 $mockedFile->expects($this->any())->method('getProperties')->will($this->returnValue(array_keys($fileInfo)));
419 $mockedFile->expects($this->any())->method('getUpdatedProperties')->will($this->returnValue(array_keys($newProperties)));
420 // do not update directly; that's up to the indexer
421 $indexFileRepositoryMock->expects($this->never())->method('update');
422 $this->fixture->setFileContents($mockedFile, uniqid());
423 }
424
425 /**
426 * @test
427 * @group integration
428 * @TODO: Rewrite or move to functional suite
429 */
430 public function moveFileCallsDriversMethodsWithCorrectArguments() {
431 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
432 $localFilePath = '/path/to/localFile';
433 $sourceFileIdentifier = '/sourceFile.ext';
434 $fileInfoDummy = array(
435 'storage' => 'A',
436 'identifier' => 'B',
437 'mtime' => 'C',
438 'ctime' => 'D',
439 'mimetype' => 'E',
440 'size' => 'F',
441 'name' => 'G',
442 );
443 $this->addToMount(array(
444 'targetFolder' => array()
445 ));
446 $this->initializeVfs();
447 $targetFolder = $this->getSimpleFolderMock('/targetFolder/');
448 $sourceDriver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\LocalDriver');
449 $sourceDriver->expects($this->once())->method('deleteFile')->with($this->equalTo($sourceFileIdentifier));
450 $configuration = $this->convertConfigurationArrayToFlexformXml(array());
451 $sourceStorage = new \TYPO3\CMS\Core\Resource\ResourceStorage($sourceDriver, array('configuration' => $configuration));
452 $sourceFile = $this->getSimpleFileMock($sourceFileIdentifier);
453 $sourceFile->expects($this->once())->method('getForLocalProcessing')->will($this->returnValue($localFilePath));
454 $sourceFile->expects($this->any())->method('getStorage')->will($this->returnValue($sourceStorage));
455 $sourceFile->expects($this->once())->method('getUpdatedProperties')->will($this->returnValue(array_keys($fileInfoDummy)));
456 $sourceFile->expects($this->once())->method('getProperties')->will($this->returnValue($fileInfoDummy));
457 /** @var $driver \TYPO3\CMS\Core\Resource\Driver\LocalDriver */
458 $driver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\LocalDriver', array(), array(array('basePath' => $this->getMountRootUrl())));
459 $driver->expects($this->once())->method('getFileInfoByIdentifier')->will($this->returnValue($fileInfoDummy));
460 $driver->expects($this->once())->method('addFile')->with($localFilePath, '/targetFolder/', $this->equalTo('file.ext'))->will($this->returnValue('/targetFolder/file.ext'));
461 /** @var $fixture \TYPO3\CMS\Core\Resource\ResourceStorage */
462 $fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('assureFileMovePermissions'), array($driver, array('configuration' => $configuration)));
463 $fixture->moveFile($sourceFile, $targetFolder, 'file.ext');
464 }
465
466 /**
467 * @test
468 * @group integration
469 * @TODO: Rewrite or move to functional suite
470 */
471 public function storageUsesInjectedFilemountsToCheckForMountBoundaries() {
472 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
473 $mockedFile = $this->getSimpleFileMock('/mountFolder/file');
474 $this->addToMount(array(
475 'mountFolder' => array(
476 'file' => 'asdfg'
477 )
478 ));
479 $mockedDriver = $this->createDriverMock(array('basePath' => $this->getMountRootUrl()), NULL, NULL);
480 $this->initializeVfs();
481 $this->prepareFixture(array(), NULL, $mockedDriver);
482 $this->fixture->addFileMount('/mountFolder');
483 $this->assertEquals(1, count($this->fixture->getFileMounts()));
484 $this->fixture->isWithinFileMountBoundaries($mockedFile);
485 }
486
487
488 /**
489 * @test
490 * @TODO: Rewrite or move to functional suite
491 */
492 public function createFolderChecksIfParentFolderExistsBeforeCreatingFolder() {
493 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
494 $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
495 $mockedDriver = $this->createDriverMock(array());
496 $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(TRUE));
497 $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('newFolder'))->will($this->returnValue($mockedParentFolder));
498 $this->prepareFixture(array(), TRUE);
499 $this->fixture->setDriver($mockedDriver);
500 $this->fixture->createFolder('newFolder', $mockedParentFolder);
501 }
502
503 /**
504 * @test
505 * @expectedException \RuntimeException
506 */
507 public function deleteFolderThrowsExceptionIfFolderIsNotEmptyAndRecursiveDeleteIsDisabled() {
508 /** @var \TYPO3\CMS\Core\Resource\Folder|\PHPUnit_Framework_MockObject_MockObject $folderMock */
509 $folderMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Folder', array(), array(), '', FALSE);
510 /** @var \TYPO3\CMS\Core\Resource\Driver\AbstractDriver|\PHPUnit_Framework_MockObject_MockObject $driverMock */
511 $driverMock = $this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver');
512 $driverMock->expects($this->once())->method('isFolderEmpty')->will($this->returnValue(FALSE));
513 /** @var \TYPO3\CMS\Core\Resource\ResourceStorage|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $fixture */
514 $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('checkFolderActionPermission'), array(), '', FALSE);
515 $fixture->expects($this->any())->method('checkFolderActionPermission')->will($this->returnValue(TRUE));
516 $fixture->_set('driver', $driverMock);
517 $fixture->deleteFolder($folderMock, FALSE);
518 }
519
520 /**
521 * @test
522 * @TODO: Rewrite or move to functional suite
523 */
524 public function createFolderCallsDriverForFolderCreation() {
525 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
526 $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
527 $this->prepareFixture(array(), TRUE);
528 $mockedDriver = $this->createDriverMock(array(), $this->fixture);
529 $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('newFolder'), $this->equalTo('/someFolder/'))->will($this->returnValue(TRUE));
530 $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(TRUE));
531 $this->fixture->createFolder('newFolder', $mockedParentFolder);
532 }
533
534 /**
535 * @test
536 * @TODO: Rewrite or move to functional suite
537 */
538 public function createFolderCanRecursivelyCreateFolders() {
539 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
540 $this->addToMount(array('someFolder' => array()));
541 $mockedDriver = $this->createDriverMock(array('basePath' => $this->getMountRootUrl()), NULL, NULL);
542 $this->prepareFixture(array(), TRUE, $mockedDriver);
543 $parentFolder = $this->fixture->getFolder('/someFolder/');
544 $newFolder = $this->fixture->createFolder('subFolder/secondSubfolder', $parentFolder);
545 $this->assertEquals('secondSubfolder', $newFolder->getName());
546 $this->assertFileExists($this->getUrlInMount('/someFolder/subFolder/'));
547 $this->assertFileExists($this->getUrlInMount('/someFolder/subFolder/secondSubfolder/'));
548 }
549
550 /**
551 * @test
552 * @TODO: Rewrite or move to functional suite
553 */
554 public function createFolderUsesRootFolderAsParentFolderIfNotGiven() {
555 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
556 $this->prepareFixture(array(), TRUE);
557 $mockedDriver = $this->createDriverMock(array(), $this->fixture);
558 $mockedDriver->expects($this->once())->method('getRootLevelFolder')->with()->will($this->returnValue('/'));
559 $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('someFolder'));
560 $this->fixture->createFolder('someFolder');
561 }
562
563 /**
564 * @test
565 * @TODO: Rewrite or move to functional suite
566 */
567 public function createFolderCreatesNestedStructureEvenIfPartsAlreadyExist() {
568 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
569 $this->addToMount(array(
570 'existingFolder' => array()
571 ));
572 $this->initializeVfs();
573 $mockedDriver = $this->createDriverMock(array('basePath' => $this->getMountRootUrl()), NULL, NULL);
574 $this->prepareFixture(array(), TRUE, $mockedDriver);
575 $rootFolder = $this->fixture->getFolder('/');
576 $newFolder = $this->fixture->createFolder('existingFolder/someFolder', $rootFolder);
577 $this->assertEquals('someFolder', $newFolder->getName());
578 $this->assertFileExists($this->getUrlInMount('existingFolder/someFolder'));
579 }
580
581 /**
582 * @test
583 */
584 public function createFolderThrowsExceptionIfParentFolderDoesNotExist() {
585 $this->setExpectedException('InvalidArgumentException', '', 1325689164);
586 $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
587 $this->prepareFixture(array(), TRUE);
588 $mockedDriver = $this->createDriverMock(array(), $this->fixture);
589 $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(FALSE));
590 $this->fixture->createFolder('newFolder', $mockedParentFolder);
591 }
592
593 /**
594 * @test
595 */
596 public function replaceFileFailsIfLocalFileDoesNotExist() {
597 $this->setExpectedException('InvalidArgumentException', '', 1325842622);
598 $this->prepareFixture(array(), TRUE);
599 $mockedFile = $this->getSimpleFileMock('/someFile');
600 $this->fixture->replaceFile($mockedFile, PATH_site . uniqid());
601 }
602
603 /**
604 * @test
605 * @TODO: Rewrite or move to functional suite
606 */
607 public function getRoleReturnsDefaultForRegularFolders() {
608 $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
609 $folderIdentifier = uniqid();
610 $this->addToMount(array(
611 $folderIdentifier => array()
612 ));
613 $this->prepareFixture(array());
614
615 $role = $this->fixture->getRole($this->getSimpleFolderMock('/' . $folderIdentifier . '/'));
616
617 $this->assertSame(\TYPO3\CMS\Core\Resource\FolderInterface::ROLE_DEFAULT, $role);
618 }
619 }