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