[BUGFIX] FAL does not copy subfolders cleanly
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / Resource / Driver / LocalDriverTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\Resource\Driver;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2013 Andreas Wolf <andreas.wolf@ikt-werk.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32 require_once dirname(dirname(__FILE__)) . '/BaseTestCase.php';
33
34 /**
35 * Test case
36 */
37 class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Functional\Resource\BaseTestCase {
38
39 /**
40 * @test
41 */
42 public function foldersCanBeCopiedWithinSameStorage() {
43 $fileContents1 = uniqid();
44 $fileContents2 = uniqid();
45 $this->addToMount(array(
46 'targetFolder' => array(),
47 'sourceFolder' => array(
48 'subFolder' => array(
49 'file' => $fileContents1
50 ),
51 'file' => $fileContents2
52 )
53 ));
54 $fixture = $this->createDriverFixture(
55 array(
56 'basePath' => $this->getMountRootUrl()
57 )
58 );
59 $sourceFolder = $this->getSimpleFolderMock('/sourceFolder/');
60 $targetFolder = $this->getSimpleFolderMock('/targetFolder/');
61 $fixture->copyFolderWithinStorage($sourceFolder, $targetFolder, 'sourceFolder');
62 $this->assertTrue($fixture->folderExists('/targetFolder/sourceFolder/'));
63 $this->assertTrue($fixture->fileExists('/targetFolder/sourceFolder/file'));
64 $this->assertTrue($fixture->folderExists('/targetFolder/sourceFolder/subFolder/'));
65 $this->assertTrue($fixture->fileExists('/targetFolder/sourceFolder/subFolder/file'));
66 }
67
68 /**
69 * @test
70 */
71 public function folderNameCanBeChangedWhileCopying() {
72 $fileContents1 = uniqid();
73 $fileContents2 = uniqid();
74 $this->addToMount(array(
75 'targetFolder' => array(),
76 'sourceFolder' => array(
77 'subFolder' => array(
78 'file' => $fileContents1
79 ),
80 'file' => $fileContents2
81 )
82 ));
83 $fixture = $this->createDriverFixture(
84 array(
85 'basePath' => $this->getMountRootUrl()
86 )
87 );
88 $sourceFolder = $this->getSimpleFolderMock('/sourceFolder/');
89 $targetFolder = $this->getSimpleFolderMock('/targetFolder/');
90 $fixture->copyFolderWithinStorage($sourceFolder, $targetFolder, 'newFolder');
91 $this->assertTrue($fixture->folderExists('/targetFolder/newFolder/'));
92 $this->assertTrue($fixture->fileExists('/targetFolder/newFolder/file'));
93 $this->assertFalse($fixture->folderExists('/targetFolder/sourceFolder/'));
94 }
95
96 /**
97 * Creates a driver fixture object, optionally using a given mount object.
98 *
99 * IMPORTANT: Call this only after setting up the virtual file system (with the addTo* methods)!
100 *
101 * @param $driverConfiguration
102 * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storageObject
103 * @param array $mockedDriverMethods
104 * @return \TYPO3\CMS\Core\Resource\Driver\LocalDriver
105 */
106 protected function createDriverFixture($driverConfiguration, \TYPO3\CMS\Core\Resource\ResourceStorage $storageObject = NULL, $mockedDriverMethods = array()) {
107 $this->initializeVfs();
108 if ($storageObject == NULL) {
109 $storageObject = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
110 }
111 if (count($mockedDriverMethods) == 0) {
112 $driver = new \TYPO3\CMS\Core\Resource\Driver\LocalDriver($driverConfiguration);
113 } else {
114 $driver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\LocalDriver', $mockedDriverMethods, array($driverConfiguration));
115 }
116 $storageObject->setDriver($driver);
117 $driver->setStorage($storageObject);
118 $driver->processConfiguration();
119 $driver->initialize();
120 return $driver;
121 }
122 }
123 ?>