2 namespace TYPO3\CMS\Core\Tests\Unit\
Resource;
4 use TYPO3\CMS\Core\
Resource\ResourceStorage
;
6 /***************************************************************
9 * (c) 2011-2013 Andreas Wolf <andreas.wolf@ikt-werk.de>
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.
18 * The GNU General Public License can be found at
19 * http://www.gnu.org/copyleft/gpl.html.
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.
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
30 * Testcase for the VFS mount class
32 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
34 class ResourceStorageTest
extends \TYPO3\CMS\Core\Tests\Unit\
Resource\BaseTestCase
{
37 * @var array A backup of registered singleton instances
39 protected $singletonInstances = array();
42 * @var \TYPO3\CMS\Core\Resource\ResourceStorage
46 public function setUp() {
48 $this->singletonInstances
= \TYPO3\CMS\Core\Utility\GeneralUtility
::getSingletonInstances();
49 \TYPO3\CMS\Core\Utility\GeneralUtility
::purgeInstances();
50 \TYPO3\CMS\Core\Utility\GeneralUtility
::setSingletonInstance(
51 'TYPO3\\CMS\\Core\\Resource\\FileRepository',
52 $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileRepository')
57 public function tearDown() {
59 \TYPO3\CMS\Core\Utility\GeneralUtility
::resetSingletonInstances($this->singletonInstances
);
65 * @param array $configuration
66 * @param boolean $mockPermissionChecks
69 protected function prepareFixture($configuration, $mockPermissionChecks = FALSE, $driverObject = NULL, array $storageRecord = array()) {
70 $permissionMethods = array('checkFolderActionPermission', 'checkFileActionPermission', 'checkUserActionPermission');
71 $mockedMethods = NULL;
72 $configuration = $this->convertConfigurationArrayToFlexformXml($configuration);
73 $storageRecord = \TYPO3\CMS\Core\Utility\GeneralUtility
::array_merge_recursive_overrule($storageRecord, array(
74 'configuration' => $configuration
76 if ($driverObject == NULL) {
77 /** @var $mockedDriver \TYPO3\CMS\Core\Resource\Driver\AbstractDriver */
78 $driverObject = $this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', array(), '', FALSE);
80 if ($mockPermissionChecks) {
81 $mockedMethods = $permissionMethods;
83 if ($mockedMethods === NULL) {
84 $this->fixture
= new \TYPO3\CMS\Core\
Resource\
ResourceStorage($driverObject, $storageRecord);
86 $this->fixture
= $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', $mockedMethods, array($driverObject, $storageRecord));
87 foreach ($permissionMethods as $method) {
88 $this->fixture
->expects($this->any())->method($method)->will($this->returnValue(TRUE));
94 * Converts a simple configuration array into a FlexForm data structure serialized as XML
96 * @param array $configuration
98 * @see \TYPO3\CMS\Core\Utility\GeneralUtility::array2xml()
100 protected function convertConfigurationArrayToFlexformXml(array $configuration) {
101 $flexformArray = array('data' => array('sDEF' => array('lDEF' => array())));
102 foreach ($configuration as $key => $value) {
103 $flexformArray['data']['sDEF']['lDEF'][$key] = array('vDEF' => $value);
105 $configuration = \TYPO3\CMS\Core\Utility\GeneralUtility
::array2xml($flexformArray);
106 return $configuration;
110 * Creates a driver fixture object, optionally using a given mount object.
112 * IMPORTANT: Call this only after setting up the virtual file system (with the addTo* methods)!
114 * @param $driverConfiguration
115 * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storageObject
116 * @param array $mockedDriverMethods
117 * @return \TYPO3\CMS\Core\Resource\Driver\LocalDriver
119 protected function createDriverMock($driverConfiguration, \TYPO3\CMS\Core\
Resource\ResourceStorage
$storageObject = NULL, $mockedDriverMethods = array()) {
120 $this->initializeVfs();
121 if ($storageObject == NULL) {
122 $storageObject = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
125 if (!isset($driverConfiguration['basePath'])) {
126 $driverConfiguration['basePath'] = $this->getMountRootUrl();
129 if ($mockedDriverMethods === NULL) {
130 $driver = new \TYPO3\CMS\Core\
Resource\Driver\
LocalDriver($driverConfiguration);
132 // We are using the LocalDriver here because PHPUnit can't mock concrete methods in abstract classes, so
133 // when using the AbstractDriver we would be in trouble when wanting to mock away some concrete method
134 $driver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\LocalDriver', $mockedDriverMethods, array($driverConfiguration));
136 $storageObject->setDriver($driver);
137 $driver->setStorage($storageObject);
138 $driver->processConfiguration();
139 $driver->initialize();
146 public function baseUriGetsSlashAppended() {
147 $uri = 'http://example.org/somewhere/else';
148 $this->prepareFixture(array('baseUri' => $uri));
149 $this->assertEquals($uri . '/', $this->fixture
->getBaseUri());
155 public function capabilitiesDataProvider() {
157 'only public' => array(
164 'only writable' => array(
171 'only browsable' => array(
178 'all capabilities' => array(
197 * @dataProvider capabilitiesDataProvider
199 public function capabilitiesOfStorageObjectAreCorrectlySet(array $capabilites) {
200 $storageRecord = array(
201 'is_public' => $capabilites['public'],
202 'is_writable' => $capabilites['writable'],
203 'is_browsable' => $capabilites['browsable'],
206 $mockedDriver = $this->createDriverMock(array(), $this->fixture
, array('hasCapability'));
207 $mockedDriver->expects($this->any())->method('hasCapability')->will($this->returnValue(TRUE));
208 $this->prepareFixture(array(), FALSE, $mockedDriver, $storageRecord);
209 $this->assertEquals($capabilites['public'], $this->fixture
->isPublic(), 'Capability "public" is not correctly set.');
210 $this->assertEquals($capabilites['writable'], $this->fixture
->isWritable(), 'Capability "writable" is not correctly set.');
211 $this->assertEquals($capabilites['browsable'], $this->fixture
->isBrowsable(), 'Capability "browsable" is not correctly set.');
217 public function fileAndFolderListFiltersAreInitializedWithDefaultFilters() {
218 $this->prepareFixture(array());
219 $this->assertEquals($GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['defaultFilterCallbacks'], $this->fixture
->getFileAndFolderNameFilters());
225 public function addFileFailsIfFileDoesNotExist() {
226 $mockedFolder = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Folder', array(), array(), '', FALSE);
227 $this->setExpectedException('InvalidArgumentException', '', 1319552745);
228 $this->prepareFixture(array());
229 $this->fixture
->addFile('/some/random/file', $mockedFolder);
235 public function addFileCallsDriverWithCorrectArguments() {
236 $mockedFolder = $this->getSimpleFolderMock('/targetFolder/');
237 $this->addToMount(array(
238 'targetFolder' => array(),
239 'file.ext' => 'ajslkd'
241 $this->initializeVfs();
242 $localFilePath = $this->getUrlInMount('file.ext');
243 $this->prepareFixture(array());
244 /** @var $driver \TYPO3\CMS\Core\Resource\Driver\LocalDriver */
245 $driver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\LocalDriver', array('addFile'), array(array('basePath' => $this->getUrlInMount('targetFolder/'))));
246 $driver->expects($this->once())->method('addFile')->with($this->equalTo($localFilePath), $this->anything(), $this->equalTo('file.ext'));
247 $this->fixture
->setDriver($driver);
248 $this->fixture
->addFile($localFilePath, $mockedFolder);
254 public function addFileChangesFilenameIfFileExists() {
255 $mockedFolder = $this->getSimpleFolderMock('/');
256 $this->addToMount(array(
257 'targetFolder' => array(
258 'file.ext' => 'asdf',
259 'file_01.ext' => 'asjdlkajs'
261 'file.ext' => 'ajslkd'
263 $this->initializeVfs();
264 $this->prepareFixture(array());
265 /** @var $driver \TYPO3\CMS\Core\Resource\Driver\LocalDriver */
266 $driver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\LocalDriver', array('addFile', 'fileExistsInFolder'), array(array('basePath' => $this->getUrlInMount('targetFolder/'))));
267 $driver->expects($this->once())->method('addFile')->with($this->anything(), $this->anything(), $this->equalTo('file_02.ext'));
268 $driver->expects($this->exactly(3))->method('fileExistsInFolder')->will($this->onConsecutiveCalls($this->returnValue(TRUE), $this->returnValue(TRUE), $this->returnValue(FALSE)));
269 $this->fixture
->setDriver($driver);
270 $this->fixture
->addFile($this->getUrlInMount('file.ext'), $mockedFolder);
274 * Data provider for checkFolderPermissionsRespectsFilesystemPermissions
278 public function checkFolderPermissionsFilesystemPermissionsDataProvider() {
280 'read action on readable/writable folder' => array(
282 array('r' => TRUE, 'w' => TRUE),
284 'read action on unreadable folder' => array(
286 array('r' => FALSE, 'w' => TRUE),
287 'TYPO3\\CMS\\Core\\Resource\\Exception\\InsufficientFolderReadPermissionsException'
289 'write action on read-only folder' => array(
291 array('r' => TRUE, 'w' => FALSE),
292 'TYPO3\\CMS\\Core\\Resource\\Exception\\InsufficientFolderWritePermissionsException'
299 * @dataProvider checkFolderPermissionsFilesystemPermissionsDataProvider
300 * @param string $action 'read' or 'write'
301 * @param array $permissionsFromDriver The permissions as returned from the driver
302 * @param boolean $expectedException
304 public function checkFolderPermissionsRespectsFilesystemPermissions($action, $permissionsFromDriver, $expectedException = '') {
305 $mockedDriver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\LocalDriver');
306 $mockedDriver->expects($this->any())->method('getFolderPermissions')->will($this->returnValue($permissionsFromDriver));
307 $mockedFolder = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Folder', array(), array(), '', FALSE);
308 // Let all other checks pass
309 /** @var $fixture \TYPO3\CMS\Core\Resource\ResourceStorage */
310 $fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('isWritable', 'isBrowsable', 'checkUserActionPermission'), array($mockedDriver, array()), '', FALSE);
311 $fixture->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
312 $fixture->expects($this->any())->method('isBrowsable')->will($this->returnValue(TRUE));
313 $fixture->expects($this->any())->method('checkUserActionPermission')->will($this->returnValue(TRUE));
314 $fixture->setDriver($mockedDriver);
315 if ($expectedException == '') {
316 $this->assertTrue($fixture->checkFolderActionPermission($action, $mockedFolder));
318 $this->markTestSkipped('The exception has been disable in TYPO3\\CMS\\Core\\Resource\\ResourceStorage');
319 $this->setExpectedException($expectedException);
320 $fixture->checkFolderActionPermission($action, $mockedFolder);
327 public function checkUserActionPermissionsAlwaysReturnsTrueIfNoUserPermissionsAreSet() {
328 $this->prepareFixture(array());
329 $this->assertTrue($this->fixture
->checkUserActionPermission('read', 'folder'));
335 public function checkUserActionPermissionReturnsFalseIfPermissionIsSetToZero() {
336 $this->prepareFixture(array());
337 $this->fixture
->setUserPermissions(array('readFolder' => TRUE, 'writeFile' => TRUE));
338 $this->assertTrue($this->fixture
->checkUserActionPermission('read', 'folder'));
341 public function checkUserActionPermission_arbitraryPermissionDataProvider() {
343 'all lower cased' => array(
344 array('readFolder' => TRUE),
348 'all upper case' => array(
349 array('readFolder' => TRUE),
353 'mixed case' => array(
354 array('readFolder' => TRUE),
363 * @dataProvider checkUserActionPermission_arbitraryPermissionDataProvider
365 public function checkUserActionPermissionAcceptsArbitrarilyCasedArguments($permissions, $action, $type) {
366 $this->prepareFixture(array());
367 $this->fixture
->setUserPermissions($permissions);
368 $this->assertTrue($this->fixture
->checkUserActionPermission($action, $type));
374 public function userActionIsDisallowedIfPermissionIsSetToFalse() {
375 $this->prepareFixture(array());
376 $this->fixture
->setUserPermissions(array('readFolder' => FALSE));
377 $this->assertFalse($this->fixture
->checkUserActionPermission('read', 'folder'));
383 public function userActionIsDisallowedIfPermissionIsNotSet() {
384 $this->prepareFixture(array());
385 $this->fixture
->setUserPermissions(array('readFolder' => TRUE));
386 $this->assertFalse($this->fixture
->checkUserActionPermission('write', 'folder'));
393 public function setFileContentsUpdatesObjectProperties() {
394 $fileContents = 'asdf';
395 $this->initializeVfs();
396 $this->prepareFixture(array(), TRUE);
397 $fileProperties = array(
398 'someProperty' => 'value',
399 'someOtherProperty' => 42
402 $driver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\LocalDriver', array(), array(array('basePath' => $this->getMountRootUrl())));
403 $driver->expects($this->once())->method('getFileInfo')->will($this->returnValue($fileProperties));
404 $driver->expects($this->once())->method('hash')->will($this->returnValue($hash));
405 $this->fixture
->setDriver($driver);
406 $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
407 $mockedFile->expects($this->any())->method('getIdentifier')->will($this->returnValue('/file.ext'));
408 $mockedFile->expects($this->once())->method('updateProperties')->with($this->equalTo(array_merge($fileProperties, array('sha1' => $hash))));
409 $this->fixture
->setFileContents($mockedFile, uniqid());
416 public function moveFileCallsDriversRawMethodsWithCorrectArguments() {
417 $localFilePath = '/path/to/localFile';
418 $sourceFileIdentifier = '/sourceFile.ext';
419 $this->addToMount(array(
420 'targetFolder' => array()
422 $this->initializeVfs();
423 $targetFolder = $this->getSimpleFolderMock('/targetFolder/');
424 $sourceDriver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\LocalDriver');
425 $sourceDriver->expects($this->once())->method('deleteFileRaw')->with($this->equalTo($sourceFileIdentifier));
426 $configuration = $this->convertConfigurationArrayToFlexformXml(array());
427 $sourceStorage = new \TYPO3\CMS\Core\
Resource\
ResourceStorage($sourceDriver, array('configuration' => $configuration));
428 $sourceFile = $this->getSimpleFileMock($sourceFileIdentifier);
429 $sourceFile->expects($this->once())->method('getForLocalProcessing')->will($this->returnValue($localFilePath));
430 $sourceFile->expects($this->any())->method('getStorage')->will($this->returnValue($sourceStorage));
431 /** @var $driver \TYPO3\CMS\Core\Resource\Driver\LocalDriver */
432 $driver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\LocalDriver', array(), array(array('basePath' => $this->getMountRootUrl())));
433 $driver->expects($this->once())->method('addFileRaw')->with($localFilePath, $targetFolder, $this->equalTo('file.ext'))->will($this->returnValue('/targetFolder/file.ext'));
434 /** @var $fixture \TYPO3\CMS\Core\Resource\ResourceStorage */
435 $fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('checkFileMovePermissions', 'updateFile'), array($driver, array('configuration' => $configuration)));
436 $fixture->expects($this->once())->method('updateFile')->with($this->equalTo($sourceFile), $this->equalTo('/targetFolder/file.ext'));
437 $fixture->moveFile($sourceFile, $targetFolder, 'file.ext');
444 public function copyFileCallsDriversRawMethodsWithCorrectArguments() {
445 $localFilePath = '/path/to/localFile';
446 $sourceFileIdentifier = '/sourceFile.ext';
447 $this->addToMount(array(
448 'targetFolder' => array()
450 $this->initializeVfs();
451 $targetFolder = $this->getSimpleFolderMock('/targetFolder/');
452 $storageConfiguration = $this->convertConfigurationArrayToFlexformXml(array());
453 $sourceStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
454 $sourceFile = $this->getSimpleFileMock($sourceFileIdentifier);
455 $sourceFile->expects($this->once())->method('getForLocalProcessing')->will($this->returnValue($localFilePath));
456 $sourceFile->expects($this->any())->method('getStorage')->will($this->returnValue($sourceStorage));
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('addFile')->with($localFilePath, $targetFolder, $this->equalTo('file.ext'));
460 /** @var $fixture \TYPO3\CMS\Core\Resource\ResourceStorage */
461 $fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('checkFileCopyPermissions'), array($driver, array('configuration' => $storageConfiguration)));
462 $fixture->copyFile($sourceFile, $targetFolder, 'file.ext');
469 public function storageUsesInjectedFilemountsToCheckForMountBoundaries() {
470 $mockedFile = $this->getSimpleFileMock('/mountFolder/file');
471 $this->addToMount(array(
472 'mountFolder' => array(
476 $mockedDriver = $this->createDriverMock(array('basePath' => $this->getMountRootUrl()), NULL, NULL);
477 $this->initializeVfs();
478 $this->prepareFixture(array(), NULL, $mockedDriver);
479 $this->fixture
->addFileMount('/mountFolder');
480 $this->assertEquals(1, count($this->fixture
->getFileMounts()));
481 $this->fixture
->isWithinFileMountBoundaries($mockedFile);
485 * This test is also valid for folders
489 public function getFileListReturnsFilesInCorrectOrder() {
496 $this->prepareFixture(array());
497 $driver = $this->createDriverMock(array('basePath' => $this->getMountRootUrl()), $this->fixture
, array('getFileList'));
498 $driver->expects($this->once())->method('getFileList')->will($this->returnValue($fileList));
499 $fileList = $this->fixture
->getFileList('/');
500 $this->assertEquals(array('fail', 'File', 'file2', 'file10'), array_keys($fileList));
506 public function getFileListIgnoresCasingWhenSortingFilenames() {
512 'IMG_1234.jpg' => 'asdf'
514 $this->prepareFixture(array());
515 $driver = $this->createDriverMock(array(), $this->fixture
, array('getFileList'));
516 $driver->expects($this->once())->method('getFileList')->will($this->returnValue($fileList));
517 $fileList = $this->fixture
->getFileList('/');
518 $this->assertEquals(array('12345', 'aFile', 'BFile', 'IMG_1234.jpg', 'zFile'), array_keys($fileList));
524 public function createFolderChecksIfParentFolderExistsBeforeCreatingFolder() {
525 $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
526 $mockedDriver = $this->createDriverMock(array());
527 $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(TRUE));
528 $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('newFolder'))->will($this->returnValue($mockedParentFolder));
529 $this->prepareFixture(array(), TRUE);
530 $this->fixture
->setDriver($mockedDriver);
531 $this->fixture
->createFolder('newFolder', $mockedParentFolder);
536 * @expectedException \RuntimeException
538 public function deleteFolderThrowsExceptionIfFolderIsNotEmptyAndRecursiveDeleteIsDisabled() {
539 /** @var \TYPO3\CMS\Core\Resource\Folder|\PHPUnit_Framework_MockObject_MockObject $folderMock */
540 $folderMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Folder', array(), array(), '', FALSE);
541 /** @var \TYPO3\CMS\Core\Resource\Driver\AbstractDriver|\PHPUnit_Framework_MockObject_MockObject $driverMock */
542 $driverMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', array(), array(), '', FALSE);
543 $driverMock->expects($this->once())->method('isFolderEmpty')->will($this->returnValue(FALSE));
544 /** @var \TYPO3\CMS\Core\Resource\ResourceStorage|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $fixture */
545 $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('checkFolderActionPermission'), array(), '', FALSE);
546 $fixture->expects($this->any())->method('checkFolderActionPermission')->will($this->returnValue(TRUE));
547 $fixture->_set('driver', $driverMock);
548 $fixture->deleteFolder($folderMock, FALSE);
554 public function createFolderCallsDriverForFolderCreation() {
555 $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
556 $this->prepareFixture(array(), TRUE);
557 $mockedDriver = $this->createDriverMock(array(), $this->fixture
);
558 $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('newFolder'), $this->equalTo($mockedParentFolder))->will($this->returnValue(TRUE));
559 $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(TRUE));
560 $this->fixture
->createFolder('newFolder', $mockedParentFolder);
566 public function createFolderCanRecursivelyCreateFolders() {
567 $this->addToMount(array('someFolder' => array()));
568 $mockedDriver = $this->createDriverMock(array('basePath' => $this->getMountRootUrl()), NULL, NULL);
569 $this->prepareFixture(array(), TRUE, $mockedDriver);
570 $parentFolder = $this->fixture
->getFolder('/someFolder/');
571 $newFolder = $this->fixture
->createFolder('subFolder/secondSubfolder', $parentFolder);
572 $this->assertEquals('secondSubfolder', $newFolder->getName());
573 $this->assertFileExists($this->getUrlInMount('/someFolder/subFolder/'));
574 $this->assertFileExists($this->getUrlInMount('/someFolder/subFolder/secondSubfolder/'));
580 public function createFolderIgnoresLeadingAndTrailingSlashesWithFoldername() {
581 $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
582 $this->prepareFixture(array(), TRUE);
583 $mockedDriver = $this->createDriverMock(array(), $this->fixture
);
584 $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(TRUE));
585 $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('subFolder'));
586 $this->fixture
->createFolder('/subFolder/', $mockedParentFolder);
592 public function createFolderUsesRootFolderAsParentFolderIfNotGiven() {
593 $mockedRootFolder = $this->getSimpleFolderMock('/');
594 $this->prepareFixture(array(), TRUE);
595 $mockedDriver = $this->createDriverMock(array(), $this->fixture
);
596 $mockedDriver->expects($this->once())->method('getRootLevelFolder')->with()->will($this->returnValue($mockedRootFolder));
597 $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/'))->will($this->returnValue(TRUE));
598 $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('someFolder'));
599 $this->fixture
->createFolder('someFolder');
605 public function createFolderCreatesNestedStructureEvenIfPartsAlreadyExist() {
606 $this->addToMount(array(
607 'existingFolder' => array()
609 $this->initializeVfs();
610 $mockedDriver = $this->createDriverMock(array('basePath' => $this->getMountRootUrl()), NULL, NULL);
611 $this->prepareFixture(array(), TRUE, $mockedDriver);
612 $rootFolder = $this->fixture
->getFolder('/');
613 $newFolder = $this->fixture
->createFolder('existingFolder/someFolder', $rootFolder);
614 $this->assertEquals('someFolder', $newFolder->getName());
615 $this->assertFileExists($this->getUrlInMount('existingFolder/someFolder'));
621 public function createFolderThrowsExceptionIfParentFolderDoesNotExist() {
622 $this->setExpectedException('InvalidArgumentException', '', 1325689164);
623 $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
624 $this->prepareFixture(array(), TRUE);
625 $mockedDriver = $this->createDriverMock(array(), $this->fixture
);
626 $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(FALSE));
627 $this->fixture
->createFolder('newFolder', $mockedParentFolder);
633 public function replaceFileFailsIfLocalFileDoesNotExist() {
634 $this->setExpectedException('InvalidArgumentException', '', 1325842622);
635 $this->prepareFixture(array(), TRUE);
636 $mockedFile = $this->getSimpleFileMock('/someFile');
637 $this->fixture
->replaceFile($mockedFile, PATH_site
. uniqid());
643 public function getFileListHandsOverRecursiveFALSEifNotExplicitlySet() {
644 $this->prepareFixture(array());
645 $driver = $this->createDriverMock(array('basePath' => $this->getMountRootUrl()), $this->fixture
, array('getFileList'));
646 $driver->expects($this->once())
647 ->method('getFileList')
648 ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), FALSE)
649 ->will($this->returnValue(array()));
650 $this->fixture
->getFileList('/');
656 public function getFileListHandsOverRecursiveTRUEifSet() {
658 $this->prepareFixture(array());
659 $driver = $this->createDriverMock(array('basePath' => $this->getMountRootUrl()), $this->fixture
, array('getFileList'));
660 $driver->expects($this->once())
661 ->method('getFileList')
662 ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), TRUE)
663 ->will($this->returnValue(array()));
664 $this->fixture
->getFileList('/', 0, 0, TRUE, TRUE, TRUE);
670 public function getRoleReturnsDefaultForRegularFolders() {
671 $folderIdentifier = uniqid();
672 $this->addToMount(array(
673 $folderIdentifier => array()
675 $this->prepareFixture(array());
677 $role = $this->fixture
->getRole($this->getSimpleFolderMock('/' . $folderIdentifier . '/'));
679 $this->assertSame(\TYPO3\CMS\Core\
Resource\FolderInterface
::ROLE_DEFAULT
, $role);
685 public function getRoleReturnsCorrectValueForDefaultProcessingFolder() {
686 $this->prepareFixture(array());
688 $role = $this->fixture
->getRole($this->getSimpleFolderMock('/' . ResourceStorage
::DEFAULT_ProcessingFolder
. '/'));
690 $this->assertSame(\TYPO3\CMS\Core\
Resource\FolderInterface
::ROLE_PROCESSING
, $role);
696 public function getRoleReturnsCorrectValueForConfiguredProcessingFolder() {
697 $folderIdentifier = uniqid();
698 $this->addToMount(array(
699 $folderIdentifier => array()
701 $this->prepareFixture(array(), FALSE, NULL, array('processingfolder' => '/' . $folderIdentifier . '/'));
703 $role = $this->fixture
->getRole($this->getSimpleFolderMock('/' . $folderIdentifier . '/'));
705 $this->assertSame(\TYPO3\CMS\Core\
Resource\FolderInterface
::ROLE_PROCESSING
, $role);
709 * Data provider for fetchFolderListFromDriverReturnsFolderWithoutProcessedFolder function
711 public function fetchFolderListFromDriverReturnsFolderWithoutProcessedFolderDataProvider() {
713 'Empty folderList returned' => array(
715 'processingFolder' => '_processed_',
716 'folderList' => array(),
717 'expectedItems' => array()
719 'Empty _processed_ folder' => array(
721 'processingFolder' => '',
722 'folderList' => array(
723 '_processed_' => array(),
725 'user_upload' => array()
727 'expectedItems' => array(
728 'user_upload' => array(),
732 '_processed_ folder not in folder list' => array(
734 'processingFolder' => '_processed_',
735 'folderList' => array(
738 'expectedItems' => array(
742 '_processed_ folder on root level' => array(
744 'processingFolder' => '_processed_',
745 'folderList' => array(
746 '_processed_' => array(),
748 'user_upload' => array()
750 'expectedItems' => array(
751 'user_upload' => array(),
755 '_processed_ folder on second level' => array(
757 'processingFolder' => 'Public/_processed_',
758 'folderList' => array(
759 '_processed_' => array(),
761 'user_upload' => array()
763 'expectedItems' => array(
764 'user_upload' => array(),
768 '_processed_ folder on third level' => array(
769 'path' => 'Public/Files/',
770 'processingFolder' => 'Public/Files/_processed_',
771 'folderList' => array(
772 '_processed_' => array(),
774 'user_upload' => array()
776 'expectedItems' => array(
777 'user_upload' => array(),
786 * @dataProvider fetchFolderListFromDriverReturnsFolderWithoutProcessedFolderDataProvider
788 public function fetchFolderListFromDriverReturnsFolderWithoutProcessedFolder($path, $processingFolder, $folderList, $expectedItems) {
789 $driverMock = $this->createDriverMock(array(), NULL, array('getFolderList', 'folderExists'));
790 $driverMock->expects($this->once())->method('getFolderList')->will($this->returnValue($folderList));
791 if (!empty($expectedItems)) {
792 // This function is called only if there were any folders retrieved
793 $driverMock->expects($this->once())->method('folderExists')->will($this->returnValue(TRUE));
796 $this->prepareFixture(array(), FALSE, $driverMock, array('processingfolder' => $processingFolder));
798 $this->assertSame($expectedItems, $this->fixture
->fetchFolderListFromDriver($path));