2 /***************************************************************
5 * (c) 2011 Andreas Wolf <andreas.wolf@ikt-werk.de>
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 require_once 'vfsStream/vfsStream.php';
29 require_once dirname(dirname(__FILE__
)) . '/BaseTestCase.php';
30 require_once dirname(__FILE__
) . '/Fixtures/LocalDriverFilenameFilter.php';
33 * Testcase for the local storage driver class of the TYPO3 VFS
37 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
39 class t3lib_file_Driver_LocalDriverTest
extends t3lib_file_BaseTestCase
{
41 static private $testDirs = array();
43 public function setUp() {
45 // use a mocked file repository to avoid updating the index when doing property update tests
46 $mockedRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileRepository');
47 \TYPO3\CMS\Core\Utility\GeneralUtility
::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository', $mockedRepository);
50 public function tearDown() {
51 \TYPO3\CMS\Core\Utility\GeneralUtility
::purgeInstances();
55 static public function tearDownAfterClass() {
56 foreach (self
::$testDirs as $dir) {
57 \TYPO3\CMS\Core\Utility\GeneralUtility
::rmdir($dir, TRUE);
62 * Creates a "real" directory for doing tests. This is neccessary because some file system properties (e.g. permissions)
63 * cannot be reflected by vfsStream, and some methods (like touch()) don't work there either.
65 * Created directories are automatically destroyed by the tearDownAfterClass() method.
69 protected function createRealTestdir() {
70 $basedir = (PATH_site
. 'typo3temp/fal-test-') . \TYPO3\CMS\Core\Utility\GeneralUtility
::shortMD5(microtime(TRUE));
72 self
::$testDirs[] = $basedir;
77 * Creates a driver fixture object, optionally using a given mount object.
79 * IMPORTANT: Call this only after setting up the virtual file system (with the addTo* methods)!
81 * @param $driverConfiguration
82 * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storageObject
83 * @param array $mockedDriverMethods
84 * @return \TYPO3\CMS\Core\Resource\Driver\LocalDriver
86 protected function createDriverFixture($driverConfiguration, \TYPO3\CMS\Core\
Resource\ResourceStorage
$storageObject = NULL, $mockedDriverMethods = array()) {
87 $this->initializeVfs();
88 if ($storageObject == NULL) {
89 $storageObject = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
91 if (count($mockedDriverMethods) == 0) {
92 $driver = new \TYPO3\CMS\Core\
Resource\Driver\
LocalDriver($driverConfiguration);
94 $driver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\LocalDriver', $mockedDriverMethods, array($driverConfiguration));
96 $storageObject->setDriver($driver);
97 $driver->setStorage($storageObject);
98 $driver->processConfiguration();
99 $driver->initialize();
106 public function rootLevelFolderIsCreatedWithCorrectArguments() {
107 $mockedMount = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
108 $fixture = $this->createDriverFixture(array(), $mockedMount);
109 $mockedFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
110 $mockedFactory->expects($this->once())->method('createFolderObject')->with($this->equalTo($mockedMount), $this->equalTo('/'), $this->equalTo(''));
111 \TYPO3\CMS\Core\Utility\GeneralUtility
::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', $mockedFactory);
112 $fixture->getRootLevelFolder();
113 \TYPO3\CMS\Core\Utility\GeneralUtility
::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', new \TYPO3\CMS\Core\
Resource\
ResourceFactory());
119 public function getDefaultFolderReturnsFolderForTemporaryPath() {
120 $fixture = $this->createDriverFixture(array(
121 'basePath' => $this->getMountRootUrl()
123 $folder = $fixture->getDefaultFolder();
124 $this->assertStringEndsWith('_temp_/', $folder->getIdentifier());
130 public function defaultLevelFolderFolderIsCreatedIfItDoesntExist() {
131 $fixture = $this->createDriverFixture(array(
132 'basePath' => $this->getMountRootUrl()
134 $storageFolder = $fixture->getDefaultFolder();
135 $this->assertFileExists($this->getUrlInMount('/_temp_/'));
141 public function getFolderInFolderReturnsCorrectFolderObject() {
142 $this->addToMount(array(
144 'someSubdir' => array()
147 $fixture = $this->createDriverFixture(array(
148 'basePath' => $this->getMountRootUrl()
150 $parentFolder = $fixture->getFolder('/someDir');
151 $folder = $fixture->getFolderInFolder('someSubdir', $parentFolder);
152 $this->assertEquals('/someDir/someSubdir/', $folder->getIdentifier());
158 public function createFolderCreatesFolderOnDisk() {
159 $this->addToMount(array('some' => array('folder' => array())));
160 $fixture = $this->createDriverFixture(array(
161 'basePath' => $this->getMountRootUrl()
163 $mockedFolder = $this->getSimpleFolderMock('/some/folder/');
164 $fixture->createFolder('path', $mockedFolder);
165 $this->assertFileExists($this->getUrlInMount('/some/folder/'));
166 $this->assertFileExists($this->getUrlInMount('/some/folder/path'));
172 public function createFolderReturnsFolderObject() {
173 $this->addToMount(array('some' => array('folder' => array())));
174 $fixture = $this->createDriverFixture(array(
175 'basePath' => $this->getMountRootUrl()
177 $mockedFolder = $this->getSimpleFolderMock('/some/folder/');
178 $createdFolder = $fixture->createFolder('path', $mockedFolder);
179 $this->assertEquals('/some/folder/path/', $createdFolder->getIdentifier());
182 public function createFolderSanitizesFolderNameBeforeCreation_dataProvider() {
184 'folder name with NULL character' => array(
185 'some' . chr(0) . 'Folder',
188 'folder name with directory part' => array(
197 * @dataProvider createFolderSanitizesFolderNameBeforeCreation_dataProvider
199 public function createFolderSanitizesFolderNameBeforeCreation($newFolderName, $expectedFolderName) {
200 $this->addToMount(array('some' => array('folder' => array())));
201 $fixture = $this->createDriverFixture(array(
202 'basePath' => $this->getMountRootUrl()
204 $mockedFolder = $this->getSimpleFolderMock('/some/folder/');
205 $fixture->createFolder($newFolderName, $mockedFolder);
206 $this->assertFileExists($this->getUrlInMount('/some/folder/' . $expectedFolderName));
212 public function driverConfigVerificationFailsIfConfiguredBasePathDoesNotExist() {
213 $this->setExpectedException('TYPO3\\CMS\\Core\\Resource\\Exception\\InvalidConfigurationException', '', 1299233097);
214 $driverConfiguration = array(
215 'basePath' => vfsStream
::url($this->basedir
. 'doesntexist/')
217 $this->assertFalse(file_exists($driverConfiguration['basePath']));
218 \TYPO3\CMS\Core\
Resource\Driver\LocalDriver
::verifyConfiguration($driverConfiguration);
224 public function basePathIsNormalizedWithTrailingSlash() {
225 $driverConfiguration = array(
226 'basePath' => $this->getMountRootUrl()
228 $fixture = $this->createDriverFixture($driverConfiguration);
229 $this->assertEquals('/', substr($fixture->getAbsoluteBasePath(), -1));
235 public function noSecondSlashIsAddedIfBasePathAlreadyHasTrailingSlash() {
236 $driverConfiguration = array(
237 'basePath' => $this->getMountRootUrl()
239 $fixture = $this->createDriverFixture($driverConfiguration);
240 $this->assertNotEquals('/', substr($fixture->getAbsoluteBasePath(), -2, 1));
246 public function getAbsolutePathReturnsCorrectPath() {
247 $this->addToMount(array(
248 'someFolder' => array(
249 'file1.ext' => 'asdfg'
252 $mockedFile = $this->getSimpleFileMock('someFolder/file1.ext');
253 $fixture = $this->createDriverFixture(array(
254 'basePath' => $this->getMountRootUrl()
256 $path = $fixture->getAbsolutePath($mockedFile);
257 $this->assertTrue(file_exists($path));
258 $this->assertEquals($this->getUrlInMount('/someFolder/file1.ext'), $path);
264 public function statReturnsCorrectFileInfo() {
266 $this->addToMount(array('file1.ext' => $contents));
267 $mockedFile = $this->getSimpleFileMock('file1.ext');
268 $fixture = $this->createDriverFixture(array(
269 'basePath' => $this->getMountRootUrl()
271 $path = $fixture->getAbsolutePath($mockedFile);
272 $stat = $fixture->getLowLevelFileInfo($mockedFile);
273 $this->assertEquals(strlen($contents), $stat['size']);
274 $this->assertEquals(filectime($path), $stat['ctime']);
275 $this->assertEquals(fileatime($path), $stat['mtime']);
276 $this->assertEquals(filemtime($path), $stat['atime']);
282 public function addFileMovesFileToCorrectLocation() {
283 $mockedFolder = $this->getSimpleFolderMock('/targetFolder/');
284 $this->addToMount(array('targetFolder' => array()));
285 $this->addToVfs(array(
286 'sourceFolder' => array(
290 $fixture = $this->createDriverFixture(array(
291 'basePath' => $this->getMountRootUrl()
293 $this->assertTrue(file_exists($this->getUrl('sourceFolder/file')));
294 $fixture->addFile($this->getUrl('sourceFolder/file'), $mockedFolder, 'file');
295 $this->assertTrue(file_exists($this->getUrlInMount('/targetFolder/file')));
301 public function addFileUsesFilenameIfGiven() {
302 $mockedFolder = $this->getSimpleFolderMock('/targetFolder/');
303 $this->addToMount(array('targetFolder' => array()));
304 $this->addToVfs(array(
305 'sourceFolder' => array(
309 $fixture = $this->createDriverFixture(array(
310 'basePath' => $this->getMountRootUrl()
312 $this->assertTrue(file_exists($this->getUrl('sourceFolder/file')));
313 $fixture->addFile($this->getUrl('sourceFolder/file'), $mockedFolder, 'targetFile');
314 $this->assertTrue(file_exists($this->getUrlInMount('/targetFolder/targetFile')));
320 public function addFileFailsIfFileIsInDriverStorage() {
321 $mockedFolder = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Folder', array(), array(), '', FALSE);
322 $mockedFolder->expects($this->any())->method('getIdentifier')->will($this->returnValue('/targetFolder/'));
323 $this->setExpectedException('InvalidArgumentException', '', 1314778269);
324 $this->addToMount(array(
325 'targetFolder' => array(
329 $storageObject = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
330 $storageObject->expects($this->any())->method('getUid')->will($this->returnValue('1'));
331 $fixture = $this->createDriverFixture(array(
332 'basePath' => $this->getMountRootUrl()
334 $fixture->addFile($this->getUrlInMount('/targetFolder/file'), $mockedFolder, 'file');
340 public function addFileReturnsFileObject() {
341 $mockedFolder = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Folder', array(), array(), '', FALSE);
342 $mockedFolder->expects($this->any())->method('getIdentifier')->will($this->returnValue('/targetFolder/'));
343 $this->addToMount(array('targetFolder' => array()));
344 $this->addToVfs(array(
345 'sourceFolder' => array(
349 $fixture = $this->createDriverFixture(array(
350 'basePath' => $this->getMountRootUrl()
352 $this->assertTrue(file_exists($this->getUrl('sourceFolder/file')));
353 $fileObject = $fixture->addFile($this->getUrl('sourceFolder/file'), $mockedFolder, 'file');
354 $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\File', $fileObject);
355 $this->assertEquals('file', $fileObject->getName());
356 $this->assertEquals('/targetFolder/file', $fileObject->getIdentifier());
362 public function addFileRawCreatesCopyOfFile() {
363 $this->addToMount(array('targetFolder' => array()));
364 $this->addToVfs(array(
365 'sourceFolder' => array(
369 $fixture = $this->createDriverFixture(array(
370 'basePath' => $this->getMountRootUrl()
372 $this->assertTrue(file_exists($this->getUrl('sourceFolder/file')));
373 $fileIdentifier = $fixture->addFileRaw($this->getUrl('sourceFolder/file'), $this->getSimpleFolderMock('/targetFolder/'), 'somefile');
374 $this->assertTrue(file_exists($this->getUrl('sourceFolder/file')));
375 $this->assertTrue(file_exists($this->getUrlInMount('targetFolder/somefile')));
376 $this->assertEquals('/targetFolder/somefile', $fileIdentifier);
382 public function deleteFileRawRemovesFile() {
383 $this->addToMount(array(
384 'targetFolder' => array(
388 $fixture = $this->createDriverFixture(array(
389 'basePath' => $this->getMountRootUrl()
391 $this->assertTrue(file_exists($this->getUrlInMount('targetFolder/file')));
392 $fixture->deleteFileRaw('/targetFolder/file');
393 $this->assertFalse(file_exists($this->getUrlInMount('targetFolder/file')));
399 public function replacingFileUpdatesMetadataInFileObject() {
400 $this->addToMount(array(
401 'targetFolder' => array(
405 $this->addToVfs(array(
406 'sourceFolder' => array(
410 $fixture = $this->createDriverFixture(array(
411 'basePath' => $this->getMountRootUrl()
413 $mockedFile = $this->getSimpleFileMock('/targetFolder/file', array('updateProperties'));
414 $mockedFile->expects($this->once())->method('updateProperties');
415 $fixture->replaceFile($mockedFile, $this->getUrl('sourceFolder/file'));
421 public function existenceChecksWorkForFilesAndFolders() {
422 $this->addToMount(array(
426 $fixture = $this->createDriverFixture(array(
427 'basePath' => $this->getMountRootUrl()
429 // Using slashes at the beginning of paths because they will be stored in the DB this way.
430 $this->assertTrue($fixture->fileExists('/file'));
431 $this->assertTrue($fixture->folderExists('/folder/'));
432 $this->assertFalse($fixture->fileExists('/nonexistingFile'));
433 $this->assertFalse($fixture->folderExists('/nonexistingFolder/'));
439 public function existenceChecksInFolderWorkForFilesAndFolders() {
440 $mockedFolder = $this->getSimpleFolderMock('/subfolder/');
441 $this->addToMount(array(
442 'subfolder' => array(
447 $fixture = $this->createDriverFixture(array(
448 'basePath' => $this->getMountRootUrl()
450 $this->assertTrue($fixture->fileExistsInFolder('file', $mockedFolder));
451 $this->assertTrue($fixture->folderExistsInFolder('folder', $mockedFolder));
452 $this->assertFalse($fixture->fileExistsInFolder('nonexistingFile', $mockedFolder));
453 $this->assertFalse($fixture->folderExistsInFolder('nonexistingFolder', $mockedFolder));
459 public function getPublicUrlReturnsCorrectUriForConfiguredBaseUri() {
460 $baseUri = 'http://example.org/foobar/' . uniqid();
461 $this->addToMount(array(
462 'file.ext' => 'asdf',
463 'subfolder' => array(
464 'file2.ext' => 'asdf'
467 $fixture = $this->createDriverFixture(array(
468 'basePath' => $this->getMountRootUrl(),
469 'baseUri' => $baseUri
471 $mockedFile1 = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
472 $mockedFile1->expects($this->any())->method('getIdentifier')->will($this->returnValue('/file.ext'));
473 $mockedFile2 = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
474 $mockedFile2->expects($this->any())->method('getIdentifier')->will($this->returnValue('/subfolder/file2.ext'));
475 $this->assertEquals($baseUri . '/file.ext', $fixture->getPublicUrl($mockedFile1));
476 $this->assertEquals($baseUri . '/subfolder/file2.ext', $fixture->getPublicUrl($mockedFile2));
482 public function fileContentsCanBeWrittenAndRead() {
483 $fileContents = 'asdf';
484 $this->addToMount(array(
485 'file.ext' => $fileContents
487 $fixture = $this->createDriverFixture(array(
488 'basePath' => $this->getMountRootUrl()
490 $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
491 $mockedFile->expects($this->any())->method('getIdentifier')->will($this->returnValue('/file.ext'));
492 $this->assertEquals($fileContents, $fixture->getFileContents($mockedFile), 'File contents could not be read');
493 $newFileContents = 'asdfgh';
494 $fixture->setFileContents($mockedFile, $newFileContents);
495 $this->assertEquals($newFileContents, $fixture->getFileContents($mockedFile), 'New file contents could not be read.');
501 public function setFileContentsReturnsNumberOfBytesWrittenToFile() {
502 $fileContents = 'asdf';
503 $this->addToMount(array(
504 'file.ext' => $fileContents
506 $fixture = $this->createDriverFixture(array(
507 'basePath' => $this->getMountRootUrl()
509 $mockedFile = $this->getSimpleFileMock('/file.ext');
510 $newFileContents = 'asdfgh';
511 $bytesWritten = $fixture->setFileContents($mockedFile, $newFileContents);
512 $this->assertEquals(strlen($newFileContents), $bytesWritten);
517 * @depends existenceChecksWorkForFilesAndFolders
518 * @return array The driver fixture, the mocked file
520 public function newFilesCanBeCreated() {
521 $this->addToMount(array(
524 /** @var $fixture \TYPO3\CMS\Core\Resource\Driver\LocalDriver */
525 list($basedir, $fixture) = $this->prepareRealTestEnvironment();
526 mkdir($basedir . '/someDir');
527 $fixture->createFile('testfile.txt', $fixture->getFolder('someDir'));
528 $mockedFile = $this->getSimpleFileMock('/someDir/testfile.txt');
529 $this->assertTrue($fixture->fileExists('/someDir/testfile.txt'));
530 return array($fixture, $mockedFile);
535 * @depends newFilesCanBeCreated
537 public function createdFilesAreEmpty(array $arguments) {
538 /** @var $fixture \TYPO3\CMS\Core\Resource\Driver\LocalDriver */
539 list($fixture, $mockedFile) = $arguments;
540 $fileData = $fixture->getFileContents($mockedFile);
541 $this->assertEquals(0, strlen($fileData));
544 /**********************************
545 * File and directory listing
546 **********************************/
550 public function getFileReturnsCorrectIdentifier() {
551 $this->addToMount(array(
553 'someFile' => 'asdfg'
555 'someFileAtRootLevel' => 'foobar'
557 $fixture = $this->createDriverFixture(array(
558 'basePath' => $this->getMountRootUrl()
560 $subdirFileInfo = $fixture->getFileInfoByIdentifier('/someDir/someFile');
561 $this->assertEquals('/someDir/someFile', $subdirFileInfo['identifier']);
562 $rootFileInfo = $fixture->getFileInfoByIdentifier('/someFileAtRootLevel');
563 $this->assertEquals('/someFileAtRootLevel', $rootFileInfo['identifier']);
569 public function getFileThrowsExceptionIfFileDoesNotExist() {
570 $this->setExpectedException('InvalidArgumentException', '', 1314516809);
571 $fixture = $this->createDriverFixture(array(
572 'basePath' => $this->getMountRootUrl()
574 $fixture->getFileInfoByIdentifier('/some/file/at/a/random/path');
580 public function getFileListReturnsEmptyArrayForEmptyDirectory() {
581 $fixture = $this->createDriverFixture(array(
582 'basePath' => $this->getMountRootUrl()
584 $fileList = $fixture->getFileList('/');
585 $this->assertEmpty($fileList);
591 public function getFileListReturnsAllFilesInDirectory() {
592 $dirStructure = array(
597 $this->addToMount($dirStructure);
598 $fixture = $this->createDriverFixture(array(
599 'basePath' => $this->getMountRootUrl()
601 $fileList = $fixture->getFileList('/');
602 $this->assertEquals(array('file1', 'file2'), array_keys($fileList));
608 public function getFileListFailsIfDirectoryDoesNotExist() {
609 $this->setExpectedException('InvalidArgumentException', '', 1314349666);
610 $this->addToMount(array('somefile' => ''));
611 $fixture = $this->createDriverFixture(array(
612 'basePath' => $this->getMountRootUrl()
614 $fixture->getFileList('somedir/');
620 public function getFileListCallsConfiguredCallbackFunctionWithGivenItemName() {
621 $dirStructure = array(
624 // register static callback to self
628 'callbackStaticTestFunction'
631 $this->addToMount($dirStructure);
632 $fixture = $this->createDriverFixture(array(
633 'basePath' => $this->getMountRootUrl()
635 // the callback function will throw an exception used to check if it was called with correct $itemName
636 $this->setExpectedException('InvalidArgumentException', '$itemName', 1336159604);
637 $fixture->getFileList('/', 0, 0, $callback);
641 * Static callback function used to test if the filter callbacks work
642 * As it is static we are using an exception to test if it is really called and works
645 * @throws InvalidArgumentException
646 * @see getFileListCallsConfiguredCallbackFunction
648 static public function callbackStaticTestFunction() {
649 list($itemName) = func_get_args();
650 if ($itemName === 'file2') {
651 throw new InvalidArgumentException('$itemName', 1336159604);
658 public function getFileListFiltersItemsWithGivenFilterMethods() {
659 $dirStructure = array(
663 $this->addToMount($dirStructure);
664 $fixture = $this->createDriverFixture(array(
665 'basePath' => $this->getMountRootUrl()
667 $filterCallbacks = array(
668 array('t3lib_file_Tests_Driver_Fixtures_LocalDriverFilenameFilter', 'filterFilename')
670 $fileList = $fixture->getFileList('/', 0, 0, $filterCallbacks);
671 $this->assertNotContains('fileA', array_keys($fileList));
677 public function getFolderListReturnsAllDirectoriesInDirectory() {
678 $dirStructure = array(
683 $this->addToMount($dirStructure);
684 $fixture = $this->createDriverFixture(array(
685 'basePath' => $this->getMountRootUrl()
687 $fileList = $fixture->getFolderList('/');
688 $this->assertEquals(array('dir1', 'dir2'), array_keys($fileList));
694 public function getFolderListDoesNotReturnHiddenFoldersByDefault() {
695 $dirStructure = array(
696 '.someHiddenFile' => array(),
700 $this->addToMount($dirStructure);
701 $fixture = $this->createDriverFixture(array(
702 'basePath' => $this->getMountRootUrl()
704 $fileList = $fixture->getFolderList('/');
705 $this->assertEquals(array('aDir'), array_keys($fileList));
711 public function getFolderListUsesCorrectPathForItems() {
712 $this->addToMount(array(
717 $fixture = $this->createDriverFixture(array(
718 'basePath' => $this->getMountRootUrl()
720 $FolderList = $fixture->getFolderList('/');
721 $this->assertEquals('/dir1/', $FolderList['dir1']['identifier']);
722 $FolderList = $fixture->getFolderList('/dir1/');
723 $this->assertEquals('/dir1/subdir1/', $FolderList['subdir1']['identifier']);
727 * Checks if the folder names . and .. are ignored when listing subdirectories
731 public function getFolderListLeavesOutNavigationalEntries() {
732 // we have to add .. and . manually, as these are not included in vfsStream directory listings (as opposed
733 // to normal file listings)
734 $this->addToMount(array(
738 $fixture = $this->createDriverFixture(array(
739 'basePath' => $this->getMountRootUrl()
741 $fileList = $fixture->getFolderList('/');
742 $this->assertEmpty($fileList);
748 public function getFolderListFiltersItemsWithGivenFilterMethods() {
749 $dirStructure = array(
750 'folderA' => array(),
753 $this->addToMount($dirStructure);
754 $fixture = $this->createDriverFixture(array(
755 'basePath' => $this->getMountRootUrl()
757 $filterCallbacks = array(
758 array('t3lib_file_Tests_Driver_Fixtures_LocalDriverFilenameFilter', 'filterFilename')
760 $folderList = $fixture->getFolderList('/', 0, 0, $filterCallbacks);
761 $this->assertNotContains('folderA', array_keys($folderList));
767 public function getFolderListFailsIfDirectoryDoesNotExist() {
768 $this->setExpectedException('InvalidArgumentException', '', 1314349666);
769 $fixture = $this->createDriverFixture(array(
770 'basePath' => $this->getMountRootUrl()
772 vfsStream
::create(array($this->basedir
=> array('somefile' => '')));
773 $fixture->getFolderList('somedir/');
779 public function hashReturnsCorrectHashes() {
780 $contents = '68b329da9893e34099c7d8ad5cb9c940';
781 $expectedMd5Hash = '8c67dbaf0ba22f2e7fbc26413b86051b';
782 $expectedSha1Hash = 'a60cd808ba7a0bcfa37fa7f3fb5998e1b8dbcd9d';
783 $mockedFile = $this->getSimpleFileMock('/hashFile');
784 $this->addToMount(array('hashFile' => $contents));
785 $fixture = $this->createDriverFixture(array(
786 'basePath' => $this->getMountRootUrl()
788 $this->assertEquals($expectedSha1Hash, $fixture->hash($mockedFile, 'sha1'));
789 $this->assertEquals($expectedMd5Hash, $fixture->hash($mockedFile, 'md5'));
795 public function hashingWithUnsupportedAlgorithmFails() {
796 $this->setExpectedException('InvalidArgumentException', '', 1304964032);
797 $fixture = $this->createDriverFixture(array(
798 'basePath' => $this->getMountRootUrl()
800 $fixture->hash($this->getSimpleFileMock('/hashFile'), uniqid());
805 * @covers TYPO3\CMS\Core\Resource\Driver\LocalDriver::getFileForLocalProcessing
807 public function getFileForLocalProcessingCreatesCopyOfFileByDefault() {
808 $fileContents = 'asdfgh';
809 $this->addToMount(array(
811 'someFile' => $fileContents
814 $fixture = $this->createDriverFixture(array(
815 'basePath' => $this->getMountRootUrl()
816 ), NULL, array('copyFileToTemporaryPath'));
817 $mockedFile = $this->getSimpleFileMock('/someDir/someFile');
818 // TODO add parameter expectation for $mockedFile as soon as PHPUnit supports object identity matching in parameter expectations
819 $fixture->expects($this->once())->method('copyFileToTemporaryPath');
820 $fixture->getFileForLocalProcessing($mockedFile);
826 public function getFileForLocalProcessingReturnsOriginalFilepathForReadonlyAccess() {
827 $fileContents = 'asdfgh';
828 $this->addToMount(array(
830 'someFile' => $fileContents
833 $fixture = $this->createDriverFixture(array(
834 'basePath' => $this->getMountRootUrl()
836 $mockedFile = $this->getSimpleFileMock('/someDir/someFile');
837 $filePath = $fixture->getFileForLocalProcessing($mockedFile, FALSE);
838 $this->assertEquals($filePath, $this->getMountRootUrl() . 'someDir/someFile');
844 public function filesCanBeCopiedToATemporaryPath() {
845 $fileContents = 'asdfgh';
846 $this->addToMount(array(
848 'someFile' => $fileContents
851 $fixture = $this->createDriverFixture(array(
852 'basePath' => $this->getMountRootUrl()
854 $mockedFile = $this->getSimpleFileMock('/someDir/someFile');
855 $filePath = $fixture->copyFileToTemporaryPath($mockedFile);
856 $this->assertContains('/typo3temp/', $filePath);
857 $this->assertEquals($fileContents, file_get_contents($filePath));
860 protected function prepareRealTestEnvironment() {
861 $basedir = $this->createRealTestdir();
862 $fixture = $this->createDriverFixture(array(
863 'basePath' => $basedir
865 return array($basedir, $fixture);
871 public function permissionsAreCorrectlyRetrievedForAllowedFile() {
872 /** @var $fixture \TYPO3\CMS\Core\Resource\Driver\LocalDriver */
873 list($basedir, $fixture) = $this->prepareRealTestEnvironment();
874 touch($basedir . '/someFile');
875 chmod($basedir . '/someFile', 448);
877 $this->assertEquals(array('r' => TRUE, 'w' => TRUE), $fixture->getFilePermissions($this->getSimpleFileMock('/someFile')));
883 public function permissionsAreCorrectlyRetrievedForForbiddenFile() {
884 if (function_exists('posix_getegid') && posix_getegid() === 0) {
885 $this->markTestSkipped('Test skipped if run on linux as root');
887 /** @var $fixture \TYPO3\CMS\Core\Resource\Driver\LocalDriver */
888 list($basedir, $fixture) = $this->prepareRealTestEnvironment();
889 touch($basedir . '/someForbiddenFile');
890 chmod($basedir . '/someForbiddenFile', 0);
892 $this->assertEquals(array('r' => FALSE, 'w' => FALSE), $fixture->getFilePermissions($this->getSimpleFileMock('/someForbiddenFile')));
898 public function permissionsAreCorrectlyRetrievedForAllowedFolder() {
899 /** @var $fixture \TYPO3\CMS\Core\Resource\Driver\LocalDriver */
900 list($basedir, $fixture) = $this->prepareRealTestEnvironment();
901 mkdir($basedir . '/someFolder');
902 chmod($basedir . '/someFolder', 448);
904 $this->assertEquals(array('r' => TRUE, 'w' => TRUE), $fixture->getFolderPermissions($this->getSimpleFolderMock('/someFolder')));
910 public function permissionsAreCorrectlyRetrievedForForbiddenFolder() {
911 if (function_exists('posix_getegid') && posix_getegid() === 0) {
912 $this->markTestSkipped('Test skipped if run on linux as root');
914 /** @var $fixture \TYPO3\CMS\Core\Resource\Driver\LocalDriver */
915 list($basedir, $fixture) = $this->prepareRealTestEnvironment();
916 mkdir($basedir . '/someForbiddenFolder');
917 chmod($basedir . '/someForbiddenFolder', 0);
919 $this->assertEquals(array('r' => FALSE, 'w' => FALSE), $fixture->getFolderPermissions($this->getSimpleFolderMock('/someForbiddenFolder')));
923 * Dataprovider for getFilePermissionsReturnsCorrectPermissionsForFilesNotOwnedByCurrentUser test
925 * @return array group, filemode and expected result
927 public function getFilePermissionsReturnsCorrectPermissionsForFilesNotOwnedByCurrentUser_dataProvider() {
929 // On some OS, the posix_* functions do not exits
930 if (function_exists('posix_getgid')) {
932 'current group, readable/writable' => array(
935 array('r' => TRUE, 'w' => TRUE)
937 'current group, readable/not writable' => array(
940 array('r' => TRUE, 'w' => FALSE)
942 'current group, not readable/not writable' => array(
945 array('r' => FALSE, 'w' => FALSE)
949 $data = array_merge_recursive($data, array(
950 'arbitrary group, readable/writable' => array(
951 vfsStream
::GROUP_USER_1
,
953 array('r' => TRUE, 'w' => TRUE)
955 'arbitrary group, readable/not writable' => array(
956 vfsStream
::GROUP_USER_1
,
958 array('r' => TRUE, 'w' => FALSE)
960 'arbitrary group, not readable/not writable' => array(
961 vfsStream
::GROUP_USER_1
,
963 array('r' => FALSE, 'w' => FALSE)
971 * @dataProvider getFilePermissionsReturnsCorrectPermissionsForFilesNotOwnedByCurrentUser_dataProvider
973 public function getFilePermissionsReturnsCorrectPermissionsForFilesNotOwnedByCurrentUser($group, $permissions, $expectedResult) {
974 $this->addToMount(array(
975 'testfile' => 'asdfg'
977 $fixture = $this->createDriverFixture(array(
978 'basePath' => $this->getMountRootUrl()
980 /** @var $fileObject vfsStreamContent */
981 $fileObject = vfsStreamWrapper
::getRoot()->getChild($this->mountDir
)->getChild('testfile');
982 // just use an "arbitrary" user here - it is only important that
983 $fileObject->chown(vfsStream
::OWNER_USER_1
);
984 $fileObject->chgrp($group);
985 $fileObject->chmod($permissions);
986 $this->assertEquals($expectedResult, $fixture->getFilePermissions($this->getSimpleFileMock('/testfile')));
992 public function isWithinRecognizesFilesWithinFolderAndInOtherFolders() {
993 $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
994 $mockedFolder = new \TYPO3\CMS\Core\
Resource\
Folder($mockedStorage, '/someFolder/', 'someFolder');
995 $fixture = $this->createDriverFixture(array(
996 'basePath' => $this->getMountRootUrl()
998 $this->assertTrue($fixture->isWithin($mockedFolder, '/someFolder/test.jpg'));
999 $this->assertTrue($fixture->isWithin($mockedFolder, '/someFolder/subFolder/test.jpg'));
1000 $this->assertFalse($fixture->isWithin($mockedFolder, '/someFolderWithALongName/test.jpg'));
1006 public function isWithinAcceptsFileAndFolderObjectsAsContent() {
1007 $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
1008 $mockedFolder = new \TYPO3\CMS\Core\
Resource\
Folder($mockedStorage, '/someFolder/', 'someFolder');
1009 $fixture = $this->createDriverFixture(array(
1010 'basePath' => $this->getMountRootUrl()
1012 $mockedSubfolder = $this->getSimpleFolderMock('/someFolder/subfolder/');
1013 $mockedFile = $this->getSimpleFileMock('/someFolder/test.jpg');
1014 $this->assertTrue($fixture->isWithin($mockedFolder, $mockedFile));
1015 $this->assertTrue($fixture->isWithin($mockedFolder, $mockedSubfolder));
1021 public function isWithinAlwaysReturnsFalseIfFolderIsWithinDifferentStorage() {
1022 $mockedStorage1 = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
1023 $mockedStorage2 = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
1024 $mockedFolder = new \TYPO3\CMS\Core\
Resource\
Folder($mockedStorage1, '/someFolder/', 'someFolder');
1025 $fixture = $this->createDriverFixture(array(
1026 'basePath' => $this->getMountRootUrl()
1027 ), $mockedStorage2);
1028 $fileIdentifier = '/someFolder/test.jpg';
1029 $subfolderIdentifier = '/someFolder/subfolder/';
1030 $mockedFile = $this->getSimpleFileMock($fileIdentifier);
1031 $mockedSubfolder = $this->getSimpleFolderMock($subfolderIdentifier);
1032 $this->assertFalse($fixture->isWithin($mockedFolder, $mockedFile));
1033 $this->assertFalse($fixture->isWithin($mockedFolder, $fileIdentifier));
1034 $this->assertFalse($fixture->isWithin($mockedFolder, $mockedSubfolder));
1035 $this->assertFalse($fixture->isWithin($mockedFolder, $subfolderIdentifier));
1038 /**********************************
1040 **********************************/
1042 * @param $identifier
1043 * @param null|\TYPO3\CMS\Core\Resource\ResourceStorage $storage
1044 * @return \TYPO3\CMS\Core\Resource\File
1046 protected function mockFileForCopyingAndMoving($identifier, \TYPO3\CMS\Core\
Resource\ResourceStorage
$storage = NULL) {
1048 $storage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
1050 $fileObject = new \TYPO3\CMS\Core\
Resource\
File(array('identifier' => $identifier, 'name' => basename($identifier), 'storage' => $storage));
1055 * @param $identifier
1056 * @param null|\TYPO3\CMS\Core\Resource\ResourceStorage $storage
1057 * @return \TYPO3\CMS\Core\Resource\Folder
1059 protected function mockFolderForCopyingAndMoving($identifier, \TYPO3\CMS\Core\
Resource\ResourceStorage
$storage = NULL) {
1061 $storage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
1063 $folderObject = new \TYPO3\CMS\Core\
Resource\
Folder($storage, $identifier, basename($identifier), 0);
1064 return $folderObject;
1068 * Prepares a simple two-folder environment with /someFolder/ and /targetFolder/. /someFolder contains a file with random
1071 * @return array $mockedFolder, $sourceFolder, $fileContents, $fixture
1073 protected function _prepareFolderEnvironmentForMoveTest() {
1074 $mockedFolder = $this->getSimpleFolderMock('/targetFolder/');
1075 $sourceFolder = $this->getSimpleFolderMock('/someFolder/');
1076 $fileContents = uniqid();
1077 $this->addToMount(array(
1078 'targetFolder' => array(),
1079 'someFolder' => array('file' => $fileContents)
1081 $fixture = $this->createDriverFixture(array(
1082 'basePath' => $this->getMountRootUrl()
1084 return array($mockedFolder, $sourceFolder, $fileContents, $fixture);
1090 public function filesCanBeCopiedWithinStorage() {
1091 $fileContents = uniqid();
1092 $this->addToMount(array(
1093 'someFile' => $fileContents,
1094 'targetFolder' => array()
1096 $fixture = $this->createDriverFixture(array(
1097 'basePath' => $this->getMountRootUrl()
1099 $storage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
1100 $sourceFile = $this->mockFileForCopyingAndMoving('/someFile', $storage);
1101 $targetFolder = $this->mockFolderForCopyingAndMoving('/targetFolder/', $storage);
1102 $fixture->copyFileWithinStorage($sourceFile, $targetFolder, 'someFile');
1103 $this->assertFileEquals($this->getUrlInMount('/someFile'), $this->getUrlInMount('/targetFolder/someFile'));
1109 public function filesCanBeMovedWithinStorage() {
1110 $mockedFolder = $this->getSimpleFolderMock('/targetFolder/');
1111 $storage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
1112 $sourceFile = $this->mockFileForCopyingAndMoving('/someFile', $storage);
1113 $fileContents = uniqid();
1114 $this->addToMount(array(
1115 'targetFolder' => array(),
1116 'someFile' => $fileContents
1118 $fixture = $this->createDriverFixture(array(
1119 'basePath' => $this->getMountRootUrl()
1121 $newIdentifier = $fixture->moveFileWithinStorage($sourceFile, $mockedFolder, 'file');
1122 $this->assertEquals($fileContents, file_get_contents($this->getUrlInMount('/targetFolder/file')));
1123 $this->assertFileNotExists($this->getUrlInMount('/someFile'));
1124 $this->assertEquals('/targetFolder/file', $newIdentifier);
1130 public function fileMetadataIsChangedAfterMovingFile() {
1131 $mockedFolder = $this->getSimpleFolderMock('/targetFolder/');
1132 $storage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
1133 $sourceFile = $this->mockFileForCopyingAndMoving('/someFile', $storage);
1134 $fileContents = uniqid();
1135 $this->addToMount(array(
1136 'targetFolder' => array(),
1137 'someFile' => $fileContents
1139 $fixture = $this->createDriverFixture(array(
1140 'basePath' => $this->getMountRootUrl()
1142 $newIdentifier = $fixture->moveFileWithinStorage($sourceFile, $mockedFolder, 'file');
1143 $fileMetadata = $fixture->getFileInfoByIdentifier($newIdentifier);
1144 $this->assertEquals($newIdentifier, $fileMetadata['identifier']);
1147 public function renamingFiles_dataProvider() {
1149 'file in subfolder' => array(
1151 'targetFolder' => array('file' => '')
1153 '/targetFolder/file',
1155 '/targetFolder/newFile'
1157 'file in rootfolder' => array(
1170 * @dataProvider renamingFiles_dataProvider
1172 public function renamingFilesChangesFilenameOnDisk(array $filesystemStructure, $oldFileIdentifier, $newFileName, $expectedNewIdentifier) {
1173 $this->addToMount($filesystemStructure);
1174 $fixture = $this->createDriverFixture(array(
1175 'basePath' => $this->getMountRootUrl()
1177 $file = $this->getSimpleFileMock($oldFileIdentifier);
1178 $newIdentifier = $fixture->renameFile($file, $newFileName);
1179 $this->assertFalse($fixture->fileExists($oldFileIdentifier));
1180 $this->assertTrue($fixture->fileExists($newIdentifier));
1181 $this->assertEquals($expectedNewIdentifier, $newIdentifier);
1187 public function renamingFilesFailsIfTargetFileExists() {
1188 $this->setExpectedException('TYPO3\\CMS\\Core\\Resource\\Exception\\ExistingTargetFileNameException', '', 1320291063);
1189 $this->addToMount(array(
1190 'targetFolder' => array('file' => '', 'newFile' => '')
1192 $fixture = $this->createDriverFixture(array(
1193 'basePath' => $this->getMountRootUrl()
1195 $file = $this->getSimpleFileMock('/targetFolder/file');
1196 $fixture->renameFile($file, 'newFile');
1200 * We use this data provider for testing move methods because there are some issues with the
1204 public function renamingFolders_dataProvider() {
1206 'folder in root folder' => array(
1208 'someFolder' => array()
1214 'file in subfolder' => array(
1216 'subfolder' => array(
1217 'someFolder' => array()
1220 '/subfolder/someFolder/',
1222 '/subfolder/newFolder/'
1229 * @dataProvider renamingFolders_dataProvider
1231 public function renamingFoldersChangesFolderNameOnDisk(array $filesystemStructure, $oldFolderIdentifier, $newFolderName, $expectedNewIdentifier) {
1232 $this->addToMount($filesystemStructure);
1233 $fixture = $this->createDriverFixture(array(
1234 'basePath' => $this->getMountRootUrl()
1236 $mockedFolder = $this->getSimpleFolderMock($oldFolderIdentifier);
1237 $mapping = $fixture->renameFolder($mockedFolder, $newFolderName);
1238 $this->assertFalse($fixture->folderExists($oldFolderIdentifier));
1239 $this->assertTrue($fixture->folderExists($expectedNewIdentifier));
1240 $this->assertEquals($expectedNewIdentifier, $mapping[$oldFolderIdentifier]);
1246 public function renameFolderReturnsCorrectMappingInformationForAllFiles() {
1247 $fileContents = 'asdfg';
1248 $this->addToMount(array(
1249 'sourceFolder' => array(
1250 'subFolder' => array('file' => $fileContents),
1254 $fixture = $this->createDriverFixture(array(
1255 'basePath' => $this->getMountRootUrl()
1257 $sourceFolder = $this->getSimpleFolderMock('/sourceFolder/');
1258 $mappingInformation = $fixture->renameFolder($sourceFolder, 'newFolder');
1259 $this->assertEquals('/newFolder/', $mappingInformation['/sourceFolder/']);
1260 $this->assertEquals('/newFolder/file', $mappingInformation['/sourceFolder/file']);
1261 $this->assertEquals('/newFolder/subFolder/file', $mappingInformation['/sourceFolder/subFolder/file']);
1262 $this->assertEquals('/newFolder/subFolder/', $mappingInformation['/sourceFolder/subFolder/']);
1268 public function renameFolderRevertsRenamingIfFilenameMapCannotBeCreated() {
1269 $this->setExpectedException('RuntimeException', '', 1334160746);
1270 $this->addToMount(array(
1271 'sourceFolder' => array(
1275 $fixture = $this->createDriverFixture(array(
1276 'basePath' => $this->getMountRootUrl()
1277 ), NULL, array('createIdentifierMap'));
1278 $fixture->expects($this->atLeastOnce())->method('createIdentifierMap')->will($this->throwException(new \TYPO3\CMS\Core\
Resource\Exception\
FileOperationErrorException()));
1279 $sourceFolder = $this->getSimpleFolderMock('/sourceFolder/');
1280 $fixture->renameFolder($sourceFolder, 'newFolder');
1281 $this->assertFileExists($this->getUrlInMount('/sourceFolder/file'));
1287 public function isFolderEmptyReturnsTrueForEmptyFolder() {
1288 // This also prepares the next few tests, so add more info than required for this test
1289 $this->addToMount(array(
1290 'emptyFolder' => array()
1292 $fixture = $this->createDriverFixture(array(
1293 'basePath' => $this->getMountRootUrl()
1295 $mockedFolder = $this->getSimpleFolderMock('/emptyFolder/');
1296 $this->assertTrue($fixture->isFolderEmpty($mockedFolder));
1303 public function isFolderEmptyReturnsFalseIfFolderHasFile() {
1304 $this->addToMount(array(
1305 'folderWithFile' => array(
1309 $fixture = $this->createDriverFixture(array(
1310 'basePath' => $this->getMountRootUrl()
1312 $mockedFolder = $this->getSimpleFolderMock('/folderWithFile/');
1313 $this->assertFalse($fixture->isFolderEmpty($mockedFolder));
1319 public function isFolderEmptyReturnsFalseIfFolderHasSubfolder() {
1320 $this->addToMount(array(
1321 'folderWithSubfolder' => array(
1322 'someFolder' => array()
1325 $fixture = $this->createDriverFixture(array(
1326 'basePath' => $this->getMountRootUrl()
1328 $mockedFolder = $this->getSimpleFolderMock('/folderWithSubfolder/');
1329 $this->assertFalse($fixture->isFolderEmpty($mockedFolder));
1332 /**********************************
1334 **********************************/
1338 public function foldersCanBeMovedWithinStorage() {
1339 /** @var \TYPO3\CMS\Core\Resource\Driver\LocalDriver $fixture */
1340 list($mockedFolder, $sourceFolder, $fileContents, $fixture) = $this->_prepareFolderEnvironmentForMoveTest();
1341 $fixture->moveFolderWithinStorage($sourceFolder, $mockedFolder, 'someFolder');
1342 $this->assertTrue(file_exists($this->getUrlInMount('/targetFolder/someFolder/')));
1343 $this->assertEquals($fileContents, file_get_contents($this->getUrlInMount('/targetFolder/someFolder/file')));
1344 $this->assertFileNotExists($this->getUrlInMount('/someFile'));
1350 public function moveFolderWithinStorageReturnsCorrectMappingInformationForAllFiles() {
1351 $fileContents = 'asdfg';
1352 $this->addToMount(array(
1353 'targetFolder' => array(),
1354 'sourceFolder' => array(
1355 'subFolder' => array('file' => $fileContents),
1359 $fixture = $this->createDriverFixture(array(
1360 'basePath' => $this->getMountRootUrl()
1362 $sourceFolder = $this->getSimpleFolderMock('/sourceFolder/');
1363 $targetFolder = $this->getSimpleFolderMock('/targetFolder/');
1364 $mappingInformation = $fixture->moveFolderWithinStorage($sourceFolder, $targetFolder, 'sourceFolder');
1365 $this->assertEquals('/targetFolder/sourceFolder/file', $mappingInformation['/sourceFolder/file']);
1366 $this->assertEquals('/targetFolder/sourceFolder/subFolder/file', $mappingInformation['/sourceFolder/subFolder/file']);
1367 $this->assertEquals('/targetFolder/sourceFolder/subFolder/', $mappingInformation['/sourceFolder/subFolder/']);
1373 public function folderCanBeRenamedWhenMoving() {
1374 /** @var \TYPO3\CMS\Core\Resource\Driver\LocalDriver $fixture */
1375 list($mockedFolder, $sourceFolder, $fileContents, $fixture) = $this->_prepareFolderEnvironmentForMoveTest();
1376 $fixture->moveFolderWithinStorage($sourceFolder, $mockedFolder, 'newFolder');
1377 $this->assertTrue(file_exists($this->getUrlInMount('/targetFolder/newFolder/')));
1380 protected function _setupFolderForCopyTest() {
1381 $fileContents1 = uniqid();
1382 $fileContents2 = uniqid();
1383 $this->addToMount(array(
1384 'targetFolder' => array(),
1385 'sourceFolder' => array(
1386 'subFolder' => array('file' => $fileContents1),
1387 'file' => $fileContents2
1390 $fixture = $this->createDriverFixture(array(
1391 'basePath' => $this->getMountRootUrl()
1398 * @see _setupFolderForCopyTest
1400 public function foldersCanBeCopiedWithinSameStorage() {
1401 $fixture = $this->_setupFolderForCopyTest();
1402 $sourceFolder = $this->getSimpleFolderMock('/sourceFolder/');
1403 $targetFolder = $this->getSimpleFolderMock('/targetFolder/');
1404 $fixture->copyFolderWithinStorage($sourceFolder, $targetFolder, 'sourceFolder');
1405 $this->assertTrue($fixture->folderExists('/targetFolder/sourceFolder/'));
1406 $this->assertTrue($fixture->fileExists('/targetFolder/sourceFolder/file'));
1407 $this->assertTrue($fixture->folderExists('/targetFolder/sourceFolder/subFolder/'));
1408 $this->assertTrue($fixture->fileExists('/targetFolder/sourceFolder/subFolder/file'));
1413 * @see _setupFolderForCopyTest
1415 public function folderNameCanBeChangedWhileCopying() {
1416 $fixture = $this->_setupFolderForCopyTest();
1417 $sourceFolder = $this->getSimpleFolderMock('/sourceFolder/');
1418 $targetFolder = $this->getSimpleFolderMock('/targetFolder/');
1419 $fixture->copyFolderWithinStorage($sourceFolder, $targetFolder, 'newFolder');
1420 $this->assertTrue($fixture->folderExists('/targetFolder/newFolder/'));
1421 $this->assertTrue($fixture->fileExists('/targetFolder/newFolder/file'));
1422 $this->assertFalse($fixture->folderExists('/targetFolder/sourceFolder/'));