c054f91bd90611b078ab4f54f86fa05b2038ee55
[Packages/TYPO3.CMS.git] / tests / t3lib / file / Driver / LocalDriverTest.php
1 <?php
2
3 /***************************************************************
4 * Copyright notice
5 *
6 * (c) 2011 Andreas Wolf <andreas.wolf@ikt-werk.de>
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
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 require_once 'vfsStream/vfsStream.php';
31 require_once dirname(dirname(__FILE__)) . '/BaseTestCase.php';
32
33 /**
34 * Testcase for the local storage driver class of the TYPO3 VFS
35 *
36 * @package TYPO3
37 * @subpackage t3lib
38 *
39 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
40 */
41 class t3lib_file_Driver_LocalDriverTest extends t3lib_file_BaseTestCase {
42
43 private static $testDirs = array();
44
45 public function setUp() {
46 parent::setUp();
47
48 // use a mocked file repository to avoid updating the index when doing property update tests
49 $mockedRepository = $this->getMock('t3lib_file_Repository_FileRepository');
50 t3lib_div::setSingletonInstance('t3lib_file_Repository_FileRepository', $mockedRepository);
51 }
52
53 public static function tearDownAfterClass() {
54 foreach (self::$testDirs as $dir) {
55 t3lib_div::rmdir($dir, TRUE);
56 }
57 }
58
59 /**
60 * Creates a "real" directory for doing tests. This is neccessary because some file system properties (e.g. permissions)
61 * cannot be reflected by vfsStream, and some methods (like touch()) don't work there either.
62 *
63 * Created directories are automatically destroyed by the tearDownAfterClass() method.
64 *
65 * @return string
66 */
67 protected function createRealTestdir() {
68 $basedir = PATH_site . 'typo3temp/fal-test-' . t3lib_div::shortMD5(microtime(TRUE));
69 mkdir($basedir);
70 self::$testDirs[] = $basedir;
71 return $basedir;
72 }
73
74 /**
75 * Creates a driver fixture object, optionally using a given mount object.
76 *
77 * IMPORTANT: Call this only after setting up the virtual file system (with the addTo* methods)!
78 *
79 * @param $driverConfiguration
80 * @param t3lib_file_Storage $storageObject
81 * @param array $mockedDriverMethods
82 * @return t3lib_file_Driver_LocalDriver
83 */
84 protected function createDriverFixture($driverConfiguration, t3lib_file_Storage $storageObject = NULL, $mockedDriverMethods = array()) {
85 $this->initializeVfs();
86
87 if ($storageObject == NULL) {
88 $storageObject = $this->getMock('t3lib_file_Storage', array(), array(), '', FALSE);
89 }
90
91 if (count($mockedDriverMethods) == 0) {
92 $driver = new t3lib_file_Driver_LocalDriver($driverConfiguration);
93 } else {
94 $driver = $this->getMock('t3lib_file_Driver_LocalDriver', $mockedDriverMethods, array(), '', FALSE);
95 }
96 $storageObject->setDriver($driver);
97 $driver->setStorage($storageObject);
98 $driver->initialize();
99 return $driver;
100 }
101
102
103 /**
104 * @test
105 */
106 public function rootLevelFolderIsCreatedWithCorrectArguments() {
107 $mockedMount = $this->getMock('t3lib_file_Storage', array(), array(), '', FALSE);
108 $fixture = $this->createDriverFixture(array(), $mockedMount);
109
110 $mockedFactory = $this->getMock('t3lib_file_Factory');
111 $mockedFactory->expects($this->once())->method('createFolderObject')->with(
112 $this->equalTo($mockedMount), $this->equalTo('/'), $this->equalTo(''));
113 t3lib_div::setSingletonInstance('t3lib_file_Factory', $mockedFactory);
114
115 $fixture->getRootLevelFolder();
116
117 t3lib_div::setSingletonInstance('t3lib_file_Factory', new t3lib_file_Factory());
118 }
119
120 /**
121 * @test
122 */
123 public function getDefaultFolderReturnsFolderForTemporaryPath() {
124 $fixture = $this->createDriverFixture(array(
125 'basePath' => $this->getMountRootUrl()
126 ));
127
128 $folder = $fixture->getDefaultFolder();
129 $this->assertStringEndsWith('_temp_/', $folder->getIdentifier());
130 }
131
132 /**
133 * @test
134 */
135 public function defaultLevelFolderFolderIsCreatedIfItDoesntExist() {
136 $fixture = $this->createDriverFixture(array(
137 'basePath' => $this->getMountRootUrl()
138 ));
139
140 $storageFolder = $fixture->getDefaultFolder();
141 $this->assertFileExists($this->getUrlInMount('/_temp_/'));
142 }
143
144 /**
145 * @test
146 */
147 public function createFolderCreatesFolderOnDisk() {
148 $this->addToMount(array('some' => array('folder' => array())));
149 $fixture = $this->createDriverFixture(array(
150 'basePath' => $this->getMountRootUrl()
151 ));
152
153 $mockedFolder = $this->getSimpleFolderMock('/some/folder/');
154
155 $fixture->createFolder('path', $mockedFolder);
156
157 $this->assertFileExists($this->getUrlInMount('/some/folder/'));
158 $this->assertFileExists($this->getUrlInMount('/some/folder/path'));
159 }
160
161 /**
162 * @test
163 */
164 public function createFolderCreatesFoldersRecursively() {
165 $this->markTestSkipped('This feature does not belong to the driver anymore -- should be reimplemented in the storage.');
166
167 $fixture = $this->createDriverFixture(array(
168 'basePath' => $this->getMountRootUrl()
169 ));
170
171 $fixture->createFolder('/some/folder/path', TRUE);
172
173 $this->assertFileExists($this->getUrlInMount('/some/folder/'));
174 $this->assertFileExists($this->getUrlInMount('/some/folder/path'));
175 }
176
177 public function createFolderSanitizesFolderNameBeforeCreation_dataProvider() {
178 return array(
179 'folder name with NULL character' => array(
180 "some\x00Folder",
181 'some_Folder'
182 ),
183 'folder name with directory part' => array(
184 '../someFolder',
185 '.._someFolder'
186 ),
187 );
188 }
189
190 /**
191 * @test
192 * @dataProvider createFolderSanitizesFolderNameBeforeCreation_dataProvider
193 */
194 public function createFolderSanitizesFolderNameBeforeCreation($newFolderName, $expectedFolderName) {
195 $this->addToMount(array('some' => array('folder' => array())));
196 $fixture = $this->createDriverFixture(array(
197 'basePath' => $this->getMountRootUrl()
198 ));
199
200 $mockedFolder = $this->getSimpleFolderMock('/some/folder/');
201
202 $fixture->createFolder($newFolderName, $mockedFolder);
203
204 $this->assertFileExists($this->getUrlInMount('/some/folder/' . $expectedFolderName));
205 }
206
207 /**
208 * @test
209 */
210 public function driverConfigVerificationFailsIfConfiguredBasePathDoesNotExist() {
211 $this->setExpectedException('RuntimeException', '', 1299233097);
212
213 $driverConfiguration = array(
214 'basePath' => vfsStream::url($this->basedir . 'doesntexist/')
215 );
216
217 $this->assertFalse(file_exists($driverConfiguration['basePath']));
218 t3lib_file_Driver_LocalDriver::verifyConfiguration($driverConfiguration);
219 }
220
221 /**
222 * @test
223 */
224 public function basePathIsNormalizedWithTrailingSlash() {
225 $driverConfiguration = array(
226 'basePath' => $this->getMountRootUrl()
227 );
228
229 $fixture = $this->createDriverFixture($driverConfiguration);
230 $this->assertEquals('/', substr($fixture->getAbsoluteBasePath(), -1));
231 }
232
233 /**
234 * @test
235 */
236 public function noSecondSlashIsAddedIfBasePathAlreadyHasTrailingSlash() {
237 $driverConfiguration = array(
238 'basePath' => $this->getMountRootUrl()
239 );
240
241 $fixture = $this->createDriverFixture($driverConfiguration);
242 $this->assertNotEquals('/', substr($fixture->getAbsoluteBasePath(), -2, 1));
243 }
244
245 /**
246 * @test
247 */
248 public function getAbsolutePathReturnsCorrectPath() {
249 $this->addToMount(array(
250 'someFolder' => array(
251 'file1.ext' => 'asdfg'
252 )
253 ));
254 $mockedFile = $this->getSimpleFileMock('someFolder/file1.ext');
255 $fixture = $this->createDriverFixture(array(
256 'basePath' => $this->getMountRootUrl()
257 ));
258
259 $path = $fixture->getAbsolutePath($mockedFile);
260 $this->assertTrue(file_exists($path));
261 $this->assertEquals($this->getUrlInMount('/someFolder/file1.ext'), $path);
262 }
263
264 /**
265 * @test
266 */
267 public function statReturnsCorrectFileInfo() {
268 $contents = 'asdfg';
269 $this->addToMount(array('file1.ext' => $contents));
270 $mockedFile = $this->getSimpleFileMock('file1.ext');
271 $fixture = $this->createDriverFixture(array(
272 'basePath' => $this->getMountRootUrl()
273 ));
274
275 $path = $fixture->getAbsolutePath($mockedFile);
276 $stat = $fixture->getLowLevelFileInfo($mockedFile);
277 $this->assertEquals(strlen($contents), $stat['size']);
278 $this->assertEquals(filectime($path), $stat['ctime']);
279 $this->assertEquals(fileatime($path), $stat['mtime']);
280 $this->assertEquals(filemtime($path), $stat['atime']);
281 }
282
283 /**
284 * @test
285 */
286 public function addFileMovesFileToCorrectLocation() {
287 $mockedFolder = $this->getSimpleFolderMock('/targetFolder/');
288
289 $this->addToMount(array('targetFolder' => array()));
290 $this->addToVfs(array(
291 'sourceFolder' => array(
292 'file' => 'asdf'
293 )
294 ));
295 $fixture = $this->createDriverFixture(array(
296 'basePath' => $this->getMountRootUrl()
297 ));
298
299 $this->assertTrue(file_exists($this->getUrl('sourceFolder/file')));
300 $fixture->addFile($this->getUrl('sourceFolder/file'), $mockedFolder, 'file');
301 $this->assertTrue(file_exists($this->getUrlInMount('/targetFolder/file')));
302 }
303
304 /**
305 * @test
306 */
307 public function addFileUsesFilenameIfGiven() {
308 $mockedFolder = $this->getSimpleFolderMock('/targetFolder/');
309
310 $this->addToMount(array('targetFolder' => array()));
311 $this->addToVfs(array(
312 'sourceFolder' => array(
313 'file' => 'asdf'
314 )
315 ));
316 $fixture = $this->createDriverFixture(array(
317 'basePath' => $this->getMountRootUrl()
318 ));
319
320 $this->assertTrue(file_exists($this->getUrl('sourceFolder/file')));
321 $fixture->addFile($this->getUrl('sourceFolder/file'), $mockedFolder, 'targetFile');
322 $this->assertTrue(file_exists($this->getUrlInMount('/targetFolder/targetFile')));
323 }
324
325 /**
326 * @test
327 */
328 public function addFileFailsIfFileIsInDriverStorage() {
329 $mockedFolder = $this->getMock('t3lib_file_Folder', array(), array(), '', FALSE);
330 $mockedFolder->expects($this->any())->method('getIdentifier')->will($this->returnValue('/targetFolder/'));
331
332 $this->setExpectedException('InvalidArgumentException', '', 1314778269);
333
334 $this->addToMount(array(
335 'targetFolder' => array(
336 'file' => 'asdf'
337 )
338 ));
339 $fixture = $this->createDriverFixture(array(
340 'basePath' => $this->getMountRootUrl()
341 ));
342
343 $fixture->addFile($this->getUrlInMount('/targetFolder/file'), $mockedFolder, 'file');
344 }
345
346 /**
347 * @test
348 */
349 public function addFileReturnsFileObject() {
350 $mockedFolder = $this->getMock('t3lib_file_Folder', array(), array(), '', FALSE);
351 $mockedFolder->expects($this->any())->method('getIdentifier')->will($this->returnValue('/targetFolder/'));
352
353 $this->addToMount(array('targetFolder' => array()));
354 $this->addToVfs(array(
355 'sourceFolder' => array(
356 'file' => 'asdf'
357 )
358 ));
359 $fixture = $this->createDriverFixture(array(
360 'basePath' => $this->getMountRootUrl()
361 ));
362
363 $this->assertTrue(file_exists($this->getUrl('sourceFolder/file')));
364 $fileObject = $fixture->addFile($this->getUrl('sourceFolder/file'), $mockedFolder, 'file');
365
366 $this->assertInstanceOf('t3lib_file_File', $fileObject);
367 $this->assertEquals('file', $fileObject->getName());
368 $this->assertEquals('/targetFolder/file', $fileObject->getIdentifier());
369 }
370
371 /**
372 * @test
373 */
374 public function addFileRawCreatesCopyOfFile() {
375 $this->addToMount(array('targetFolder' => array()));
376 $this->addToVfs(array(
377 'sourceFolder' => array(
378 'file' => 'asdf'
379 )
380 ));
381 $fixture = $this->createDriverFixture(array(
382 'basePath' => $this->getMountRootUrl()
383 ));
384
385 $this->assertTrue(file_exists($this->getUrl('sourceFolder/file')));
386 $fileIdentifier = $fixture->addFileRaw($this->getUrl('sourceFolder/file'), $this->getSimpleFolderMock('/targetFolder/'), 'somefile');
387 $this->assertTrue(file_exists($this->getUrl('sourceFolder/file')));
388 $this->assertTrue(file_exists($this->getUrlInMount('targetFolder/somefile')));
389 $this->assertEquals('/targetFolder/somefile', $fileIdentifier);
390 }
391
392 /**
393 * @test
394 */
395 public function deleteFileRawRemovesFile() {
396 $this->addToMount(array('targetFolder' => array(
397 'file' => 'asdjlkfa'
398 )));
399 $fixture = $this->createDriverFixture(array(
400 'basePath' => $this->getMountRootUrl()
401 ));
402
403 $this->assertTrue(file_exists($this->getUrlInMount('targetFolder/file')));
404 $fixture->deleteFileRaw('/targetFolder/file');
405 $this->assertFalse(file_exists($this->getUrlInMount('targetFolder/file')));
406 }
407
408 /**
409 * @test
410 */
411 public function replacingFileUpdatesMetadataInFileObject() {
412 $this->addToMount(array('targetFolder' => array(
413 'file' => 'asdjlkfa'
414 )));
415 $this->addToVfs(array('sourceFolder' => array(
416 'file' => 'asjdalks'
417 )));
418 $fixture = $this->createDriverFixture(array(
419 'basePath' => $this->getMountRootUrl()
420 ));
421
422 $mockedFile = $this->getSimpleFileMock('/targetFolder/file', array('updateProperties'));
423 $mockedFile->expects($this->once())->method('updateProperties');
424
425 $fixture->replaceFile($mockedFile, $this->getUrl('sourceFolder/file'));
426 }
427
428 /**
429 * @test
430 */
431 public function existenceChecksWorkForFilesAndFolders() {
432 $this->addToMount(array(
433 'file' => 'asdf',
434 'folder' => array()
435 ));
436 $fixture = $this->createDriverFixture(array(
437 'basePath' => $this->getMountRootUrl()
438 ));
439
440 // Using slashes at the beginning of paths because they will be stored in the DB this way.
441 $this->assertTrue($fixture->fileExists('/file'));
442 $this->assertTrue($fixture->folderExists('/folder/'));
443 $this->assertFalse($fixture->fileExists('/nonexistingFile'));
444 $this->assertFalse($fixture->folderExists('/nonexistingFolder/'));
445 }
446
447 /**
448 * @test
449 */
450 public function existenceChecksInFolderWorkForFilesAndFolders() {
451 $mockedFolder = $this->getSimpleFolderMock('/subfolder/');
452
453 $this->addToMount(array('subfolder' => array(
454 'file' => 'asdf',
455 'folder' => array()
456 )));
457 $fixture = $this->createDriverFixture(array(
458 'basePath' => $this->getMountRootUrl()
459 ));
460
461 $this->assertTrue($fixture->fileExistsInFolder('file', $mockedFolder));
462 $this->assertTrue($fixture->folderExistsInFolder('folder', $mockedFolder));
463 $this->assertFalse($fixture->fileExistsInFolder('nonexistingFile', $mockedFolder));
464 $this->assertFalse($fixture->folderExistsInFolder('nonexistingFolder', $mockedFolder));
465 }
466
467 /**
468 * @test
469 */
470 public function getPublicUrlReturnsCorrectUriForConfiguredBaseUri() {
471 $baseUri = 'http://example.org/foobar/' . uniqid();
472 $this->addToMount(array(
473 'file.ext' => 'asdf',
474 'subfolder' => array(
475 'file2.ext' => 'asdf'
476 )
477 ));
478 $fixture = $this->createDriverFixture(array(
479 'basePath' => $this->getMountRootUrl(),
480 'baseUri' => $baseUri
481 ));
482
483 $mockedFile1 = $this->getMock('t3lib_file_File', array(), array(), '', FALSE);
484 $mockedFile1->expects($this->any())->method('getIdentifier')->will($this->returnValue('/file.ext'));
485 $mockedFile2 = $this->getMock('t3lib_file_File', array(), array(), '', FALSE);
486 $mockedFile2->expects($this->any())->method('getIdentifier')->will($this->returnValue('/subfolder/file2.ext'));
487
488 $this->assertEquals($baseUri . '/file.ext', $fixture->getPublicUrl($mockedFile1));
489 $this->assertEquals($baseUri . '/subfolder/file2.ext', $fixture->getPublicUrl($mockedFile2));
490 }
491
492 /**
493 * @test
494 */
495 public function fileContentsCanBeWrittenAndRead() {
496 $fileContents = 'asdf';
497 $this->addToMount(array(
498 'file.ext' => $fileContents
499 ));
500 $fixture = $this->createDriverFixture(array(
501 'basePath' => $this->getMountRootUrl()
502 ));
503
504 $mockedFile = $this->getMock('t3lib_file_File', array(), array(), '', FALSE);
505 $mockedFile->expects($this->any())->method('getIdentifier')->will($this->returnValue('/file.ext'));
506
507 $this->assertEquals($fileContents, $fixture->getFileContents($mockedFile), 'File contents could not be read');
508 $newFileContents = 'asdfgh';
509 $fixture->setFileContents($mockedFile, $newFileContents);
510 $this->assertEquals($newFileContents, $fixture->getFileContents($mockedFile), 'New file contents could not be read.');
511 }
512
513 /**
514 * @test
515 */
516 public function setFileContentsReturnsNumberOfBytesWrittenToFile() {
517 $fileContents = 'asdf';
518 $this->addToMount(array(
519 'file.ext' => $fileContents
520 ));
521 $fixture = $this->createDriverFixture(array(
522 'basePath' => $this->getMountRootUrl()
523 ));
524
525 $mockedFile = $this->getSimpleFileMock('/file.ext');
526
527 $newFileContents = 'asdfgh';
528 $bytesWritten = $fixture->setFileContents($mockedFile, $newFileContents);
529
530 $this->assertEquals(strlen($newFileContents), $bytesWritten);
531 }
532
533 /**
534 * @test
535 * @depends existenceChecksWorkForFilesAndFolders
536 * @return array The driver fixture, the mocked file
537 */
538 public function newFilesCanBeCreated() {
539 $this->addToMount(array(
540 'someDir' => array()
541 ));
542 /** @var $fixture t3lib_file_Driver_LocalDriver */
543 list($basedir, $fixture) = $this->prepareRealTestEnvironment();
544
545 mkdir($basedir . '/someDir');
546 $fixture->createFile('testfile.txt', $fixture->getFolder('someDir'));
547
548 $mockedFile = $this->getSimpleFileMock('/someDir/testfile.txt');
549
550 $this->assertTrue($fixture->fileExists('/someDir/testfile.txt'));
551
552 return array($fixture, $mockedFile);
553 }
554
555 /**
556 * @test
557 * @depends newFilesCanBeCreated
558 */
559 public function createdFilesAreEmpty(array $arguments) {
560 /** @var $fixture t3lib_file_Driver_LocalDriver */
561 list($fixture, $mockedFile) = $arguments;
562 $fileData = $fixture->getFileContents($mockedFile);
563 $this->assertEquals(0, strlen($fileData));
564 }
565
566 /**********************************
567 * File and directory listing
568 **********************************/
569
570 /**
571 * @test
572 */
573 public function getFileReturnsCorrectIdentifier() {
574 $this->addToMount(array(
575 'someDir' => array(
576 'someFile' => 'asdfg'
577 ),
578 'someFileAtRootLevel' => 'foobar'
579 ));
580 $fixture = $this->createDriverFixture(array(
581 'basePath' => $this->getMountRootUrl()
582 ));
583
584 $subdirFileInfo = $fixture->getFileInfoByIdentifier('/someDir/someFile');
585 $this->assertEquals('/someDir/someFile', $subdirFileInfo['identifier']);
586 $rootFileInfo = $fixture->getFileInfoByIdentifier('/someFileAtRootLevel');
587 $this->assertEquals('/someFileAtRootLevel', $rootFileInfo['identifier']);
588 }
589
590 /**
591 * @test
592 */
593 public function getFileThrowsExceptionIfFileDoesNotExist() {
594 $this->setExpectedException('InvalidArgumentException', '', 1314516809);
595 $fixture = $this->createDriverFixture(array(
596 'basePath' => $this->getMountRootUrl()
597 ));
598
599 $fixture->getFileInfoByIdentifier('/some/file/at/a/random/path');
600 }
601
602 /**
603 * @test
604 */
605 public function getFileListReturnsAllFilesInDirectory() {
606 $dirStructure = array(
607 'aDir' => array(),
608 'file1' => 'asdfg',
609 'file2' => 'fdsa'
610 );
611 $this->addToMount($dirStructure);
612 $fixture = $this->createDriverFixture(array(
613 'basePath' => $this->getMountRootUrl()
614 ));
615
616 $fileList = $fixture->getFileList('/');
617
618 $this->assertEquals(array('file1', 'file2'), array_keys($fileList));
619 }
620
621 /**
622 * @test
623 */
624 public function getFileListFailsIfDirectoryDoesNotExist() {
625 $this->setExpectedException('InvalidArgumentException', '', 1314349666);
626
627 $this->addToMount(array('somefile' => ''));
628 $fixture = $this->createDriverFixture(array(
629 'basePath' => $this->getMountRootUrl()
630 ));
631
632 $fixture->getFileList('somedir/');
633 }
634
635 /**
636 * @test
637 */
638 public function getFileListDoesNotReturnHiddenFilesByDefault() {
639 $dirStructure = array(
640 'aDir' => array(),
641 '.someHiddenFile' => 'asdf',
642 'file1' => 'asdfg',
643 'file2' => 'fdsa'
644 );
645 $this->addToMount($dirStructure);
646 $fixture = $this->createDriverFixture(array(
647 'basePath' => $this->getMountRootUrl()
648 ));
649
650 $fileList = $fixture->getFileList('/');
651
652 $this->assertEquals(array('file1', 'file2'), array_keys($fileList));
653 }
654
655 /**
656 * @test
657 */
658 public function getFolderListReturnsAllDirectoriesInDirectory() {
659 $dirStructure = array(
660 'dir1' => array(),
661 'dir2' => array(),
662 'file' => 'asdfg'
663 );
664 $this->addToMount($dirStructure);
665
666 $fixture = $this->createDriverFixture(array(
667 'basePath' => $this->getMountRootUrl()
668 ));
669
670 $fileList = $fixture->getFolderList('/');
671
672 $this->assertEquals(array('dir1', 'dir2'), array_keys($fileList));
673 }
674
675 /**
676 * @test
677 */
678 public function getFolderListDoesNotReturnHiddenFoldersByDefault() {
679 $dirStructure = array(
680 '.someHiddenFile' => array(),
681 'aDir' => array(),
682 'file1' => '',
683 );
684 $this->addToMount($dirStructure);
685 $fixture = $this->createDriverFixture(array(
686 'basePath' => $this->getMountRootUrl()
687 ));
688
689 $fileList = $fixture->getFolderList('/');
690
691 $this->assertEquals(array('aDir'), array_keys($fileList));
692 }
693
694 /**
695 * @test
696 */
697 public function getFolderListUsesCorrectPathForItems() {
698 $this->addToMount(array(
699 'dir1' => array(
700 'subdir1' => array()
701 )
702 ));
703
704 $fixture = $this->createDriverFixture(array(
705 'basePath' => $this->getMountRootUrl()
706 ));
707
708 $FolderList = $fixture->getFolderList('/');
709 $this->assertEquals('/dir1/', $FolderList['dir1']['identifier']);
710
711 $FolderList = $fixture->getFolderList('/dir1/');
712 $this->assertEquals('/dir1/subdir1/', $FolderList['subdir1']['identifier']);
713 }
714
715 /**
716 * Checks if the folder names . and .. are ignored when listing subdirectories
717 *
718 * @test
719 */
720 public function getFolderListLeavesOutNavigationalEntries() {
721 $this->addToMount(array(
722 '..' => array(),
723 '.' => array()
724 ));
725 $fixture = $this->createDriverFixture(array(
726 'basePath' => $this->getMountRootUrl()
727 ));
728
729 $fileList = $fixture->getFolderList('/');
730
731 $this->assertEmpty($fileList);
732 }
733
734 /**
735 * @test
736 */
737 public function getFolderListFailsIfDirectoryDoesNotExist() {
738 $this->setExpectedException('InvalidArgumentException', '', 1314349666);
739
740 $fixture = $this->createDriverFixture(array(
741 'basePath' => $this->getMountRootUrl()
742 ));
743 vfsStream::create(array($this->basedir => array('somefile' => '')));
744
745 $fixture->getFolderList('somedir/');
746 }
747
748 /**
749 * @test
750 */
751 public function hashReturnsCorrectHashes() {
752 $contents = "68b329da9893e34099c7d8ad5cb9c940";
753 $expectedMd5Hash = "8c67dbaf0ba22f2e7fbc26413b86051b";
754 $expectedSha1Hash = "a60cd808ba7a0bcfa37fa7f3fb5998e1b8dbcd9d";
755
756 $mockedFile = $this->getSimpleFileMock('/hashFile');
757 $this->addToMount(array('hashFile' => $contents));
758 $fixture = $this->createDriverFixture(array(
759 'basePath' => $this->getMountRootUrl()
760 ));
761
762 $this->assertEquals($expectedSha1Hash, $fixture->hash($mockedFile, 'sha1'));
763 $this->assertEquals($expectedMd5Hash, $fixture->hash($mockedFile, 'md5'));
764 }
765
766 /**
767 * @test
768 */
769 public function hashingWithUnsupportedAlgorithmFails() {
770 $this->setExpectedException('InvalidArgumentException', '', 1304964032);
771
772 $fixture = $this->createDriverFixture(array(
773 'basePath' => $this->getMountRootUrl()
774 ));
775 $fixture->hash($this->getSimpleFileMock('/hashFile'), uniqid());
776 }
777
778 /**
779 * @test
780 * @covers t3lib_file_Driver_LocalDriver::getFileForLocalProcessing
781 */
782 public function getFileForLocalProcessingCreatesCopyOfFileByDefault() {
783 $fileContents = 'asdfgh';
784 $this->addToMount(array(
785 'someDir' => array(
786 'someFile' => $fileContents
787 )
788 ));
789 $fixture = $this->createDriverFixture(array(
790 'basePath' => $this->getMountRootUrl()
791 ), NULL, array('copyFileToTemporaryPath'));
792 $mockedFile = $this->getSimpleFileMock('/someDir/someFile');
793 // TODO add parameter expectation for $mockedFile as soon as PHPUnit supports object identity matching in parameter expectations
794 $fixture->expects($this->once())->method('copyFileToTemporaryPath');
795
796 $fixture->getFileForLocalProcessing($mockedFile);
797 }
798
799 /**
800 * @test
801 */
802 public function getFileForLocalProcessingReturnsOriginalFilepathForReadonlyAccess() {
803 $fileContents = 'asdfgh';
804 $this->addToMount(array(
805 'someDir' => array(
806 'someFile' => $fileContents
807 )
808 ));
809 $fixture = $this->createDriverFixture(array(
810 'basePath' => $this->getMountRootUrl()
811 ));
812 $mockedFile = $this->getSimpleFileMock('/someDir/someFile');
813
814 $filePath = $fixture->getFileForLocalProcessing($mockedFile, FALSE);
815
816 $this->assertEquals($filePath, $this->getMountRootUrl() . 'someDir/someFile');
817 }
818
819 /**
820 * @test
821 */
822 public function filesCanBeCopiedToATemporaryPath() {
823 $fileContents = 'asdfgh';
824 $this->addToMount(array(
825 'someDir' => array(
826 'someFile' => $fileContents
827 )
828 ));
829 $fixture = $this->createDriverFixture(array(
830 'basePath' => $this->getMountRootUrl()
831 ));
832
833 $mockedFile = $this->getSimpleFileMock('/someDir/someFile');
834
835 $filePath = $fixture->copyFileToTemporaryPath($mockedFile);
836
837 $this->assertContains('/typo3temp/', $filePath);
838 $this->assertEquals($fileContents, file_get_contents($filePath));
839 }
840
841 protected function prepareRealTestEnvironment() {
842 $basedir = $this->createRealTestdir();
843 $fixture = $this->createDriverFixture(array(
844 'basePath' => $basedir
845 ));
846
847 return array($basedir, $fixture);
848 }
849
850 /**
851 * @test
852 */
853 public function permissionsAreCorrectlyRetrieved() {
854 /** @var $fixture t3lib_file_Driver_LocalDriver */
855 list($basedir, $fixture) = $this->prepareRealTestEnvironment();
856 touch($basedir . '/someFile');
857 chmod($basedir . '/someFile', 0700);
858 touch($basedir . '/someForbiddenFile');
859 chmod($basedir . '/someForbiddenFile', 0000);
860 mkdir($basedir . '/someFolder');
861 chmod($basedir . '/someFolder', 0700);
862 mkdir($basedir . '/someForbiddenFolder');
863 chmod($basedir . '/someForbiddenFolder', 0000);
864 clearstatcache();
865
866 $this->assertEquals(array('r' => TRUE, 'w' => TRUE), $fixture->getFilePermissions($this->getSimpleFileMock('/someFile')));
867 $this->assertEquals(array('r' => FALSE, 'w' => FALSE), $fixture->getFilePermissions($this->getSimpleFileMock('/someForbiddenFile')));
868 $this->assertEquals(array('r' => TRUE, 'w' => TRUE), $fixture->getFolderPermissions($this->getSimpleFolderMock('/someFolder')));
869 $this->assertEquals(array('r' => FALSE, 'w' => FALSE), $fixture->getFolderPermissions($this->getSimpleFolderMock('/someForbiddenFolder')));
870 }
871
872 /**
873 * Dataprovider for getFilePermissionsReturnsCorrectPermissionsForFilesNotOwnedByCurrentUser test
874 *
875 * @return array group, filemode and expected result
876 */
877 public function getFilePermissionsReturnsCorrectPermissionsForFilesNotOwnedByCurrentUser_dataProvider() {
878 $data = array();
879
880 // On some OS, the posix_* functions do not exits
881 if (function_exists('posix_getgid')) {
882 $data = array(
883 'current group, readable/writable' => array(
884 posix_getgid(),
885 0060,
886 array('r' => TRUE, 'w' => TRUE)
887 ),
888 'current group, readable/not writable' => array(
889 posix_getgid(),
890 0040,
891 array('r' => TRUE, 'w' => FALSE)
892 ),
893 'current group, not readable/not writable' => array(
894 posix_getgid(),
895 0000,
896 array('r' => FALSE, 'w' => FALSE)
897 ),
898 );
899 }
900
901 $data = array_merge_recursive($data, array(
902 'arbitrary group, readable/writable' => array(
903 vfsStream::GROUP_USER_1,
904 0006,
905 array('r' => TRUE, 'w' => TRUE)
906 ),
907 'arbitrary group, readable/not writable' => array(
908 vfsStream::GROUP_USER_1,
909 0664,
910 array('r' => TRUE, 'w' => FALSE)
911 ),
912 'arbitrary group, not readable/not writable' => array(
913 vfsStream::GROUP_USER_1,
914 0660,
915 array('r' => FALSE, 'w' => FALSE)
916 ),
917 ));
918
919 return $data;
920 }
921
922 /**
923 * @test
924 * @dataProvider getFilePermissionsReturnsCorrectPermissionsForFilesNotOwnedByCurrentUser_dataProvider
925 */
926 public function getFilePermissionsReturnsCorrectPermissionsForFilesNotOwnedByCurrentUser($group, $permissions, $expectedResult) {
927 $this->addToMount(array(
928 'testfile' => 'asdfg'
929 ));
930 $fixture = $this->createDriverFixture(array(
931 'basePath' => $this->getMountRootUrl()
932 ));
933 /** @var $fileObject vfsStreamContent */
934 $fileObject = vfsStreamWrapper::getRoot()->getChild($this->mountDir)->getChild('testfile');
935 // just use an "arbitrary" user here - it is only important that
936 $fileObject->chown(vfsStream::OWNER_USER_1);
937 $fileObject->chgrp($group);
938 $fileObject->chmod($permissions);
939
940 $this->assertEquals($expectedResult, $fixture->getFilePermissions($this->getSimpleFileMock('/testfile')));
941 }
942
943 /**
944 * @test
945 */
946 public function isWithinRecognizesFilesWithinFolderAndInOtherFolders() {
947 $mockedStorage = $this->getMock('t3lib_file_Storage', array(), array(), '', FALSE);
948
949 $mockedFolder = new t3lib_file_Folder($mockedStorage, '/someFolder/', 'someFolder');
950 $fixture = $this->createDriverFixture(array(
951 'basePath' => $this->getMountRootUrl()
952 ), $mockedStorage);
953
954 $this->assertTrue($fixture->isWithin($mockedFolder, '/someFolder/test.jpg'));
955 $this->assertTrue($fixture->isWithin($mockedFolder, '/someFolder/subFolder/test.jpg'));
956 $this->assertFalse($fixture->isWithin($mockedFolder, '/someFolderWithALongName/test.jpg'));
957 }
958
959 /**
960 * @test
961 */
962 public function isWithinAcceptsFileAndFolderObjectsAsContent() {
963 $mockedStorage = $this->getMock('t3lib_file_Storage', array(), array(), '', FALSE);
964
965 $mockedFolder = new t3lib_file_Folder($mockedStorage, '/someFolder/', 'someFolder');
966 $fixture = $this->createDriverFixture(array(
967 'basePath' => $this->getMountRootUrl()
968 ), $mockedStorage);
969
970 $mockedSubfolder = $this->getSimpleFolderMock('/someFolder/subfolder/');
971 $mockedFile = $this->getSimpleFileMock('/someFolder/test.jpg');
972
973 $this->assertTrue($fixture->isWithin($mockedFolder, $mockedFile));
974 $this->assertTrue($fixture->isWithin($mockedFolder, $mockedSubfolder));
975 }
976
977 /**
978 * @test
979 */
980 public function isWithinAlwaysReturnsFalseIfFolderIsWithinDifferentStorage() {
981 $mockedStorage1 = $this->getMock('t3lib_file_Storage', array(), array(), '', FALSE);
982 $mockedStorage2 = $this->getMock('t3lib_file_Storage', array(), array(), '', FALSE);
983
984 $mockedFolder = new t3lib_file_Folder($mockedStorage1, '/someFolder/', 'someFolder');
985 $fixture = $this->createDriverFixture(array(
986 'basePath' => $this->getMountRootUrl()
987 ), $mockedStorage2);
988
989 $fileIdentifier = '/someFolder/test.jpg';
990 $subfolderIdentifier = '/someFolder/subfolder/';
991 $mockedFile = $this->getSimpleFileMock($fileIdentifier);
992 $mockedSubfolder = $this->getSimpleFolderMock($subfolderIdentifier);
993
994 $this->assertFalse($fixture->isWithin($mockedFolder, $mockedFile));
995 $this->assertFalse($fixture->isWithin($mockedFolder, $fileIdentifier));
996 $this->assertFalse($fixture->isWithin($mockedFolder, $mockedSubfolder));
997 $this->assertFalse($fixture->isWithin($mockedFolder, $subfolderIdentifier));
998 }
999
1000 /**********************************
1001 * Copy/move file
1002 **********************************/
1003
1004 /**
1005 * @param $identifier
1006 * @param null|t3lib_file_Storage $storage
1007 * @return t3lib_file_File
1008 */
1009 protected function mockFileForCopyingAndMoving($identifier, t3lib_file_Storage $storage = NULL) {
1010 if (!$storage) {
1011 $storage = $this->getMock('t3lib_file_Storage', array(), array(), '', FALSE);
1012 }
1013
1014 $fileObject = new t3lib_file_File(array('identifier' => $identifier, 'name' => basename($identifier), 'storage' => $storage));
1015 return $fileObject;
1016 }
1017
1018 /**
1019 * @param $identifier
1020 * @param null|t3lib_file_Storage $storage
1021 * @return t3lib_file_Folder
1022 */
1023 protected function mockFolderForCopyingAndMoving($identifier, t3lib_file_Storage $storage = NULL) {
1024 if (!$storage) {
1025 $storage = $this->getMock('t3lib_file_Storage', array(), array(), '', FALSE);
1026 }
1027
1028 $folderObject = new t3lib_file_Folder($storage, $identifier, basename($identifier), 0);
1029 return $folderObject;
1030 }
1031
1032 /**
1033 * Prepares a simple two-folder environment with /someFolder/ and /targetFolder/. /someFolder contains a file with random
1034 * contents
1035 *
1036 * @return array $mockedFolder, $sourceFolder, $fileContents, $fixture
1037 */
1038 protected function _prepareFolderEnvironmentForMoveTest() {
1039 $mockedFolder = $this->getSimpleFolderMock('/targetFolder/');
1040 $sourceFolder = $this->getSimpleFolderMock('/someFolder/');
1041
1042 $fileContents = uniqid();
1043 $this->addToMount(array(
1044 'targetFolder' => array(),
1045 'someFolder' => array('file' => $fileContents)
1046 ));
1047 $fixture = $this->createDriverFixture(array(
1048 'basePath' => $this->getMountRootUrl()
1049 ));
1050 return array($mockedFolder, $sourceFolder, $fileContents, $fixture);
1051 }
1052
1053
1054 /**
1055 * @test
1056 */
1057 public function filesCanBeCopiedWithinStorage() {
1058 $fileContents = uniqid();
1059 $this->addToMount(array(
1060 'someFile' => $fileContents,
1061 'targetFolder' => array()
1062 ));
1063 $fixture = $this->createDriverFixture(array(
1064 'basePath' => $this->getMountRootUrl()
1065 ));
1066
1067 $storage = $this->getMock('t3lib_file_Storage', array(), array(), '', FALSE);
1068 $sourceFile = $this->mockFileForCopyingAndMoving('/someFile', $storage);
1069 $targetFolder = $this->mockFolderForCopyingAndMoving('/targetFolder/', $storage);
1070
1071 $fixture->copyFileWithinStorage($sourceFile, $targetFolder, 'someFile');
1072 $this->assertFileEquals($this->getUrlInMount('/someFile'), $this->getUrlInMount('/targetFolder/someFile'));
1073 }
1074
1075 /**
1076 * @test
1077 */
1078 public function filesCanBeMovedWithinStorage() {
1079 $mockedFolder = $this->getSimpleFolderMock('/targetFolder/');
1080 $storage = $this->getMock('t3lib_file_Storage', array(), array(), '', FALSE);
1081 $sourceFile = $this->mockFileForCopyingAndMoving('/someFile', $storage);
1082
1083 $fileContents = uniqid();
1084 $this->addToMount(array(
1085 'targetFolder' => array(),
1086 'someFile' => $fileContents
1087 ));
1088 $fixture = $this->createDriverFixture(array(
1089 'basePath' => $this->getMountRootUrl()
1090 ));
1091
1092 $newIdentifier = $fixture->moveFileWithinStorage($sourceFile, $mockedFolder, 'file');
1093 $this->assertEquals($fileContents, file_get_contents($this->getUrlInMount('/targetFolder/file')));
1094 $this->assertFileNotExists($this->getUrlInMount('/someFile'));
1095 $this->assertEquals('/targetFolder/file', $newIdentifier);
1096 }
1097
1098 /**
1099 * @test
1100 */
1101 public function fileMetadataIsChangedAfterMovingFile() {
1102 $mockedFolder = $this->getSimpleFolderMock('/targetFolder/');
1103 $storage = $this->getMock('t3lib_file_Storage', array(), array(), '', FALSE);
1104 $sourceFile = $this->mockFileForCopyingAndMoving('/someFile', $storage);
1105
1106 $fileContents = uniqid();
1107 $this->addToMount(array(
1108 'targetFolder' => array(),
1109 'someFile' => $fileContents
1110 ));
1111 $fixture = $this->createDriverFixture(array(
1112 'basePath' => $this->getMountRootUrl()
1113 ));
1114
1115 $newIdentifier = $fixture->moveFileWithinStorage($sourceFile, $mockedFolder, 'file');
1116 $fileMetadata = $fixture->getFileInfoByIdentifier($newIdentifier);
1117 $this->assertEquals($newIdentifier, $fileMetadata['identifier']);
1118 }
1119
1120 public function renamingFiles_dataProvider() {
1121 return array(
1122 'file in subfolder' => array(
1123 array(
1124 'targetFolder' => array('file' => ''),
1125 ),
1126 '/targetFolder/file',
1127 'newFile',
1128 '/targetFolder/newFile'
1129 ),
1130 'file in rootfolder' => array(
1131 array(
1132 'fileInRoot' => ''
1133 ),
1134 '/fileInRoot',
1135 'newFile',
1136 '/newFile'
1137 )
1138 );
1139 }
1140
1141 /**
1142 * @test
1143 * @dataProvider renamingFiles_dataProvider
1144 */
1145 public function renamingFilesChangesFilenameOnDisk(array $filesystemStructure, $oldFileIdentifier, $newFileName, $expectedNewIdentifier) {
1146 $this->addToMount($filesystemStructure);
1147 $fixture = $this->createDriverFixture(array(
1148 'basePath' => $this->getMountRootUrl()
1149 ));
1150
1151 $file = $this->getSimpleFileMock($oldFileIdentifier);
1152
1153 $newIdentifier = $fixture->renameFile($file, $newFileName);
1154 $this->assertFalse($fixture->fileExists($oldFileIdentifier));
1155 $this->assertTrue($fixture->fileExists($newIdentifier));
1156 $this->assertEquals($expectedNewIdentifier, $newIdentifier);
1157 }
1158
1159 /**
1160 * @test
1161 */
1162 public function renamingFilesFailsIfTargetFileExists() {
1163 $this->setExpectedException('t3lib_file_exception_ExistingTargetFileNameException', '', 1320291063);
1164
1165 $this->addToMount(array(
1166 'targetFolder' => array('file' => '', 'newFile' => ''),
1167 ));
1168 $fixture = $this->createDriverFixture(array(
1169 'basePath' => $this->getMountRootUrl()
1170 ));
1171
1172 $file = $this->getSimpleFileMock('/targetFolder/file');
1173
1174 $fixture->renameFile($file, 'newFile');
1175 }
1176
1177 /**
1178 * We use this data provider for testing move methods because there are some issues with the
1179 *
1180 * @return array
1181 */
1182 public function renamingFolders_dataProvider() {
1183 return array(
1184 'folder in root folder' => array(
1185 array(
1186 'someFolder' => array(),
1187 ),
1188 '/someFolder/',
1189 'newFolder',
1190 '/newFolder/'
1191 ),
1192 'file in subfolder' => array(
1193 array(
1194 'subfolder' => array(
1195 'someFolder' => array()
1196 )
1197 ),
1198 '/subfolder/someFolder/',
1199 'newFolder',
1200 '/subfolder/newFolder/'
1201 )
1202 );
1203 }
1204
1205 /**
1206 * @test
1207 * @dataProvider renamingFolders_dataProvider
1208 */
1209 public function renamingFoldersChangesFolderNameOnDisk(array $filesystemStructure, $oldFolderIdentifier, $newFolderName, $expectedNewIdentifier) {
1210 $this->addToMount($filesystemStructure);
1211 $fixture = $this->createDriverFixture(array(
1212 'basePath' => $this->getMountRootUrl()
1213 ));
1214 $mockedFolder = $this->getSimpleFolderMock($oldFolderIdentifier);
1215
1216 $newIdentifier = $fixture->renameFolder($mockedFolder, $newFolderName);
1217
1218 $this->assertFalse($fixture->folderExists($oldFolderIdentifier));
1219 $this->assertTrue($fixture->folderExists($expectedNewIdentifier));
1220 $this->assertEquals($expectedNewIdentifier, $newIdentifier);
1221 }
1222
1223 /**
1224 * @test
1225 */
1226 public function renameFolderReturnsCorrectMappingInformationForAllFiles() {
1227 $fileContents = 'asdfg';
1228 $this->addToMount(array(
1229 'sourceFolder' => array(
1230 'subFolder' => array('file' => $fileContents),
1231 'file' => 'asdfg'
1232 )
1233 ));
1234 $fixture = $this->createDriverFixture(array(
1235 'basePath' => $this->getMountRootUrl()
1236 ));
1237
1238 $sourceFolder = $this->getSimpleFolderMock('/sourceFolder/');
1239
1240 $mappingInformation = $fixture->renameFolder($sourceFolder, 'newFolder');
1241
1242 $this->assertEquals('/newFolder/file', $mappingInformation['/sourceFolder/file']);
1243 $this->assertEquals('/newFolder/subFolder/file', $mappingInformation['/sourceFolder/subFolder/file']);
1244 $this->assertEquals('/newFolder/subFolder/', $mappingInformation['/sourceFolder/subFolder/']);
1245 }
1246
1247 /**
1248 * @test
1249 */
1250 public function isFolderEmptyReturnsTrueForEmptyFolder() {
1251 // This also prepares the next few tests, so add more info than required for this test
1252 $this->addToMount(array(
1253 'emptyFolder' => array(),
1254 ));
1255 $fixture = $this->createDriverFixture(array(
1256 'basePath' => $this->getMountRootUrl()
1257 ));
1258 $mockedFolder = $this->getSimpleFolderMock('/emptyFolder/');
1259
1260 $this->assertTrue($fixture->isFolderEmpty($mockedFolder));
1261
1262 return $fixture;
1263 }
1264
1265 /**
1266 * @test
1267 */
1268 public function isFolderEmptyReturnsFalseIfFolderHasFile() {
1269 $this->addToMount(array(
1270 'folderWithFile' => array(
1271 'someFile' => ''
1272 ),
1273 ));
1274 $fixture = $this->createDriverFixture(array(
1275 'basePath' => $this->getMountRootUrl()
1276 ));
1277 $mockedFolder = $this->getSimpleFolderMock('/folderWithFile/');
1278
1279 $this->assertFalse($fixture->isFolderEmpty($mockedFolder));
1280 }
1281
1282 /**
1283 * @test
1284 */
1285 public function isFolderEmptyReturnsFalseIfFolderHasSubfolder() {
1286 $this->addToMount(array(
1287 'folderWithSubfolder' => array(
1288 'someFolder' => array()
1289 )
1290 ));
1291 $fixture = $this->createDriverFixture(array(
1292 'basePath' => $this->getMountRootUrl()
1293 ));
1294 $mockedFolder = $this->getSimpleFolderMock('/folderWithSubfolder/');
1295
1296 $this->assertFalse($fixture->isFolderEmpty($mockedFolder));
1297 }
1298
1299
1300 /**********************************
1301 * Copy/move folder
1302 **********************************/
1303
1304 /**
1305 * @test
1306 */
1307 public function foldersCanBeMovedWithinStorage() {
1308 /** @var t3lib_file_Driver_LocalDriver $fixture */
1309 list($mockedFolder, $sourceFolder, $fileContents, $fixture) = $this->_prepareFolderEnvironmentForMoveTest();
1310
1311 $fixture->moveFolderWithinStorage($sourceFolder, $mockedFolder, 'someFolder');
1312 $this->assertTrue(file_exists($this->getUrlInMount('/targetFolder/someFolder/')));
1313 $this->assertEquals($fileContents, file_get_contents($this->getUrlInMount('/targetFolder/someFolder/file')));
1314 $this->assertFileNotExists($this->getUrlInMount('/someFile'));
1315 }
1316
1317 /**
1318 * @test
1319 */
1320 public function moveFolderWithinStorageReturnsCorrectMappingInformationForAllFiles() {
1321 $fileContents = 'asdfg';
1322 $this->addToMount(array(
1323 'targetFolder' => array(),
1324 'sourceFolder' => array(
1325 'subFolder' => array('file' => $fileContents),
1326 'file' => 'asdfg'
1327 )
1328 ));
1329 $fixture = $this->createDriverFixture(array(
1330 'basePath' => $this->getMountRootUrl()
1331 ));
1332
1333 $sourceFolder = $this->getSimpleFolderMock('/sourceFolder/');
1334 $targetFolder = $this->getSimpleFolderMock('/targetFolder/');
1335
1336 $mappingInformation = $fixture->moveFolderWithinStorage($sourceFolder, $targetFolder, 'sourceFolder');
1337
1338 $this->assertEquals('/targetFolder/sourceFolder/file', $mappingInformation['/sourceFolder/file']);
1339 $this->assertEquals('/targetFolder/sourceFolder/subFolder/file', $mappingInformation['/sourceFolder/subFolder/file']);
1340 $this->assertEquals('/targetFolder/sourceFolder/subFolder/', $mappingInformation['/sourceFolder/subFolder/']);
1341 }
1342
1343 /**
1344 * @test
1345 */
1346 public function folderCanBeRenamedWhenMoving() {
1347 /** @var t3lib_file_Driver_LocalDriver $fixture */
1348 list($mockedFolder, $sourceFolder, $fileContents, $fixture) = $this->_prepareFolderEnvironmentForMoveTest();
1349
1350 $fixture->moveFolderWithinStorage($sourceFolder, $mockedFolder, 'newFolder');
1351 $this->assertTrue(file_exists($this->getUrlInMount('/targetFolder/newFolder/')));
1352 }
1353
1354
1355 protected function _setupFolderForCopyTest() {
1356 $fileContents1 = uniqid();
1357 $fileContents2 = uniqid();
1358 $this->addToMount(array(
1359 'targetFolder' => array(),
1360 'sourceFolder' => array(
1361 'subFolder' => array('file' => $fileContents1),
1362 'file' => $fileContents2
1363 )
1364 ));
1365 $fixture = $this->createDriverFixture(array(
1366 'basePath' => $this->getMountRootUrl()
1367 ));
1368 return $fixture;
1369 }
1370
1371 /**
1372 * @test
1373 * @see _setupFolderForCopyTest
1374 */
1375 public function foldersCanBeCopiedWithinSameStorage() {
1376 $fixture = $this->_setupFolderForCopyTest();
1377
1378 $sourceFolder = $this->getSimpleFolderMock('/sourceFolder/');
1379 $targetFolder = $this->getSimpleFolderMock('/targetFolder/');
1380
1381 $fixture->copyFolderWithinStorage($sourceFolder, $targetFolder, 'sourceFolder');
1382
1383 $this->assertTrue($fixture->folderExists('/targetFolder/sourceFolder/'));
1384 $this->assertTrue($fixture->fileExists('/targetFolder/sourceFolder/file'));
1385 $this->assertTrue($fixture->folderExists('/targetFolder/sourceFolder/subFolder/'));
1386 $this->assertTrue($fixture->fileExists('/targetFolder/sourceFolder/subFolder/file'));
1387 }
1388
1389 /**
1390 * @test
1391 * @see _setupFolderForCopyTest
1392 */
1393 public function folderNameCanBeChangedWhileCopying() {
1394 $fixture = $this->_setupFolderForCopyTest();
1395
1396 $sourceFolder = $this->getSimpleFolderMock('/sourceFolder/');
1397 $targetFolder = $this->getSimpleFolderMock('/targetFolder/');
1398
1399 $fixture->copyFolderWithinStorage($sourceFolder, $targetFolder, 'newFolder');
1400
1401 $this->assertTrue($fixture->folderExists('/targetFolder/newFolder/'));
1402 $this->assertTrue($fixture->fileExists('/targetFolder/newFolder/file'));
1403 $this->assertFalse($fixture->folderExists('/targetFolder/sourceFolder/'));
1404 }
1405 }
1406 ?>