[FEATURE] Integrate basic file abstraction layer models
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Functional / Domain / Model / FileContextTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2012 Oliver Hader <oliver.hader@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 require_once t3lib_extMgm::extPath('extbase') . 'Tests/Functional/Domain/Model/Fixture/FileContext.php';
26
27 /**
28 * Test case to check functionality type converters on FAL domain objects.
29 */
30 class Tx_Extbase_Tests_Functional_Domain_Model_FileContextTest extends Tx_Extbase_Tests_Functional_BaseTestCase {
31 /**
32 * @var Tx_Extbase_Property_PropertyMapper
33 */
34 protected $propertyMapper;
35
36 /**
37 * @var Tx_Extbase_MVC_Controller_MvcPropertyMappingConfiguration
38 */
39 protected $propertyMapperConfiguration;
40
41 /**
42 * Sets up this test suite.
43 */
44 protected function setUp() {
45 parent::setUp();
46
47 $this->importDataSet(dirname(__FILE__) . '/Fixture/data_sys_file_storage.xml');
48 $this->importDataSet(dirname(__FILE__) . '/Fixture/data_sys_file.xml');
49 $this->importDataSet(dirname(__FILE__) . '/Fixture/data_sys_file_reference.xml');
50 $this->importDataSet(dirname(__FILE__) . '/Fixture/data_sys_file_collection.xml');
51
52 /** @var $configurationBuilder Tx_Extbase_Property_PropertyMappingConfigurationBuilder */
53 $configurationBuilder = $this->objectManager->get('Tx_Extbase_Property_PropertyMappingConfigurationBuilder');
54
55 $this->propertyMapperConfiguration = $configurationBuilder->build(
56 'Tx_Extbase_MVC_Controller_MvcPropertyMappingConfiguration'
57 );
58
59 $this->propertyMapper = $this->objectManager->get('Tx_Extbase_Property_PropertyMapper');
60 }
61
62 /**
63 * Cleans up this test suite.
64 */
65 protected function tearDown() {
66 parent::tearDown();
67
68 unset($this->propertyMapperConfiguration);
69 unset($this->propertyMapper);
70 }
71
72 /**
73 * @test
74 */
75 public function fileObjectIsAvailable() {
76 $data = array(
77 'file' => 1,
78 );
79
80 /** @var $fixture Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext */
81 $fixture = $this->propertyMapper->convert(
82 $data,
83 'Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext',
84 $this->propertyMapperConfiguration
85 );
86
87 $this->assertInstanceOf('Tx_Extbase_Domain_Model_File', $fixture->getFile());
88 $this->assertInstanceOf('t3lib_file_File', $fixture->getFile()->getObject());
89 $this->assertEquals(1, $fixture->getFile()->getObject()->getUid());
90 }
91
92 /**
93 * @test
94 */
95 public function areFileObjectsAvailableFromFixture() {
96 $data = array(
97 'files' => array(
98 1,
99 2,
100 ),
101 );
102
103 /** @var $fixture Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext */
104 $fixture = $this->propertyMapper->convert(
105 $data,
106 'Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext',
107 $this->propertyMapperConfiguration
108 );
109
110 $this->assertInstanceOf('Tx_Extbase_Persistence_ObjectStorage', $fixture->getFiles());
111 $this->assertEquals(2, $fixture->getFiles()->count());
112
113 $fixture->getFiles()->rewind();
114 $this->assertEquals(1, $fixture->getFiles()->current()->getObject()->getUid());
115 $fixture->getFiles()->next();
116 $this->assertEquals(2, $fixture->getFiles()->current()->getObject()->getUid());
117 }
118
119 /**
120 * @test
121 */
122 public function isFileReferenceObjectAvailableFromFixture() {
123 $data = array(
124 'fileReference' => 1,
125 );
126
127 /** @var $fixture Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext */
128 $fixture = $this->propertyMapper->convert(
129 $data,
130 'Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext',
131 $this->propertyMapperConfiguration
132 );
133
134 $this->assertInstanceOf('Tx_Extbase_Domain_Model_FileReference', $fixture->getFileReference());
135 $this->assertInstanceOf('t3lib_file_FileReference', $fixture->getFileReference()->getObject());
136 $this->assertInstanceOf('t3lib_file_File', $fixture->getFileReference()->getObject()->getOriginalFile());
137 $this->assertEquals(1, $fixture->getFileReference()->getObject()->getOriginalFile()->getUid());
138 }
139
140 /**
141 * @test
142 */
143 public function areFileReferenceObjectsAvailableFromFixture() {
144 $data = array(
145 'fileReferences' => array(
146 1,
147 2,
148 ),
149 );
150
151 /** @var $fixture Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext */
152 $fixture = $this->propertyMapper->convert(
153 $data,
154 'Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext',
155 $this->propertyMapperConfiguration
156 );
157
158 $this->assertInstanceOf('Tx_Extbase_Persistence_ObjectStorage', $fixture->getFileReferences());
159 $this->assertEquals(2, $fixture->getFileReferences()->count());
160
161 $fixture->getFileReferences()->rewind();
162 $this->assertInstanceOf('t3lib_file_FileReference', $fixture->getFileReferences()->current()->getObject());
163 $this->assertInstanceOf('t3lib_file_File', $fixture->getFileReferences()->current()->getObject()->getOriginalFile());
164 $this->assertEquals(1, $fixture->getFileReferences()->current()->getObject()->getOriginalFile()->getUid());
165 $fixture->getFileReferences()->next();
166 $this->assertInstanceOf('t3lib_file_FileReference', $fixture->getFileReferences()->current()->getObject());
167 $this->assertInstanceOf('t3lib_file_File', $fixture->getFileReferences()->current()->getObject()->getOriginalFile());
168 $this->assertEquals(2, $fixture->getFileReferences()->current()->getObject()->getOriginalFile()->getUid());
169 }
170
171 /**
172 * @test
173 * @todo Find a way to mock the storage through all instances of Extbase
174 */
175 public function isFolderObjectAvailableFromFixture() {
176 if (!defined('TYPO3_MODE') || TYPO3_MODE !== 'BE') {
177 $this->markTestSkipped('This test currently relies on an existing fileadmin/ storage in the filesystem.');
178 }
179
180 $data = array(
181 'folder' => '9999:/',
182 );
183
184 /** @var $fixture Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext */
185 $fixture = $this->propertyMapper->convert(
186 $data,
187 'Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext',
188 $this->propertyMapperConfiguration
189 );
190
191 $this->assertInstanceOf('Tx_Extbase_Domain_Model_Folder', $fixture->getFolder());
192 $this->assertInstanceOf('t3lib_file_Folder', $fixture->getFolder()->getObject());
193 $this->assertEquals('/', $fixture->getFolder()->getObject()->getIdentifier());
194 }
195
196 /**
197 * @test
198 * @todo Find a way to mock the storage through all instances of Extbase
199 */
200 public function areFolderObjectsAvailableFromFixture() {
201 if (!defined('TYPO3_MODE') || TYPO3_MODE !== 'BE') {
202 $this->markTestSkipped('This test currently relies on an existing fileadmin/ storage in the filesystem.');
203 }
204
205 $data = array(
206 'folders' => array(
207 '9999:/',
208 '9999:/',
209 ),
210 );
211
212 /** @var $fixture Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext */
213 $fixture = $this->propertyMapper->convert(
214 $data,
215 'Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext',
216 $this->propertyMapperConfiguration
217 );
218
219 $this->assertInstanceOf('Tx_Extbase_Persistence_ObjectStorage', $fixture->getFolders());
220 $this->assertEquals(2, $fixture->getFolders()->count());
221
222 $fixture->getFolders()->rewind();
223 $this->assertInstanceOf('Tx_Extbase_Domain_Model_Folder', $fixture->getFolders()->current());
224 $this->assertInstanceOf('t3lib_file_Folder', $fixture->getFolders()->current()->getObject());
225 $this->assertEquals('/', $fixture->getFolders()->current()->getObject()->getIdentifier());
226 $fixture->getFolders()->next();
227 $this->assertInstanceOf('Tx_Extbase_Domain_Model_Folder', $fixture->getFolders()->current());
228 $this->assertInstanceOf('t3lib_file_Folder', $fixture->getFolders()->current()->getObject());
229 $this->assertEquals('/', $fixture->getFolders()->current()->getObject()->getIdentifier());
230 }
231
232 /**
233 * @test
234 */
235 public function isStaticFileCollectionObjectAvailableFromFixture() {
236 $data = array(
237 'staticFileCollection' => 2,
238 );
239
240 /** @var $fixture Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext */
241 $fixture = $this->propertyMapper->convert(
242 $data,
243 'Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext',
244 $this->propertyMapperConfiguration
245 );
246
247 $this->assertInstanceOf('Tx_Extbase_Domain_Model_StaticFileCollection', $fixture->getStaticFileCollection());
248 $this->assertEquals(2, $fixture->getStaticFileCollection()->getObject()->getUid());
249 }
250
251 /**
252 * @test
253 */
254 public function areStaticFileCollectionObjectsAvailableFromFixture() {
255 $data = array(
256 'staticFileCollections' => array(
257 2,
258 ),
259 );
260
261 /** @var $fixture Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext */
262 $fixture = $this->propertyMapper->convert(
263 $data,
264 'Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext',
265 $this->propertyMapperConfiguration
266 );
267
268 $this->assertInstanceOf('Tx_Extbase_Persistence_ObjectStorage', $fixture->getStaticFileCollections());
269 $this->assertEquals(1, $fixture->getStaticFileCollections()->count());
270
271 $this->assertInstanceOf('Tx_Extbase_Domain_Model_StaticFileCollection', $fixture->getStaticFileCollections()->current());
272 $this->assertEquals(2, $fixture->getStaticFileCollections()->current()->getObject()->getUid());
273 }
274
275 /**
276 * @test
277 */
278 public function isFolderBasedFileCollectionObjectAvailableFromFixture() {
279 $data = array(
280 'folderBasedFileCollection' => 1,
281 );
282
283 /** @var $fixture Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext */
284 $fixture = $this->propertyMapper->convert(
285 $data,
286 'Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext',
287 $this->propertyMapperConfiguration
288 );
289
290 $this->assertInstanceOf('Tx_Extbase_Domain_Model_FolderBasedFileCollection', $fixture->getFolderBasedFileCollection());
291 $this->assertEquals(1, $fixture->getFolderBasedFileCollection()->getObject()->getUid());
292 }
293
294 /**
295 * @test
296 */
297 public function areFolderBasedFileCollectionObjectAvailableFromFixture() {
298 $data = array(
299 'folderBasedFileCollections' => array(
300 1,
301 ),
302 );
303
304 /** @var $fixture Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext */
305 $fixture = $this->propertyMapper->convert(
306 $data,
307 'Tx_Extbase_Tests_Functional_Domain_Model_Fixture_FileContext',
308 $this->propertyMapperConfiguration
309 );
310
311 $this->assertInstanceOf('Tx_Extbase_Persistence_ObjectStorage', $fixture->getFolderBasedFileCollections());
312 $this->assertEquals(1, $fixture->getFolderBasedFileCollections()->count());
313
314 $this->assertInstanceOf('Tx_Extbase_Domain_Model_FolderBasedFileCollection', $fixture->getFolderBasedFileCollections()->current());
315 $this->assertEquals(1, $fixture->getFolderBasedFileCollections()->current()->getObject()->getUid());
316 }
317 }
318 ?>