827754d22c740d1a0afd0cf425039b12062d1fca
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Functional / Domain / Model / FileContextTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Functional\Domain\Model;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Oliver Hader <oliver.hader@typo3.org>
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 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('extbase') . 'Tests/Functional/Domain/Model/Fixture/FileContext.php';
27
28 /**
29 * Test case to check functionality type converters on FAL domain objects.
30 */
31 class FileContextTest extends \Tx_Extbase_Tests_Functional_BaseTestCase {
32
33 /**
34 * @var \TYPO3\CMS\Extbase\Property\PropertyMapper
35 */
36 protected $propertyMapper;
37
38 /**
39 * @var \TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfiguration
40 */
41 protected $propertyMapperConfiguration;
42
43 /**
44 * Sets up this test suite.
45 */
46 protected function setUp() {
47 parent::setUp();
48 $this->importDataSet(dirname(__FILE__) . '/Fixture/data_sys_file_storage.xml');
49 $this->importDataSet(dirname(__FILE__) . '/Fixture/data_sys_file.xml');
50 $this->importDataSet(dirname(__FILE__) . '/Fixture/data_sys_file_reference.xml');
51 $this->importDataSet(dirname(__FILE__) . '/Fixture/data_sys_file_collection.xml');
52 /** @var $configurationBuilder \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationBuilder */
53 $configurationBuilder = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Property\\PropertyMappingConfigurationBuilder');
54 $this->propertyMapperConfiguration = $configurationBuilder->build('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\MvcPropertyMappingConfiguration');
55 $this->propertyMapper = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Property\\PropertyMapper');
56 }
57
58 /**
59 * Cleans up this test suite.
60 */
61 protected function tearDown() {
62 parent::tearDown();
63 unset($this->propertyMapperConfiguration);
64 unset($this->propertyMapper);
65 }
66
67 /**
68 * @test
69 */
70 public function fileObjectIsAvailable() {
71 $data = array(
72 'file' => 1
73 );
74 /** @var $fixture \TYPO3\CMS\Extbase\Tests\Functional\Domain\Model\Fixture\FileContext */
75 $fixture = $this->propertyMapper->convert($data, 'TYPO3\\CMS\\Extbase\\Tests\\Functional\\Domain\\Model\\Fixture\\FileContext', $this->propertyMapperConfiguration);
76 $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Domain\\Model\\File', $fixture->getFile());
77 $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\File', $fixture->getFile()->getObject());
78 $this->assertEquals(1, $fixture->getFile()->getObject()->getUid());
79 }
80
81 /**
82 * @test
83 */
84 public function areFileObjectsAvailableFromFixture() {
85 $data = array(
86 'files' => array(
87 1,
88 2
89 )
90 );
91 /** @var $fixture \TYPO3\CMS\Extbase\Tests\Functional\Domain\Model\Fixture\FileContext */
92 $fixture = $this->propertyMapper->convert($data, 'TYPO3\\CMS\\Extbase\\Tests\\Functional\\Domain\\Model\\Fixture\\FileContext', $this->propertyMapperConfiguration);
93 $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', $fixture->getFiles());
94 $this->assertEquals(2, $fixture->getFiles()->count());
95 $fixture->getFiles()->rewind();
96 $this->assertEquals(1, $fixture->getFiles()->current()->getObject()->getUid());
97 $fixture->getFiles()->next();
98 $this->assertEquals(2, $fixture->getFiles()->current()->getObject()->getUid());
99 }
100
101 /**
102 * @test
103 */
104 public function isFileReferenceObjectAvailableFromFixture() {
105 $data = array(
106 'fileReference' => 1
107 );
108 /** @var $fixture \TYPO3\CMS\Extbase\Tests\Functional\Domain\Model\Fixture\FileContext */
109 $fixture = $this->propertyMapper->convert($data, 'TYPO3\\CMS\\Extbase\\Tests\\Functional\\Domain\\Model\\Fixture\\FileContext', $this->propertyMapperConfiguration);
110 $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Domain\\Model\\FileReference', $fixture->getFileReference());
111 $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\FileReference', $fixture->getFileReference()->getObject());
112 $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\File', $fixture->getFileReference()->getObject()->getOriginalFile());
113 $this->assertEquals(1, $fixture->getFileReference()->getObject()->getOriginalFile()->getUid());
114 }
115
116 /**
117 * @test
118 */
119 public function areFileReferenceObjectsAvailableFromFixture() {
120 $data = array(
121 'fileReferences' => array(
122 1,
123 2
124 )
125 );
126 /** @var $fixture \TYPO3\CMS\Extbase\Tests\Functional\Domain\Model\Fixture\FileContext */
127 $fixture = $this->propertyMapper->convert($data, 'TYPO3\\CMS\\Extbase\\Tests\\Functional\\Domain\\Model\\Fixture\\FileContext', $this->propertyMapperConfiguration);
128 $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', $fixture->getFileReferences());
129 $this->assertEquals(2, $fixture->getFileReferences()->count());
130 $fixture->getFileReferences()->rewind();
131 $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\FileReference', $fixture->getFileReferences()->current()->getObject());
132 $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\File', $fixture->getFileReferences()->current()->getObject()->getOriginalFile());
133 $this->assertEquals(1, $fixture->getFileReferences()->current()->getObject()->getOriginalFile()->getUid());
134 $fixture->getFileReferences()->next();
135 $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\FileReference', $fixture->getFileReferences()->current()->getObject());
136 $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\File', $fixture->getFileReferences()->current()->getObject()->getOriginalFile());
137 $this->assertEquals(2, $fixture->getFileReferences()->current()->getObject()->getOriginalFile()->getUid());
138 }
139
140 /**
141 * @test
142 * @todo Find a way to mock the storage through all instances of Extbase
143 */
144 public function isFolderObjectAvailableFromFixture() {
145 if (!defined('TYPO3_MODE') || TYPO3_MODE !== 'BE') {
146 $this->markTestSkipped('This test currently relies on an existing fileadmin/ storage in the filesystem.');
147 }
148 $data = array(
149 'folder' => '9999:/'
150 );
151 /** @var $fixture \TYPO3\CMS\Extbase\Tests\Functional\Domain\Model\Fixture\FileContext */
152 $fixture = $this->propertyMapper->convert($data, 'TYPO3\\CMS\\Extbase\\Tests\\Functional\\Domain\\Model\\Fixture\\FileContext', $this->propertyMapperConfiguration);
153 $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Domain\\Model\\Folder', $fixture->getFolder());
154 $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\Folder', $fixture->getFolder()->getObject());
155 $this->assertEquals('/', $fixture->getFolder()->getObject()->getIdentifier());
156 }
157
158 /**
159 * @test
160 * @todo Find a way to mock the storage through all instances of Extbase
161 */
162 public function areFolderObjectsAvailableFromFixture() {
163 if (!defined('TYPO3_MODE') || TYPO3_MODE !== 'BE') {
164 $this->markTestSkipped('This test currently relies on an existing fileadmin/ storage in the filesystem.');
165 }
166 $data = array(
167 'folders' => array(
168 '9999:/',
169 '9999:/'
170 )
171 );
172 /** @var $fixture \TYPO3\CMS\Extbase\Tests\Functional\Domain\Model\Fixture\FileContext */
173 $fixture = $this->propertyMapper->convert($data, 'TYPO3\\CMS\\Extbase\\Tests\\Functional\\Domain\\Model\\Fixture\\FileContext', $this->propertyMapperConfiguration);
174 $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', $fixture->getFolders());
175 $this->assertEquals(2, $fixture->getFolders()->count());
176 $fixture->getFolders()->rewind();
177 $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Domain\\Model\\Folder', $fixture->getFolders()->current());
178 $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\Folder', $fixture->getFolders()->current()->getObject());
179 $this->assertEquals('/', $fixture->getFolders()->current()->getObject()->getIdentifier());
180 $fixture->getFolders()->next();
181 $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Domain\\Model\\Folder', $fixture->getFolders()->current());
182 $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\Folder', $fixture->getFolders()->current()->getObject());
183 $this->assertEquals('/', $fixture->getFolders()->current()->getObject()->getIdentifier());
184 }
185
186 /**
187 * @test
188 */
189 public function isStaticFileCollectionObjectAvailableFromFixture() {
190 $data = array(
191 'staticFileCollection' => 2
192 );
193 /** @var $fixture \TYPO3\CMS\Extbase\Tests\Functional\Domain\Model\Fixture\FileContext */
194 $fixture = $this->propertyMapper->convert($data, 'TYPO3\\CMS\\Extbase\\Tests\\Functional\\Domain\\Model\\Fixture\\FileContext', $this->propertyMapperConfiguration);
195 $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Domain\\Model\\StaticFileCollection', $fixture->getStaticFileCollection());
196 $this->assertEquals(2, $fixture->getStaticFileCollection()->getObject()->getUid());
197 }
198
199 /**
200 * @test
201 */
202 public function areStaticFileCollectionObjectsAvailableFromFixture() {
203 $data = array(
204 'staticFileCollections' => array(
205 2
206 )
207 );
208 /** @var $fixture \TYPO3\CMS\Extbase\Tests\Functional\Domain\Model\Fixture\FileContext */
209 $fixture = $this->propertyMapper->convert($data, 'TYPO3\\CMS\\Extbase\\Tests\\Functional\\Domain\\Model\\Fixture\\FileContext', $this->propertyMapperConfiguration);
210 $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', $fixture->getStaticFileCollections());
211 $this->assertEquals(1, $fixture->getStaticFileCollections()->count());
212 $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Domain\\Model\\StaticFileCollection', $fixture->getStaticFileCollections()->current());
213 $this->assertEquals(2, $fixture->getStaticFileCollections()->current()->getObject()->getUid());
214 }
215
216 /**
217 * @test
218 */
219 public function isFolderBasedFileCollectionObjectAvailableFromFixture() {
220 $data = array(
221 'folderBasedFileCollection' => 1
222 );
223 /** @var $fixture \TYPO3\CMS\Extbase\Tests\Functional\Domain\Model\Fixture\FileContext */
224 $fixture = $this->propertyMapper->convert($data, 'TYPO3\\CMS\\Extbase\\Tests\\Functional\\Domain\\Model\\Fixture\\FileContext', $this->propertyMapperConfiguration);
225 $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Domain\\Model\\FolderBasedFileCollection', $fixture->getFolderBasedFileCollection());
226 $this->assertEquals(1, $fixture->getFolderBasedFileCollection()->getObject()->getUid());
227 }
228
229 /**
230 * @test
231 */
232 public function areFolderBasedFileCollectionObjectAvailableFromFixture() {
233 $data = array(
234 'folderBasedFileCollections' => array(
235 1
236 )
237 );
238 /** @var $fixture \TYPO3\CMS\Extbase\Tests\Functional\Domain\Model\Fixture\FileContext */
239 $fixture = $this->propertyMapper->convert($data, 'TYPO3\\CMS\\Extbase\\Tests\\Functional\\Domain\\Model\\Fixture\\FileContext', $this->propertyMapperConfiguration);
240 $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', $fixture->getFolderBasedFileCollections());
241 $this->assertEquals(1, $fixture->getFolderBasedFileCollections()->count());
242 $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Domain\\Model\\FolderBasedFileCollection', $fixture->getFolderBasedFileCollections()->current());
243 $this->assertEquals(1, $fixture->getFolderBasedFileCollections()->current()->getObject()->getUid());
244 }
245 }
246
247 ?>